ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/AE/Installer/trunk/source/main_window.cpp
(Generate patch)

Comparing AE/Installer/trunk/source/main_window.cpp (file contents):
Revision 356 by gumby, Thu Jun 18 22:30:30 2009 UTC vs.
Revision 357 by gumby, Fri Jun 19 21:32:17 2009 UTC

# Line 34 | Line 34 | const string strInstallerVersion = "1.0"
34   const bool SPLIT = 1;
35   const bool NOT_SPLIT = 0;
36   bool splitInstances = SPLIT;
37 <
37 > bool busy = 0;
38   #ifdef WIN32
39   const string strOniSplit = "Onisplit.exe";
40   string strImportOption = "-import:nosep";
# Line 60 | Line 60 | using namespace std;
60  
61   int globalizeData(void)
62   {
63 <            using boost::lexical_cast;
64 <    using boost::bad_lexical_cast;
65 < // using namespace boost::posix_time;
63 >        busy = 1;
64 >        using boost::lexical_cast;
65 >        using boost::bad_lexical_cast;
66 >        // using namespace boost::posix_time;
67          using namespace boost::gregorian;
68          using namespace boost::posix_time;
69          ptime start_time(second_clock::local_time());
# Line 76 | Line 77 | int globalizeData(void)
77          ofstream logfile("Globalize.log");
78          logfile << "Globalization started " << to_simple_string(start_time) << endl;
79          try {
80 <                
80 >
81                  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.
82                  //const vector<double> ck(cv, &cv[CvSize]);
83                  vector<string> levels;
# Line 95 | Line 96 | int globalizeData(void)
96                  path Animations = "../GameDataFolder/level0_Animations";
97                  path TRAC = Animations / "level0_TRAC";
98                  path TRAM = Animations / "level0_TRAM";
99 <                
99 >
100                  vector<path> GDFPaths;
101                  GDFPaths.push_back(Characters);
102                  GDFPaths.push_back(Particles);
# Line 103 | Line 104 | int globalizeData(void)
104                  GDFPaths.push_back(Sounds);
105                  GDFPaths.push_back(TRAC);
106                  GDFPaths.push_back(TRAM);
107 <                
108 <                        
107 >
108 >
109                  path VanillaCharacters = "packages/VanillaDats/level0_Final/level0_Characters/level0_Characters.oni";
110                  path VanillaParticles = "packages/VanillaDats/level0_Final/level0_Particles/level0_Particles.oni";
111                  path VanillaTextures  = "packages/VanillaDats/level0_Final/level0_Textures/level0_Textures.oni";
# Line 114 | Line 115 | int globalizeData(void)
115                  path VanillaTRAM = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAM.oni";
116  
117                  vector<path> VanillaPaths;
118 <                
118 >
119                  VanillaPaths.push_back(VanillaCharacters);
120                  VanillaPaths.push_back(VanillaParticles);
121                  VanillaPaths.push_back(VanillaTextures);
122                  VanillaPaths.push_back(VanillaSounds);
123                  VanillaPaths.push_back(VanillaTRAC);
124                  VanillaPaths.push_back(VanillaTRAM);
125 <                
125 >
126                  /*
127                  if (exists("../GameDataFolder/"))
128                  {
# Line 142 | Line 143 | int globalizeData(void)
143                  setStatusArea("Creating needed directories...");
144                  logfile <<  "Creating needed directories...\n";
145                  create_directory( "../GameDataFolder/" );
146 <                
146 >
147                  create_directory( "packages" );
148 <                
148 >
149                  if (exists("packages/VanillaDats")) remove_all("packages/VanillaDats");
150                  create_directory( "packages/VanillaDats" );
151 <                
151 >
152                  create_directory( "packages/VanillaDats/level0_Final/" );
153                  //blah blah finish this.
154                  //logfile <<  "packages/VanillaDats/level0_Final/ created";
# Line 162 | Line 163 | int globalizeData(void)
163                  int num_levels = 0;
164                  for(int i = 1; i < 15; i++)
165                  {
166 <                                if (exists("../../GameDataFolder/level" + levels[i] + "_Final.dat")) {
166 >                        if (exists("../../GameDataFolder/level" + levels[i] + "_Final.dat")) {
167                                  num_levels++;
168  
169                          }
# Line 171 | Line 172 | int globalizeData(void)
172                  int total_steps =  8 + 2 * num_levels;
173                  for(int i = 0; i < 15; i++)
174                  {
175 <                        
175 >
176                          //printf(levels[i],"%d",levels[i]); // int to char array
177 <                        
177 >
178                          if (exists("../../GameDataFolder/level" + levels[i] + "_Final.dat")) {
179                                  logfile << "level" << levels[i] << "_Final\n";
180                                  logfile << "\tExporting level" << levels[i] << "_Final.dat\n";
181                                  //printf(Step_x_x,"Step %d/%d: exporting level%d_final.dat", parts_done + 1,, levels[i]); setStatusArea((string)Step_x_x);
182                                  setStatusArea("Step " + lexical_cast<std::string>(parts_done + 1) + "/" + lexical_cast<std::string>(total_steps) + " exporting level" + levels[i]+"_Final.dat");
183                                  create_directory( "../GameDataFolder/level" + levels[i] + "_Final" );
184 < //                              setStatusArea(strOniSplit + " -export ../GameDataFolder/level" + levels[i] + "_Final ../../GameDataFolder/level" + levels[i] + "_Final.dat");
184 >                                //                              setStatusArea(strOniSplit + " -export ../GameDataFolder/level" + levels[i] + "_Final ../../GameDataFolder/level" + levels[i] + "_Final.dat");
185                                  system((strOniSplit + " -export ../GameDataFolder/level" + levels[i] + "_Final ../../GameDataFolder/level" + levels[i] + "_Final.dat").c_str());
186                                  create_directory( "packages/VanillaDats/level" + levels[i] + "_Final" );
187                                  create_directory( "packages/VanillaDats/level" + levels[i] + "_Final/level" + levels[i] + "_Final" );
# Line 256 | Line 257 | int globalizeData(void)
257                                                  else if (dir_itr->path().filename().substr(0,4) == "AGDB"
258                                                          || dir_itr->path().filename().substr(0,4) == "TRCM") {
259                                                                  cout <<dir_itr->path().filename() << "\n";
260 <                                        
260 >
261                                                                  if(!exists( Archive / dir_itr->filename())) rename(dir_itr->path(), Archive / dir_itr->filename());
262                                                                  else remove(dir_itr->path());
263                                                  }
# Line 269 | Line 270 | int globalizeData(void)
270                                          }
271  
272  
273 <                                                
273 >
274                                  }
275                                  logfile << "\tCleaning up TXMPs...\n";
276                                  system( (strOniSplit + " -move:delete " + Textures.string() + " ../GameDataFolder/level" + levels[i] + "_Final/TXMP*.oni").c_str());
277                                  parts_done++;
278  
279                                  setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) ));
280 <                                
280 >
281                          }
282                  }
283                  logfile << "Reimporting levels\n";
# Line 289 | Line 290 | int globalizeData(void)
290                          system( (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levels[i] + "_Final packages/VanillaDats/level" + levels[i] + "_Final/level"
291                                  + levels[i] + "_Final/level" + levels[i] + "_Final.oni > Globalize.oni").c_str());
292                          setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) ));
293 <                                parts_done++;
293 >                        parts_done++;
294                  }
295                  create_directory( VanillaCharacters.parent_path() );
296                  create_directory( VanillaParticles.parent_path() );
297                  create_directory( VanillaTextures.parent_path() );
298                  create_directory( VanillaSounds.parent_path() );
299                  create_directory( VanillaAnimations.remove_filename() );
300 <                
300 >
301                  for(int j = 0; j < GDFPaths.size(); j++) {
302                          logfile << "\tReimporting " << GDFPaths[j].filename() << ".oni\n";
303                          setStatusArea("Step" + lexical_cast<std::string>(parts_done + 1) + "/" + lexical_cast<std::string>(total_steps) + ": reimporting " + GDFPaths[j].filename() );
# Line 304 | Line 305 | int globalizeData(void)
305                          parts_done++;
306                          setProgressBar( (int)(1000 * (float)(parts_done) / (float)(total_steps) ));
307                  }
308 < /*
308 >                /*
309                  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) ));
310                  system((strOniSplit + " " + strImportOption + " " + Characters.string() + " " + VanillaCharacters.string()).c_str());
311                  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) ));
# Line 320 | Line 321 | int globalizeData(void)
321                  system((strOniSplit + " " + strImportOption + " " + TRAM.string() + " " + VanillaTRAM.string()).c_str());
322                  //parts_done++; setStatusArea((string)"Copying level scripts...");setProgressBar( (int)(1000 * (float)(parts_done) / (float)(7 + 2 * num_levels) ));
323                  if (exists("../GameDataFolder/IGMD")) remove_all("../GameDataFolder/IGMD");
324 < */
324 >                */
325                  create_directory((path)"../GameDataFolder/IGMD");
326                  copy((path)"packages/VanillaBSL/", (path)"../GameDataFolder");
327                  setProgressBar( 1000 );
328                  setStatusArea((string)"Done! Now select your mod packages and click install.");
329 <        //      while(1) Sleep(-1);
330 <                
329 >                //      while(1) Sleep(-1);
330 >
331          }
332          catch (exception ex) {
333                  setStatusArea("Warning, handled exception: " + (string)ex.what());
334          }
334        
335                ptime end_time(second_clock::local_time());
336                time_period total_time (start_time, end_time);
337                logfile << "\n\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length();
338                //total_time.length().hours();
339        logfile.close();
335  
336 +        ptime end_time(second_clock::local_time());
337 +        time_period total_time (start_time, end_time);
338 +        logfile << "\n\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length();
339 +        //total_time.length().hours();
340 +        logfile.close();
341 +        busy = 0;
342          return err;
343   }
344  
# Line 490 | Line 491 | ModPackage fileToModPackage(fstream &fil
491  
492   void recompileAll(vector<string> installedMods)
493   {
494 +        busy = 1;
495          using namespace boost::gregorian;
496          using namespace boost::posix_time;
497 +        using boost::lexical_cast;
498 +        using boost::bad_lexical_cast;
499          
500          setStatusArea("Importing levels...");
501          //setStatusArea("Recompiling Data...");
# Line 550 | Line 554 | void recompileAll(vector<string> install
554                                                  }
555                                                  importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Install.log";
556  
557 <                                                printf(statusString,"%d/%i\0",j,numberOfDats);  
557 >                                                
558                                                  setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats
559 <                                                setStatusArea("Importing " +  dir_itr->path().filename() + " " + statusString);
559 >                                                setStatusArea("Step " + lexical_cast<std::string>(j) + '/' + lexical_cast<std::string>(numberOfDats)+ ": Importing " +  dir_itr->path().filename() + " ");
560  
561                                                  system(importCommand.c_str());
562                                                  //Sleep(1000);
# Line 563 | Line 567 | void recompileAll(vector<string> install
567                                  }
568                                  catch ( const std::exception & ex )
569                                  {
570 <                                        
571 <        remove("Install.log");
572 <        ofstream logfile("Install.log");
573 <        
574 <        
570 >
571 >                                        remove("Install.log");
572 >                                        ofstream logfile("Install.log");
573 >
574 >
575                                          logfile << "Warning, exception " << ex.what() << "!";
576                                          setStatusArea("Warning, exception " + (string)ex.what() + "!");
577 < logfile.close();        
577 >                                        logfile.close();        
578                                  }
579                          }
580  
581                  }
582                  catch( const std::exception & ex ) {
583 <        
584 <        remove("Install.log");
585 <        ofstream logfile("Install.log");
586 <        
587 <        
588 <                                        logfile << "Warning, exception " << ex.what() << "!";
589 <                                        setStatusArea("Warning, exception " + (string)ex.what() + "!");
590 < logfile.close();
583 >
584 >                        remove("Install.log");
585 >                        ofstream logfile("Install.log");
586 >
587 >
588 >                        logfile << "Warning, exception " << ex.what() << "!";
589 >                        setStatusArea("Warning, exception " + (string)ex.what() + "!");
590 >                        logfile.close();
591                  }
592  
593          }
# Line 622 | Line 626 | logfile.close();
626                                          }
627                                          importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat >> Install.log";
628  
629 <                                        printf(statusString,"%d/%i\0",j,numberOfDats);  
629 >
630                                          setProgressBar( (int)(1000 * (float)(j-1) / (float)numberOfDats) ); //100% * dat we're on / total dats
631 <                                        setStatusArea("Importing " +  dir_itr->path().filename() + " " + statusString);
631 >                                        setStatusArea("Step " + lexical_cast<std::string>(j) + '/' + lexical_cast<std::string>(numberOfDats)+ ": Importing " +  dir_itr->path().filename() + " ");
632  
633                                          system(importCommand.c_str());
634  
# Line 633 | Line 637 | logfile.close();
637                          }
638                          catch ( const std::exception & ex )
639                          {
640 <        
641 <        remove("Install.log");
642 <        ofstream logfile("Install.log");
643 <        
644 <        
645 <                                        logfile << "Warning, exception " << ex.what() << "!";
646 <                                        setStatusArea("Warning, exception " + (string)ex.what() + "!");
647 < logfile.close();
640 >
641 >                                remove("Install.log");
642 >                                ofstream logfile("Install.log");
643 >
644 >
645 >                                logfile << "Warning, exception " << ex.what() << "!";
646 >                                setStatusArea("Warning, exception " + (string)ex.what() + "!");
647 >                                logfile.close();
648                          }}
649          }
650          logfile << "Writing config file";
651          writeInstalledMods(installedMods);
652          setProgressBar(1000);
653          setStatusArea("Done! You can now play Oni.");
650        
651                ptime end_time(second_clock::local_time());
652                time_period total_time (start_time, end_time);
653                        
654        
655                ofstream logfile2("Install.log", ios::app | ios::ate);
656                string outstring = (string)"\n\nGlobalization ended " + to_simple_string(end_time) + "\nThe process took ";// + (string)total_time.length();
657                
658                logfile2 << "\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length();
659                
660                //logfile2.write(outstring.c_str(), outstring.length());
661 logfile2.close();
654  
655 <                //total_time.length().hours();
656 <        
655 >        ptime end_time(second_clock::local_time());
656 >        time_period total_time (start_time, end_time);
657 >
658 >
659 >        ofstream logfile2("Install.log", ios::app | ios::ate);
660 >        string outstring = (string)"\n\nGlobalization ended " + to_simple_string(end_time) + "\nThe process took ";// + (string)total_time.length();
661 >
662 >        logfile2 << "\nGlobalization ended " << to_simple_string(end_time) << "\nThe process took " << total_time.length();
663 >
664 >        //logfile2.write(outstring.c_str(), outstring.length());
665 >        logfile2.close();
666 >
667 >        //total_time.length().hours();
668 >
669          Sleep(1000);
670          setProgressBar(0);
671 +        busy = 0;
672   }
673  
674   void writeInstalledMods(vector<string> installedMods)
# Line 868 | Line 873 | bool MainWindow::Create( wxWindow* paren
873          CreateControls();
874          SetIcon(GetIconResource(wxT("oni_special.ico")));
875          Centre();
876 <        
877 <        
876 >
877 >
878          ////@end MainWindow creation
879          return true;
880   }
# Line 957 | Line 962 | void MainWindow::CreateControls()
962          itemMenu44->Append(wxID_ABOUT, _("About"), wxEmptyString, wxITEM_NORMAL);
963          menuBar->Append(itemMenu44, _("Help"));
964          itemFrame1->SetMenuBar(menuBar);
965 <
965 >        
966          wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
967          itemFrame1->SetSizer(itemBoxSizer2);
968  
# Line 1115 | Line 1120 | void MainWindow::CreateControls()
1120  
1121          if(strImportOption == "-import:nosep") NoSepRadio->SetValue(true);
1122          else SepRadio->SetValue(true);
1123 <        
1124 <        
1123 >
1124 >
1125   #ifdef WIN32
1126          RedirectIOToConsole();
1127          HWND hWnd = GetConsoleWindow();
1128          ShowWindow( hWnd, SW_HIDE );
1129   #endif
1130 <        
1131 <                //MainWindow::SetSize(MainWindow::GetRect().GetWidth(), MainWindow::GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight() );
1130 >
1131 >        //MainWindow::SetSize(MainWindow::GetRect().GetWidth(), MainWindow::GetRect().GetHeight()-OptionsPanel->GetRect().GetHeight() );
1132   }
1133  
1134  
# Line 1217 | Line 1222 | wxIcon MainWindow::GetIconResource( cons
1222          wxUnusedVar(name);
1223          if (name == _T("oni_special.ico"))
1224          {
1225 <        //      wxIcon icon(_T("oni_special.ico"), wxBITMAP_TYPE_ICO);
1226 <        //      return icon;
1225 >                //      wxIcon icon(_T("oni_special.ico"), wxBITMAP_TYPE_ICO);
1226 >                //      return icon;
1227          }
1228          return wxNullIcon;
1229          ////@end MainWindow icon retrieval
# Line 1270 | Line 1275 | void MainWindow::OnOptionsClick( wxComma
1275   {
1276  
1277  
1278 <        
1278 >
1279  
1280          if (!event.GetInt() ) {
1281                  OptionsPanel->Hide();
# Line 1320 | Line 1325 | void MainWindow::OnInstallButtonClick( w
1325          localPackages.push_back("Globalize");
1326          for(int i = 0; i < globalPackages.size(); i++) if(Mods_CheckboxList->IsChecked(i)) localPackages.push_back( globalPackages[i].modStringName );
1327          if ( !localPackages.empty() )   {
1328 <
1328 >        
1329                  //MainWindow::MainWindow().Hide();      
1330                  //      boost::thread thrd2(recompileAll(localPackages) );
1331                  //MainWindow::MainWindow().Show();
1332 +                this->InstallButton->Disable();
1333 +                this->ReglobalizeButton->Disable();
1334   #ifdef WIN32
1335                  recompile packages(localPackages);
1336                  boost::thread thrd(packages);
1337   #else
1331                this->Disable();
1338                  recompileAll(localPackages);
1333                this->Enable();
1339   #endif
1340  
1341 +                this->InstallButton->Enable();
1342 +                this->ReglobalizeButton->Enable();
1343          }
1344  
1345  
# Line 1459 | Line 1466 | void MainWindow::refreshMods (vector<str
1466  
1467   void MainWindow::OnLoadClick( wxCommandEvent& event )
1468   {
1469 +        if (busy == 1) return;
1470          static const wxChar *FILETYPES = _T(
1471                  "Mod Loadouts (*.cfg)|*.cfg|"
1472                  "All files (*.*)|*.*"
# Line 1483 | Line 1491 | void MainWindow::OnLoadClick( wxCommandE
1491  
1492   void MainWindow::OnSaveClick( wxCommandEvent& event )
1493   {
1494 +        if (busy == 1) return;
1495          static const wxChar *FILETYPES = _T(
1496                  "Mod Loadouts (*.cfg)|*.cfg|"
1497                  "All files (*.*)|*.*"
# Line 1541 | Line 1550 | void MainWindow::OnReGlobalizeButtonClic
1550          wxMessageDialog* YesNoDialog = new wxMessageDialog(this,                        "WARNING: This will DELETE the Edition's GameDataFolder and reglobalize all of your data. \n Are you SURE you want to do this? ", "AE Installer Alert",  wxYES_NO | wxICON_EXCLAMATION  , wxDefaultPosition);
1551  
1552          if (YesNoDialog->ShowModal() == wxID_NO) { //if the user said no...
1553 <                
1553 >
1554          }
1555          else {
1547                
1556          
1557 +                this->InstallButton->Disable();
1558 +                this->ReglobalizeButton->Disable();
1559  
1560   #ifdef WIN32
1561  
1562 <        boost::thread thrd2(globalizeData);
1563 <        //globalizeData();
1564 <        //boost::thread::create_thread(&globalizeData);
1565 <        //       boost::thread_group Tg;
1566 <        // Tg.create_thread( &globalizeData(), this );
1562 >                boost::thread thrd2(globalizeData);
1563 >                //globalizeData();
1564 >                //boost::thread::create_thread(&globalizeData);
1565 >                //       boost::thread_group Tg;
1566 >                // Tg.create_thread( &globalizeData(), this );
1567   #else
1568 <        globalizeData();
1569 <        setProgressBar(1000);
1570 <        setStatusArea("Done!");
1568 >                globalizeData();
1569 >                setProgressBar(1000);
1570 >                setStatusArea("Done!");
1571   #endif
1572 < }
1572 >                
1573 >                this->InstallButton->Enable();
1574 >                this->ReglobalizeButton->Enable();
1575 >        }
1576  
1577   }
1578   /*

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)