void FileAssociation::setAssociation (int index) { cExtension->select (index); leProgram->setLabel (d_associations[index].program); for (int i = 0; i < 4; i++) rbAction[i]->setChecked (i == d_associations[index].association); leProgram->setEnabled (d_associations[index].association == 0); bChooseProgram->setEnabled (d_associations[index].association == 0); // TODO: check for valid associtaion #ifdef WIN32__ char path[256]; strcpy (path, mx_gettemppath ()); strcat (path, "/hlmvtemp."); strcat (path, d_associations[index].extension); FILE *file = fopen (path, "wb"); if (file) fclose (file); int val = (int) ShellExecute ((HWND) getHandle (), "open", path, 0, 0, SW_HIDE); char str[32]; sprintf (str, "%d", val); setLabel (str); rbAction[1]->setEnabled (val != 31); /* WORD dw = 0; HICON hIcon = ExtractAssociatedIcon ((HINSTANCE) GetWindowLong ((HWND) getHandle (), GWL_HINSTANCE), path, &dw); SendMessage ((HWND) getHandle (), WM_SETICON, (WPARAM) ICON_SMALL, (LPARAM) hIcon); char str[32]; sprintf (str, "%d", (int) hIcon); setLabel (str); */ DeleteFile (path); //DestroyIcon (hIcon); #endif rbAction[2]->setEnabled ( !mx_strcasecmp (d_associations[index].extension, "mdl") || !mx_strcasecmp (d_associations[index].extension, "tga") || !mx_strcasecmp (d_associations[index].extension, "wav") ); }
//----------------------------------------------------------------------------- // Purpose: Loads the file and updates the MRU list. // Input : pszFile - File to load. //----------------------------------------------------------------------------- void MDLViewer::LoadModelFile( const char *pszFile ) { int i; models->LoadModel( pszFile ); for (i = 0; i < 4; i++) { if (!mx_strcasecmp( recentFiles[i], pszFile )) break; } // swap existing recent file if (i < 4) { char tmp[256]; strcpy (tmp, recentFiles[0]); strcpy (recentFiles[0], recentFiles[i]); strcpy (recentFiles[i], tmp); } // insert recent file else { for (i = 3; i > 0; i--) strcpy (recentFiles[i], recentFiles[i - 1]); strcpy( recentFiles[0], pszFile ); } initRecentFiles (); }
//----------------------------------------------------------------------------- // Purpose: Loads the file and updates the MRU list. // Input : pszFile - File to load. //----------------------------------------------------------------------------- void MDLViewer::LoadModelFile( const char *pszFile, int slot ) { // copy off name, pszFile may be point into recentFiles array char filename[1024]; strcpy( filename, pszFile ); LoadModelResult_t eLoaded = d_cpl->loadModel( filename, slot ); if ( eLoaded != LoadModel_Success ) { switch (eLoaded) { case LoadModel_LoadFail: { mxMessageBox (this, "Error loading model.", g_appTitle, MX_MB_ERROR | MX_MB_OK); break; } case LoadModel_PostLoadFail: { mxMessageBox (this, "Error post-loading model.", g_appTitle, MX_MB_ERROR | MX_MB_OK); break; } case LoadModel_NoModel: { mxMessageBox (this, "Error loading model. The model has no vertices.", g_appTitle, MX_MB_ERROR | MX_MB_OK); break; } } return; } if (slot == -1) { int i; for (i = 0; i < 8; i++) { if (!mx_strcasecmp( recentFiles[i], filename )) break; } // shift down existing recent files for (i = ((i > 7) ? 7 : i); i > 0; i--) { strcpy (recentFiles[i], recentFiles[i-1]); } strcpy( recentFiles[0], filename ); initRecentFiles (); setLabel( "%s", filename ); } }
int pak_ExtractFile (const char *pakFile, const char *lumpName, char *outFile) { FILE *file = fopen (pakFile, "rb"); if (!file) return 0; int ident, dirofs, dirlen; fread (&ident, sizeof (int), 1, file); if (ident != (int) (('K' << 24) + ('C' << 16) + ('A' << 8) + 'P')) { fclose (file); return 0; } fread (&dirofs, sizeof (int), 1, file); fread (&dirlen, sizeof (int), 1, file); fseek (file, dirofs, SEEK_SET); int numLumps = dirlen / 64; for (int i = 0; i < numLumps; i++) { char name[56]; int filepos, filelen; fread (name, 56, 1, file); fread (&filepos, sizeof (int), 1, file); fread (&filelen, sizeof (int), 1, file); if (!mx_strcasecmp (name, lumpName)) { FILE *out = fopen (outFile, "wb"); if (!out) { fclose (file); return 0; } fseek (file, filepos, SEEK_SET); while (filelen--) fputc (fgetc (file), out); fclose (out); fclose (file); return 1; } } fclose (file); return 0; }
MX_EXPORT mx_status_type mxd_file_vinput_open( MX_RECORD *record ) { static const char fname[] = "mxd_file_vinput_open()"; MX_VIDEO_INPUT *vinput; MX_FILE_VINPUT *file_vinput = NULL; long i, pixels_per_frame; DIR *dir; struct dirent *dirent_ptr; long dimension_array[2]; size_t sizeof_array[2]; char *name_ptr; int saved_errno; mx_status_type mx_status; file_vinput = NULL; if ( record == (MX_RECORD *) NULL ) { return mx_error( MXE_NULL_ARGUMENT, fname, "The MX_RECORD pointer passed was NULL." ); } vinput = (MX_VIDEO_INPUT *) record->record_class_struct; mx_status = mxd_file_vinput_get_pointers( vinput, &file_vinput, fname ); if ( mx_status.code != MXE_SUCCESS ) return mx_status; #if MXD_FILE_VINPUT_DEBUG MX_DEBUG(-2,("%s invoked for record '%s'", fname, record->name)); #endif /* Initialize a bunch of driver parameters. */ vinput->parameter_type = -1; vinput->frame_number = -100; vinput->get_frame = -100; vinput->frame = NULL; vinput->frame_buffer = NULL; vinput->byte_order = (long) mx_native_byteorder(); vinput->trigger_mode = MXF_DEV_NO_TRIGGER; vinput->total_num_frames = 0; file_vinput->old_total_num_frames = 0; switch( vinput->image_format ) { case MXT_IMAGE_FORMAT_RGB: vinput->bytes_per_pixel = 3; vinput->bits_per_pixel = 24; break; case MXT_IMAGE_FORMAT_GREY8: vinput->bytes_per_pixel = 1; vinput->bits_per_pixel = 8; break; case MXT_IMAGE_FORMAT_GREY16: vinput->bytes_per_pixel = 2; vinput->bits_per_pixel = 16; break; default: return mx_error( MXE_UNSUPPORTED, fname, "Image format %ld '%s' is not a supported image format " "for emulated video input '%s'.", vinput->image_format, vinput->image_format_name, record->name ); } pixels_per_frame = vinput->framesize[0] * vinput->framesize[1]; vinput->bytes_per_frame = pixels_per_frame * mx_round( vinput->bytes_per_pixel ); #if MXD_FILE_VINPUT_DEBUG MX_DEBUG(-2, ("%s: vinput->framesize[0] = %ld, vinput->framesize[1] = %ld", fname, vinput->framesize[0], vinput->framesize[1] )); MX_DEBUG(-2,("%s: vinput->image_format_name = '%s'", fname, vinput->image_format_name)); MX_DEBUG(-2,("%s: vinput->image_format = %ld", fname, vinput->image_format)); MX_DEBUG(-2,("%s: vinput->byte_order = %ld", fname, vinput->byte_order)); MX_DEBUG(-2,("%s: vinput->trigger_mode = %ld", fname, vinput->trigger_mode)); MX_DEBUG(-2,("%s: vinput->bits_per_pixel = %ld", fname, vinput->bits_per_pixel)); MX_DEBUG(-2,("%s: vinput->bytes_per_pixel = %g", fname, vinput->bytes_per_pixel)); MX_DEBUG(-2,("%s: vinput->bytes_per_frame = %ld", fname, vinput->bytes_per_frame)); #endif if ( mx_strcasecmp( "pnm", file_vinput->file_format_name ) == 0 ) { file_vinput->file_format = MXT_IMAGE_FILE_PNM; } else if ( mx_strcasecmp( "marccd", file_vinput->file_format_name ) == 0 ) { file_vinput->file_format = MXT_IMAGE_FILE_MARCCD; } else if ( mx_strcasecmp( "smv", file_vinput->file_format_name ) == 0 ) { file_vinput->file_format = MXT_IMAGE_FILE_SMV; } else { return mx_error( MXE_UNSUPPORTED, fname, "The image file format '%s' requested for video input '%s' is " "not supported.", file_vinput->file_format_name, record->name ); } /* Find out how many files are in the specified directory. */ file_vinput->num_files = 0; file_vinput->filename_array = NULL; file_vinput->current_filenum = 0; dir = opendir( file_vinput->directory_name ); if ( dir == (DIR *) NULL ) { saved_errno = errno; return mx_error( MXE_FILE_IO_ERROR, fname, "Cannot access the directory '%s'. " "Errno = %d, error message = '%s'.", file_vinput->directory_name, saved_errno, strerror(saved_errno) ); } while(1) { errno = 0; dirent_ptr = readdir(dir); if ( dirent_ptr != NULL ) { name_ptr = dirent_ptr->d_name; if ( name_ptr[0] == '.' ) { /* Skip files whose names start with '.' */ } else { file_vinput->num_files++; } } else { if ( errno == 0 ) { break; /* Exit the while() loop. */ } else { saved_errno = errno; return mx_error( MXE_FILE_IO_ERROR, fname, "An error occurred while counting the number " "of files in the directory '%s'.", file_vinput->directory_name ); } } } rewinddir(dir); #if MXD_FILE_VINPUT_DEBUG MX_DEBUG(-2,("%s: Total number of files in '%s' = %ld", fname, file_vinput->directory_name, file_vinput->num_files)); #endif if ( file_vinput->num_files <= 0 ) { return mx_error( MXE_NOT_FOUND, fname, "There are no files in the directory '%s' " "specified by video input record '%s'.", file_vinput->directory_name, record->name ); } /* Read in the names of all of the files in the specified directory. */ #if 1 dimension_array[0] = file_vinput->num_files; dimension_array[1] = MXU_FILENAME_LENGTH+1; sizeof_array[0] = sizeof(char); sizeof_array[1] = sizeof(char *); file_vinput->filename_array = mx_allocate_array( MXFT_STRING, 2, dimension_array, sizeof_array ); if ( file_vinput->filename_array == NULL ) { return mx_error( MXE_OUT_OF_MEMORY, fname, "Unable to allocate a %ld element filename array " "for video input '%s'.", file_vinput->num_files, record->name ); } #else { char *ptr, *row_ptr; dimension_array[0] = 0; sizeof_array[0] = 0; ptr = malloc( file_vinput->num_files * (MXU_FILENAME_LENGTH+1) * sizeof(char) ); if ( ptr == NULL ) { return mx_error( MXE_OUT_OF_MEMORY, fname, "Cannot allocate memory for a %ld element array " "of filenames for video input '%s'.", file_vinput->num_files, record->name ); } file_vinput->filename_array = malloc( file_vinput->num_files * sizeof(char *) ); if ( ptr == NULL ) { return mx_error( MXE_OUT_OF_MEMORY, fname, "Cannot allocate memory for a %ld element array " "of filename pointers for video input '%s'.", file_vinput->num_files, record->name ); } for ( i = 0; i < file_vinput->num_files; i++ ) { row_ptr = ptr + i * (MXU_FILENAME_LENGTH+1); file_vinput->filename_array[i] = row_ptr; } } #endif dir = opendir( file_vinput->directory_name ); if ( dir == (DIR *) NULL ) { saved_errno = errno; return mx_error( MXE_FILE_IO_ERROR, fname, "Cannot access the directory '%s' " "even though we did access it just a moment ago. " "Errno = %d, error message = '%s'.", file_vinput->directory_name, saved_errno, strerror(saved_errno) ); } for ( i = 0; i < file_vinput->num_files; ) { errno = 0; dirent_ptr = readdir(dir); if ( dirent_ptr == NULL ) { if ( errno == 0 ) { return mx_error( MXE_UNEXPECTED_END_OF_DATA, fname, "Directory '%s' used by video input '%s' " "now has fewer files (%ld) than it did " "just a moment ago (%ld).", file_vinput->directory_name, vinput->record->name, i, file_vinput->num_files ); } else { saved_errno = errno; return mx_error( MXE_FILE_IO_ERROR, fname, "An error occurred while getting the name " "of file %ld in the directory '%s'.", i, file_vinput->directory_name ); } } name_ptr = dirent_ptr->d_name; if ( name_ptr[0] == '.' ) { /* Skip files whose names start with '.' */ } else { strlcpy( file_vinput->filename_array[i], name_ptr, MXU_FILENAME_LENGTH ); i++; /* Move to the next array element. */ } #if 0 && MXD_FILE_VINPUT_DEBUG MX_DEBUG(-2, ("%s: Unsorted filename_array[%ld] = '%s'", fname, i, file_vinput->filename_array[i])); #endif } /* Sort the filenames into alphanumeric order. */ qsort( file_vinput->filename_array, file_vinput->num_files, sizeof(char *), mxp_strcmp ); #if 0 && MXD_FILE_VINPUT_DEBUG /* Print out the sorted list of filenames. */ for ( i = 0; i < file_vinput->num_files; i++ ) { MX_DEBUG(-2,("%s: Sorted filename_array[%ld] = '%s'", fname, i, file_vinput->filename_array[i])); } #endif #if MXD_FILE_VINPUT_DEBUG MX_DEBUG(-2,("%s complete for record '%s'.", fname, record->name)); #endif return MX_SUCCESSFUL_RESULT; }
MX_EXPORT mx_status_type mxd_nuvant_ezstat_ainput_open( MX_RECORD *record ) { static const char fname[] = "mxd_nuvant_ezstat_ainput_open()"; MX_ANALOG_INPUT *ainput = NULL; MX_NUVANT_EZSTAT_AINPUT *ezstat_ainput = NULL; MX_NUVANT_EZSTAT *ezstat = NULL; char *type_name = NULL; mx_status_type mx_status; if ( record == (MX_RECORD *) NULL ) { return mx_error( MXE_NULL_ARGUMENT, fname, "The MX_RECORD pointer passed was NULL." ); } ainput = (MX_ANALOG_INPUT *) record->record_class_struct; mx_status = mxd_nuvant_ezstat_ainput_get_pointers( ainput, &ezstat_ainput, &ezstat, fname); if ( mx_status.code != MXE_SUCCESS ) return mx_status; type_name = ezstat_ainput->input_type_name; if ( mx_strcasecmp( type_name, "ai0" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_AI0; } else if ( mx_strcasecmp( type_name, "ai1" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_AI1; } else if ( mx_strcasecmp( type_name, "ai2" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_AI2; } else if ( mx_strcasecmp( type_name, "ai3" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_AI3; } else if ( mx_strcasecmp( type_name, "ai14" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_AI14; } else if ( mx_strcasecmp( type_name, "ai15" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_AI15; } else if ( mx_strcasecmp( type_name, "galvanostat_fuel_cell_current" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_GALVANOSTAT_FUEL_CELL_CURRENT; } else if ( mx_strcasecmp( type_name, "fuel_cell_voltage_drop" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_FUEL_CELL_VOLTAGE_DROP; } else if ( mx_strcasecmp( type_name, "potentiostat_current_feedback_resistor_voltage" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_POTENTIOSTAT_CURRENT_FEEDBACK_RESISTOR_VOLTAGE; } else if ( mx_strcasecmp( type_name, "potentiostat_fast_scan_fuel_cell_current" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_POTENTIOSTAT_FAST_SCAN_FUEL_CELL_CURRENT; } else if ( mx_strcasecmp( type_name, "fast_scan_fuel_cell_voltage_drop" ) == 0 ) { ezstat_ainput->input_type = MXT_NE_AINPUT_FAST_SCAN_FUEL_CELL_VOLTAGE_DROP; } else { return mx_error( MXE_UNSUPPORTED, fname, "Input type '%s' is not supported for " "analog input '%s'.", type_name, record->name ); } return MX_SUCCESSFUL_RESULT; }