void UpgradeDir(const char* path, bool force, bool subdir) { int upgraded = 0, ok = 0, failed = 0; UpgradeDir(path, force, subdir, upgraded, ok, failed); printf("UPGRADEDIR COMPLETE\nUpgraded: %d\nUp to date: %d\nFailed: %d\n", upgraded, ok, failed); _getch(); }
void UpgradeDir(const char* path, bool force, bool subdir, int& upgraded, int& ok, int& failed) { WIN32_FIND_DATA find; printf("Upgrade checking dir '%s'\n", path); HANDLE f = FindFirstFile(Formats("%s/*", path), &find); if(f == INVALID_HANDLE_VALUE) { printf("FIND failed...\n"); ++failed; return; } do { if(find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if(subdir && strcmp(find.cFileName, ".") != 0 && strcmp(find.cFileName, "..") != 0) { string new_path = Formats("%s/%s", path, find.cFileName); UpgradeDir(new_path.c_str(), force, subdir, upgraded, ok, failed); } } else { if(EndsWith(find.cFileName, ".qmsh") || EndsWith(find.cFileName, ".phy")) { string file_path = Formats("%s/%s", path, find.cFileName); int result = Upgrade(file_path.c_str(), force); if(result == -1) failed++; else if(result == 0) ok++; else upgraded++; } } } while(FindNextFile(f, &find)); FindClose(f); }
//================================================================================================= // Pocz¹tek programu //================================================================================================= int main(int argc, char **argv) { setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); if(argc == 1) { printf("QMSH converter, version %s (output %d).\nUsage: \"converter FILE.qmsh.tmp\". Use \"converter -h\" for list of commands.\n", CONVERTER_VERSION, QMSH::VERSION); return 0; } export_phy = false; int result = 0; bool check_subdir = true, force_update = false; for(int i = 1; i < argc; ++i) { char* cstr = argv[i]; if(cstr[0] == '-') { string str(cstr); if(str == "-h" || str == "-help" || str == "-?") { printf("Converter switches:\n" "-h/help/? - list of commands\n" "-v - show converter version and input file versions\n" "-o FILE - output file name\n" "-g1 - use single group (default)\n" "-gf FILE - use animation groups from file\n" "-gcreate - create animation groups and save as file\n" "-gcreaten FILE - create animation groups and save as named file\n" "-phy - export only physic mesh (default extension .phy)\n" "-normal - export normal mesh\n" "-info FILE - show information about mesh (version etc)\n" "-details OPTIONS FILE - like info but more details\n" "-compare FILE FILE2 - compare two meshes and show differences\n" "-upgrade FILE - upgrade mesh to newest version\n" "-upgradedir DIR - upgrade all meshes in directory and subdirectories\n" "-subdir - check subdirectories in upgradedir (default)\n" "-nosubdir - don't check subdirectories in upgradedir\n" "-force - force upgrade operation\n" "-noforce - don't force upgrade operation (default)\n" "Parameters without '-' are treated as input file.\n"); } else if(str == "-v") { printf("Converter version %s\nHandled input file version: %d..%d\nOutput file version: %d\n", CONVERTER_VERSION, QmshTmpLoader::QMSH_TMP_HANDLED_VERSION.x, QmshTmpLoader::QMSH_TMP_HANDLED_VERSION.y, QMSH::VERSION); } else if(str == "-g1") gopt = GO_ONE; else if(str == "-gf") { if(i + 1 < argc) { ++i; group_file = argv[i]; gopt = GO_FILE; } else printf("Missing FILE name for '-gf'!\n"); } else if(str == "-gcreate") { gopt = GO_CREATE; group_file.clear(); } else if(str == "-gcreaten") { if(i + 1 < argc) { ++i; group_file = argv[i]; gopt = GO_CREATE; } else printf("Missing FILE name for '-gcreaten'!\n"); } else if(str == "-o") { if(i + 1 < argc) { ++i; output_file = argv[i]; force_output = true; } else printf("Missing OUTPUT PATH for '-o'!\n"); } else if(str == "-phy") export_phy = true; else if(str == "-normal") export_phy = false; else if(str == "-info") { if(i + 1 < argc) { ++i; Info(argv[i]); } else printf("Missing FILE for '-info'!\n"); } else if(str == "-details") { if(i + 2 < argc) { Info(argv[i + 2], argv[i + 1]); i += 2; } else { printf("Missing OPTIONS or FILE for '-details'!\n"); ++i; } } else if(str == "-compare") { if(i + 2 < argc) { Compare(argv[i + 1], argv[i + 2]); i += 2; } else { printf("Missing FILEs for '-compare'!\n"); ++i; } } else if(str == "-upgrade") { if(i + 1 < argc) { ++i; Upgrade(argv[i], force_update); } else printf("Missing FILE for '-upgrade'!\n"); } else if(str == "-upgradedir") { if(i + 1 < argc) { ++i; UpgradeDir(argv[i], force_update, check_subdir); } else printf("Missing FILE for '-upgradedir'!\n"); } else if(str == "-subdir") check_subdir = true; else if(str == "-nosubdir") check_subdir = false; else if(str == "-force") force_update = true; else if(str == "-noforce") force_update = false; else printf("Unknown switch \"%s\"!\n", cstr); } else { string tstr(cstr); if(!ConvertToQmsh(tstr)) result = 1; group_file.clear(); output_file.clear(); gopt = GO_ONE; } } if(IsDebuggerPresent()) { printf("Press any key to exit..."); _getch(); } return result; }