--- AE/Installer/trunk/source/main_window.cpp 2009/06/18 22:30:30 355 +++ AE/Installer/trunk/source/main_window.cpp 2009/06/29 19:23:42 379 @@ -1,11 +1,11 @@ /* -AE/Mod Installer -by Gumby and Iritscen + AE/Mod Installer + by Gumby and Iritscen */ -// To-do: - +// To-do: - Load credits from text resource file // - Institute lots of checks into file-handling -// - Clear mod info fields when mod is de-selected ??? +// - Clear mod info fields when mod is de-selected #define DEBUG #include @@ -30,11 +30,11 @@ by Gumby and Iritscen #include #endif -const string strInstallerVersion = "1.0"; +//const string strInstallerVersion = "1.0"; const bool SPLIT = 1; const bool NOT_SPLIT = 0; bool splitInstances = SPLIT; - +bool busy = 0; #ifdef WIN32 const string strOniSplit = "Onisplit.exe"; string strImportOption = "-import:nosep"; @@ -60,9 +60,10 @@ using namespace std; int globalizeData(void) { - using boost::lexical_cast; - using boost::bad_lexical_cast; -// using namespace boost::posix_time; + busy = 1; + using boost::lexical_cast; + using boost::bad_lexical_cast; + // using namespace boost::posix_time; using namespace boost::gregorian; using namespace boost::posix_time; ptime start_time(second_clock::local_time()); @@ -76,7 +77,7 @@ int globalizeData(void) ofstream logfile("Globalize.log"); logfile << "Globalization started " << to_simple_string(start_time) << endl; try { - + char levels_cstr[15][3] = {"0", "1", "2", "3", "4", "6", "8", "9", "10", "11", "12", "13", "14", "18", "19"}; // the levels Oni has...probably should have made a string array. Oops. //const vector ck(cv, &cv[CvSize]); vector levels; @@ -95,7 +96,7 @@ int globalizeData(void) path Animations = "../GameDataFolder/level0_Animations"; path TRAC = Animations / "level0_TRAC"; path TRAM = Animations / "level0_TRAM"; - + vector GDFPaths; GDFPaths.push_back(Characters); GDFPaths.push_back(Particles); @@ -103,8 +104,8 @@ int globalizeData(void) GDFPaths.push_back(Sounds); GDFPaths.push_back(TRAC); GDFPaths.push_back(TRAM); - - + + path VanillaCharacters = "packages/VanillaDats/level0_Final/level0_Characters/level0_Characters.oni"; path VanillaParticles = "packages/VanillaDats/level0_Final/level0_Particles/level0_Particles.oni"; path VanillaTextures = "packages/VanillaDats/level0_Final/level0_Textures/level0_Textures.oni"; @@ -114,14 +115,14 @@ int globalizeData(void) path VanillaTRAM = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAM.oni"; vector VanillaPaths; - + VanillaPaths.push_back(VanillaCharacters); VanillaPaths.push_back(VanillaParticles); VanillaPaths.push_back(VanillaTextures); VanillaPaths.push_back(VanillaSounds); VanillaPaths.push_back(VanillaTRAC); VanillaPaths.push_back(VanillaTRAM); - + /* if (exists("../GameDataFolder/")) { @@ -142,12 +143,12 @@ int globalizeData(void) setStatusArea("Creating needed directories..."); logfile << "Creating needed directories...\n"; create_directory( "../GameDataFolder/" ); - + create_directory( "packages" ); - + if (exists("packages/VanillaDats")) remove_all("packages/VanillaDats"); create_directory( "packages/VanillaDats" ); - + create_directory( "packages/VanillaDats/level0_Final/" ); //blah blah finish this. //logfile << "packages/VanillaDats/level0_Final/ created"; @@ -162,7 +163,7 @@ int globalizeData(void) int num_levels = 0; for(int i = 1; i < 15; i++) { - if (exists("../../GameDataFolder/level" + levels[i] + "_Final.dat")) { + if (exists("../../GameDataFolder/level" + levels[i] + "_Final.dat")) { num_levels++; } @@ -171,16 +172,16 @@ int globalizeData(void) int total_steps = 8 + 2 * num_levels; for(int i = 0; i < 15; i++) { - + //printf(levels[i],"%d",levels[i]); // int to char array - + if (exists("../../GameDataFolder/level" + levels[i] + "_Final.dat")) { logfile << "level" << levels[i] << "_Final\n"; logfile << "\tExporting level" << levels[i] << "_Final.dat\n"; //printf(Step_x_x,"Step %d/%d: exporting level%d_final.dat", parts_done + 1,, levels[i]); setStatusArea((string)Step_x_x); setStatusArea("Step " + lexical_cast(parts_done + 1) + "/" + lexical_cast(total_steps) + " exporting level" + levels[i]+"_Final.dat"); create_directory( "../GameDataFolder/level" + levels[i] + "_Final" ); -// setStatusArea(strOniSplit + " -export ../GameDataFolder/level" + levels[i] + "_Final ../../GameDataFolder/level" + levels[i] + "_Final.dat"); + // setStatusArea(strOniSplit + " -export ../GameDataFolder/level" + levels[i] + "_Final ../../GameDataFolder/level" + levels[i] + "_Final.dat"); system((strOniSplit + " -export ../GameDataFolder/level" + levels[i] + "_Final ../../GameDataFolder/level" + levels[i] + "_Final.dat").c_str()); create_directory( "packages/VanillaDats/level" + levels[i] + "_Final" ); create_directory( "packages/VanillaDats/level" + levels[i] + "_Final/level" + levels[i] + "_Final" ); @@ -256,7 +257,7 @@ int globalizeData(void) else if (dir_itr->path().filename().substr(0,4) == "AGDB" || dir_itr->path().filename().substr(0,4) == "TRCM") { cout <path().filename() << "\n"; - + if(!exists( Archive / dir_itr->filename())) rename(dir_itr->path(), Archive / dir_itr->filename()); else remove(dir_itr->path()); } @@ -264,19 +265,19 @@ int globalizeData(void) } else { - logfile << "\tMoved file: " << dir_itr->path().filename() << "\n"; + //logfile << "\tMoved file: " << dir_itr->path().filename() << "\n"; } } - + } logfile << "\tCleaning up TXMPs...\n"; system( (strOniSplit + " -move:delete " + Textures.string() + " ../GameDataFolder/level" + levels[i] + "_Final/TXMP*.oni").c_str()); parts_done++; setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) )); - + } } logfile << "Reimporting levels\n"; @@ -287,24 +288,24 @@ int globalizeData(void) //printf(Step_x_x,"Step %d/%d: reimporting level", parts_done + 1, 7 + 2 * num_levels); setStatusArea((string)Step_x_x + levels[i] + (string)"_Final.dat"); setStatusArea("Step " + lexical_cast(parts_done + 1) + "/" + lexical_cast(total_steps) + " reimporting level" + levels[i]+"_Final.oni"); system( (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levels[i] + "_Final packages/VanillaDats/level" + levels[i] + "_Final/level" - + levels[i] + "_Final/level" + levels[i] + "_Final.oni > Globalize.oni").c_str()); + + levels[i] + "_Final/level" + levels[i] + "_Final.oni >> Globalize.log").c_str()); setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) )); - parts_done++; + parts_done++; } create_directory( VanillaCharacters.parent_path() ); create_directory( VanillaParticles.parent_path() ); create_directory( VanillaTextures.parent_path() ); create_directory( VanillaSounds.parent_path() ); create_directory( VanillaAnimations.remove_filename() ); - + for(int j = 0; j < GDFPaths.size(); j++) { logfile << "\tReimporting " << GDFPaths[j].filename() << ".oni\n"; - setStatusArea("Step" + lexical_cast(parts_done + 1) + "/" + lexical_cast(total_steps) + ": reimporting " + GDFPaths[j].filename() ); + setStatusArea("Step " + lexical_cast(parts_done + 1) + "/" + lexical_cast(total_steps) + ": reimporting " + GDFPaths[j].filename() ); system((strOniSplit + " " + strImportOption + " " + GDFPaths[j].string() + " " + VanillaPaths[j].string()).c_str()); parts_done++; setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) )); } -/* + /* printf(Step_x_x,"Step %d/%d: reimporting level0_Characters", parts_done,7 + 2 * num_levels); setStatusArea((string)Step_x_x);setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) )); system((strOniSplit + " " + strImportOption + " " + Characters.string() + " " + VanillaCharacters.string()).c_str()); parts_done++; printf(Step_x_x,"Step %d/%d: reimporting level0_Particles", parts_done,7 + 2 * num_levels); setStatusArea((string)Step_x_x);setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) )); @@ -320,24 +321,41 @@ int globalizeData(void) system((strOniSplit + " " + strImportOption + " " + TRAM.string() + " " + VanillaTRAM.string()).c_str()); //parts_done++; setStatusArea((string)"Copying level scripts...");setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) )); if (exists("../GameDataFolder/IGMD")) remove_all("../GameDataFolder/IGMD"); -*/ + */ create_directory((path)"../GameDataFolder/IGMD"); - copy((path)"packages/VanillaBSL/", (path)"../GameDataFolder"); - setProgressBar( 1000 ); - setStatusArea((string)"Done! Now select your mod packages and click install."); - // while(1) Sleep(-1); + copy((path)"packages/VanillaBSL/IGMD", (path)"../GameDataFolder"); + setProgressBar( 1000 ); + + // CIP:last of all, set up the edition folder as a playable Oni installation by placing the latest application (+ Daodan DLL on Windows) in edition/ + // CIP:then copy persist.dat and keyconfig.txt into edition/ as well + +#ifndef WIN32 + /* On Mac only, set the current GDF to the AE GDF by writing to Oni's global preferences file (thankfully a standard OS X ".plist" XML file). + If there are no Oni prefs (only possible if Oni has not been run even once), then the above line will fail silently, no harm done, + and when the user does run Oni for the first time, using the copy of the app in the AE GDF, Oni will set the prefs to use that GDF at that point */ + path fullAEpath = system_complete("."); // get full path for Installer + char prefsCommand[300] = "defaults write com.godgames.oni RetailInstallationPath -string '"; + strcat(prefsCommand, fullAEpath.parent_path().parent_path().string().c_str()); // get path of edition/ folder (Oni wants the folder that *contains* the GDF) + strcat(prefsCommand, "'"); // path string is enclosed in single quotes to avoid the need to escape UNIX-unfriendly characters + system(prefsCommand); + +#endif + + setStatusArea((string)"Done! Now select your mod packages and click install."); + // while(1) Sleep(-1); + } catch (exception ex) { setStatusArea("Warning, handled exception: " + (string)ex.what()); } - - ptime end_time(second_clock::local_time()); - time_period total_time (start_time, end_time); - logfile << "\n\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length(); - //total_time.length().hours(); - logfile.close(); + ptime end_time(second_clock::local_time()); + time_period total_time (start_time, end_time); + logfile << "\n\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length(); + //total_time.length().hours(); + logfile.close(); + busy = 0; return err; } @@ -490,8 +508,11 @@ ModPackage fileToModPackage(fstream &fil void recompileAll(vector installedMods) { + busy = 1; using namespace boost::gregorian; using namespace boost::posix_time; + using boost::lexical_cast; + using boost::bad_lexical_cast; setStatusArea("Importing levels..."); //setStatusArea("Recompiling Data..."); @@ -550,9 +571,9 @@ void recompileAll(vector install } importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Install.log"; - printf(statusString,"%d/%i\0",j,numberOfDats); + setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats - setStatusArea("Importing " + dir_itr->path().filename() + " " + statusString); + setStatusArea("Step " + lexical_cast(j) + '/' + lexical_cast(numberOfDats)+ ": Importing " + dir_itr->path().filename() + " "); system(importCommand.c_str()); //Sleep(1000); @@ -563,27 +584,27 @@ void recompileAll(vector install } catch ( const std::exception & ex ) { - - remove("Install.log"); - ofstream logfile("Install.log"); - - + + remove("Install.log"); + ofstream logfile("Install.log"); + + logfile << "Warning, exception " << ex.what() << "!"; setStatusArea("Warning, exception " + (string)ex.what() + "!"); -logfile.close(); + logfile.close(); } } } catch( const std::exception & ex ) { - - remove("Install.log"); - ofstream logfile("Install.log"); - - - logfile << "Warning, exception " << ex.what() << "!"; - setStatusArea("Warning, exception " + (string)ex.what() + "!"); -logfile.close(); + + remove("Install.log"); + ofstream logfile("Install.log"); + + + logfile << "Warning, exception " << ex.what() << "!"; + setStatusArea("Warning, exception " + (string)ex.what() + "!"); + logfile.close(); } } @@ -622,9 +643,9 @@ logfile.close(); } importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Install.log"; - printf(statusString,"%d/%i\0",j,numberOfDats); + setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats - setStatusArea("Importing " + dir_itr->path().filename() + " " + statusString); + setStatusArea("Step " + lexical_cast(j) + '/' + lexical_cast(numberOfDats)+ ": Importing " + dir_itr->path().filename() + " "); system(importCommand.c_str()); @@ -633,37 +654,38 @@ logfile.close(); } catch ( const std::exception & ex ) { - - remove("Install.log"); - ofstream logfile("Install.log"); - - - logfile << "Warning, exception " << ex.what() << "!"; - setStatusArea("Warning, exception " + (string)ex.what() + "!"); -logfile.close(); + + remove("Install.log"); + ofstream logfile("Install.log"); + + + logfile << "Warning, exception " << ex.what() << "!"; + setStatusArea("Warning, exception " + (string)ex.what() + "!"); + logfile.close(); }} } logfile << "Writing config file"; writeInstalledMods(installedMods); setProgressBar(1000); setStatusArea("Done! You can now play Oni."); - - ptime end_time(second_clock::local_time()); - time_period total_time (start_time, end_time); - - - ofstream logfile2("Install.log", ios::app | ios::ate); - string outstring = (string)"\n\nGlobalization ended " + to_simple_string(end_time) + "\nThe process took ";// + (string)total_time.length(); - - logfile2 << "\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length(); - - //logfile2.write(outstring.c_str(), outstring.length()); -logfile2.close(); - //total_time.length().hours(); - + ptime end_time(second_clock::local_time()); + time_period total_time (start_time, end_time); + + + ofstream logfile2("Install.log", ios::app | ios::ate); + string outstring = (string)"\n\nGlobalization ended " + to_simple_string(end_time) + "\nThe process took ";// + (string)total_time.length(); + + logfile2 << "\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length(); + + //logfile2.write(outstring.c_str(), outstring.length()); + logfile2.close(); + + //total_time.length().hours(); + Sleep(1000); setProgressBar(0); + busy = 0; } void writeInstalledMods(vector installedMods) @@ -868,8 +890,8 @@ bool MainWindow::Create( wxWindow* paren CreateControls(); SetIcon(GetIconResource(wxT("oni_special.ico"))); Centre(); - - + + ////@end MainWindow creation return true; } @@ -957,7 +979,7 @@ void MainWindow::CreateControls() itemMenu44->Append(wxID_ABOUT, _("About"), wxEmptyString, wxITEM_NORMAL); menuBar->Append(itemMenu44, _("Help")); itemFrame1->SetMenuBar(menuBar); - + wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL); itemFrame1->SetSizer(itemBoxSizer2); @@ -1115,15 +1137,15 @@ void MainWindow::CreateControls() if(strImportOption == "-import:nosep") NoSepRadio->SetValue(true); else SepRadio->SetValue(true); - - + + #ifdef WIN32 RedirectIOToConsole(); HWND hWnd = GetConsoleWindow(); ShowWindow( hWnd, SW_HIDE ); #endif - - //MainWindow::SetSize(MainWindow::GetRect().GetWidth(), MainWindow::GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight() ); + + //MainWindow::SetSize(MainWindow::GetRect().GetWidth(), MainWindow::GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight() ); } @@ -1217,8 +1239,8 @@ wxIcon MainWindow::GetIconResource( cons wxUnusedVar(name); if (name == _T("oni_special.ico")) { - // wxIcon icon(_T("oni_special.ico"), wxBITMAP_TYPE_ICO); - // return icon; + // wxIcon icon(_T("oni_special.ico"), wxBITMAP_TYPE_ICO); + // return icon; } return wxNullIcon; ////@end MainWindow icon retrieval @@ -1268,19 +1290,17 @@ void MainWindow::OnModsCheckboxList1Togg void MainWindow::OnOptionsClick( wxCommandEvent& event ) { - - - - if (!event.GetInt() ) { OptionsPanel->Hide(); - MainWindow::SetSize(MainWindow::GetRect().GetWidth(), MainWindow::GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight());} + this->SetSize(this->GetRect().GetWidth(), this->GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight());} else { - //Uncomment this when we release, it gets annoying if you are testing globalization a lot ;) - //wxMessageDialog* YesNoDialog = new wxMessageDialog(this, "WARNING: These options are for advanced users only, use with caution.", "AE Installer Alert", wxOK | wxICON_EXCLAMATION , wxDefaultPosition); - //YesNoDialog->ShowModal(); +// Uncomment this when we release, it gets annoying if you are testing globalization a lot ;) + wxMessageDialog* YesNoDialog = new wxMessageDialog(this, "WARNING: These options are for advanced users only, use with caution.", + "AE Installer Alert", wxOK | wxICON_EXCLAMATION , wxDefaultPosition); + YesNoDialog->ShowModal(); OptionsPanel->Show(); - MainWindow::SetSize(MainWindow::GetRect().GetWidth(), MainWindow::GetRect().GetHeight()+OptionsPanel->GetRect().GetHeight()); + this->SetSize(this->GetRect().GetWidth(), this->GetRect().GetHeight()+OptionsPanel->GetRect().GetHeight()+1); + this->SetSize(this->GetRect().GetWidth(), this->GetRect().GetHeight()-1); } } @@ -1320,19 +1340,21 @@ void MainWindow::OnInstallButtonClick( w localPackages.push_back("Globalize"); for(int i = 0; i < globalPackages.size(); i++) if(Mods_CheckboxList->IsChecked(i)) localPackages.push_back( globalPackages[i].modStringName ); if ( !localPackages.empty() ) { - + //MainWindow::MainWindow().Hide(); // boost::thread thrd2(recompileAll(localPackages) ); //MainWindow::MainWindow().Show(); + this->InstallButton->Disable(); + this->ReglobalizeButton->Disable(); #ifdef WIN32 recompile packages(localPackages); boost::thread thrd(packages); #else - this->Disable(); recompileAll(localPackages); - this->Enable(); #endif + this->InstallButton->Enable(); + this->ReglobalizeButton->Enable(); } @@ -1459,6 +1481,7 @@ void MainWindow::refreshMods (vectorShowModal() == wxID_NO) { //if the user said no... - + } else { - + this->InstallButton->Disable(); + this->ReglobalizeButton->Disable(); #ifdef WIN32 - boost::thread thrd2(globalizeData); - //globalizeData(); - //boost::thread::create_thread(&globalizeData); - // boost::thread_group Tg; - // Tg.create_thread( &globalizeData(), this ); + boost::thread thrd2(globalizeData); + //globalizeData(); + //boost::thread::create_thread(&globalizeData); + // boost::thread_group Tg; + // Tg.create_thread( &globalizeData(), this ); #else - globalizeData(); - setProgressBar(1000); - setStatusArea("Done!"); + globalizeData(); #endif -} + + this->InstallButton->Enable(); + this->ReglobalizeButton->Enable(); + } } /*