bool MountCmdPatcher::patch_files(const std::string &directory) { patch_file(directory + "/" + FlashScript); patch_file(directory + "/" + InstallerScript); // Don't fail if an error occurs return true; }
int main(int argc, char const *argv[]) { if (argc <2) { std::cout << "usage: "<< argv[0] << " <file-name>" << std::endl; return 1; } std::string patch_file(argv[1]); std::fstream fs (patch_file.c_str(), std::fstream::in); if (!fs.is_open()) { std::cout << "file couldn't be opened" << std::endl; return 1; } int numFeatures; fs >> numFeatures; std::cout << "Num features: " << numFeatures << std::endl; int num1, num2, num3 = 0; std::string delim; for (int i = 0; i < numFeatures; ++i) { fs >> num1 ; if (fs.fail()) { std::cout << " failed: " <<std::endl; fs >> delim; continue; } std::cout << num1 <<std::endl; }
void patcher_copy::diff () const { QDir(patched()).removeRecursively(); for(QString modified_file : modified_files()){ QFile original_file(original() + "/" + modified_file); QString patch_path = patched() + "/" + modified_file; QFile patch_file(patch_path); if(patch_file.exists()){ patch_file.remove(); } else{ QDir().mkpath(QFileInfo(patch_path).absolutePath()); } original_file.copy(patch_path); } }
void patcher_copy::patch () const { for(QString patched_file : patched_files()){ QString original_path = original() + "/" + patched_file; QFile original_file(original_path); QFile patch_file(patched() + "/" + patched_file); if(original_file.exists()){ original_file.remove(); } else{ QDir().mkpath(QFileInfo(original_path).absolutePath()); } patch_file.copy(original_path); if(utimes(original_path.toLocal8Bit(), NULL)){ qCritical() << "Could not update patch file time."; } } }
void parseParameters(int argc, char *argv[]) { // Help message: std::string help = "Usage: xooky_nabox [-version] [-help] <file>\n\n"; // Get the flag values and store. int showVersion = 0; int showHelp = 0; const struct option long_options[] = { {"version", no_argument, &showVersion, 1}, {"help", no_argument, &showHelp, 1}, { NULL, no_argument, NULL, 0 } }; int option_index; int c; while((c = getopt_long_only(argc, argv, "i:o:r:b:", long_options, &option_index)) != -1) { switch (c) { case '0': // One of the flags was entered, nothing to do. break; default: break; } } // If no params if(argc<=1) { std::cout << help; exit(1); } #ifdef DEBUG std::cout << "showVersion: " << showVersion << std::endl; std::cout << "showHelp: " << showHelp << std::endl; std::cout << "file: " << argv[argc-1] << std::endl << std::endl; #endif if(showHelp == 1) { std::cout << help; exit(0); } if(showVersion == 1) { std::cout << "XookyNabox version is " << XOOKY_VERSION << std::endl; std::cout << "LibPd version is " << LIB_PD_VERSION << std::endl; exit(0); } //Last argument must be a filename. Validate and store. char* arg_patch = argv[argc-1]; std::ifstream patch_file(arg_patch); if(!patch_file.good()) { std::cout << "The file " << arg_patch <<" is not valid.\n"; std::cout << help; exit(1); } char patch_path[1024]; realpath(arg_patch, patch_path); std::string patch_path_str = std::string(patch_path); unsigned int pos = patch_path_str.find_last_of('/'); directory = patch_path_str.substr(0,pos+1); filename = patch_path_str.substr(pos+1); }