/** * Determines if the file passed in is a patch or not. * * This function will take a pointer to a string filename, open it, * then try its best to figure out what kind of file it is. It will * print its findings out to the console if the pStruct verbose flag * is set. * * If the file passed in doesn't exist, it is created and returned as * a pointer to the writable FILE for use with fwrite and other * writing stream functions. (For creating patches, or target files) * * @param char* argument: The filename passed into the function. * @param pStruct: The parameter structure to set the function * pointers this function deems will open the file, and with a verbose * flag set prints out information to the console about its * findings. * * @return int: Returns the FILE pointer if the passed in argument is * a path to a valid patch file, (Or to a new file where a patch will * be written) and NULL otherwise. */ FILE* openIfPatch(char *filename, pStruct *params) { FILE *file; if(!(file = useFile(filename, params, "rb"))){ return useFile(filename, params, "wb+"); } /* * Least amount of work... Just check the filename to determine type * of check. */ if(strlen(filename) > 4) { char *extension = filename + (strlen(filename) - 4); /* Quick IPS check */ if(strcasecmp(extension, ".ips") == 0) { if(IPSCheckPatch(file, (params->flags & ARG_VERBOSE))) { params->patchFunction = &IPSPatchFile; return file; } } /* Quick UPS check */ if(strcasecmp(extension, ".ups") == 0) { if(UPSCheckPatch(file, (params->flags & ARG_VERBOSE))) { params->patchFunction = &UPSPatchFile; return file; } } } /* Hoomy. Guess we gotta check the headers of the files themselves. */ return headerProbe(file, params); }
void SimpleLogger::setOutput(internal::LogLevel::Level level, std::ostream& os) { LogChannel& channel = useChannel(level); LogFile& file = useFile(level); if (file.useStream() != os ) { file.close(); } channel.setOutput(os); }
bool CApplication::LoadGameDLL( const char* filename, int argc, char* argv[] ) { HINSTANCE hLib = NULL; hLib = LoadLibrary( useFile( filename ).c_str() ); if ( hLib ) { modules.push_back( hLib ); cfunc GameDLLInit = ( cfunc )GetProcAddress( ( HMODULE )hLib, "GameDLLInit" ); ModuleImportExport ie; ie.app = CApplication::GetSingletonPtr(); return GameDLLInit( ie, argc, argv ); } return false; }
/** * Filename parsing function * * This function parses filename arguments and attempts to open the * files associated with them. It also has the first level of error * handling for files. * * @param char *argument A pointer to a filename string to attempt to * open. * @param struct pStruct *params A pointer to a parameter struct * containing files, and flags for execution. * * @return Returns 1 on success, or 0 on failure. */ int fileArgument(char *argument, pStruct *params) { FILE *file; if((file = openIfPatch(argument, params))){ if(params->patchFile == NULL) { /* TODO check size of file, if 0 set as create patch file */ return !!(params->patchFile = file); } else { return AIPSError(ERR_MEDIUM, "You totally just gave me two patch files."); } } else { if(params->romFile == NULL) { return !!(params->romFile = useFile(argument, params, "rb+")); } else { return AIPSError(ERR_MEDIUM, "Hunh? Dual ROM files?"); } } }
void SimpleLogger::setOutput(const std::string& path) { // Set all enabled channels to write to the same file. // first set LOG_INFO channel to the path, // then use its file stream to set the others LogChannel& infoChannel = useChannel(internal::LogLevel::LOG_INFO); setOutput(internal::LogLevel::LOG_INFO, path); LogFile& infoFile = useFile(internal::LogLevel::LOG_INFO); std::size_t numChannels = sizeof(channels_) / sizeof(channels_[0]); for (std::size_t n = 0; n < numChannels; ++n) { LogChannel& channel = channels_[n]; if (channel.getLevel() != getNullChannel().getLevel() && channel.getLevel() != infoChannel.getLevel()) { setOutput(channel.getLevel(), infoFile.useStream()); } } }
void SimpleLogger::setOutput(internal::LogLevel::Level level, const std::string& path) { LogChannel& channel = useChannel(level); // First check if path has already been opened and then use its stream // otherwise open new file LogFile* foundFilePtr = findFile(path); if (foundFilePtr) { LogFile& foundFile = *foundFilePtr; setOutput(level, foundFile.useStream()); } else { LogFile& file = useFile(level); file.close(); file.openNew(path); setOutput(level, file.useStream()); } }