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

Comparing AE/Installer/trunk/source/aeinstallerapp.cpp (file contents):
Revision 401 by gumby, Tue Jul 7 00:34:21 2009 UTC vs.
Revision 516 by iritscen, Wed Apr 28 10:40:52 2010 UTC

# Line 1 | Line 1
1 < /////////////////////////////////////////////////////////////////////////////
2 < // Name:        aeinstallerapp.cpp
3 < // Purpose:    
4 < // Author:      
5 < // Modified by:
6 < // Created:     07/05/2009 17:23:39
7 < // RCS-ID:      
8 < // Copyright:  
9 < // Licence:    
10 < /////////////////////////////////////////////////////////////////////////////
1 > /***************************************************************************\
2 > | Project: AE Installer                                                                                                         |
3 > | By: Gumby & Iritscen                                                                                                          |
4 > | File: AEInstallerApp.cpp                                                                                                      |
5 > | Function: Sets up the main application window.                                                        |
6 > | Created: 07/05/2009 17:23:39                                                                                          |
7 > \***************************************************************************/
8 >
9 > #include "boost/filesystem.hpp"
10 > #include "boost/lexical_cast.hpp" // int -> string
11   #include "boost/thread.hpp"
12 < #include <boost/thread/mutex.hpp>
12 > #include "boost/thread/mutex.hpp"
13   #include <fstream>
14 < #include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
15 < #include "boost/lexical_cast.hpp" //int -> string
16 < using namespace boost::filesystem;
17 < // For compilers that support precompilation, includes "wx/wx.h".
18 < #include "wx/wxprec.h"
19 <
20 < #ifdef __BORLANDC__
21 < #pragma hdrstop
22 < #endif
23 <
24 < #ifndef WX_PRECOMP
25 < #include "wx/wx.h"
26 < #endif
14 > #include <string>
15 > #include "installer.h"
16 > #include "aeinstallerapp.h"
17  
18   ////@begin includes
19   ////@end includes
20  
21 < #include "aeinstallerapp.h"
22 < #include <string>
21 > extern int updateStatus;
22 > extern bool installerJustUpdated;
23 > Install_info_cfg currentAE, updateAE;
24 > MainWindow* TheWindow;
25  
26   ////@begin XPM images
27   ////@end XPM images
# Line 87 | Line 79 | void AEInstallerApp::Init()
79   * Initialisation for AEInstallerApp
80   */
81  
82 + /* The OnInit() routine is used to check whether the Installer has the software *\
83 + |  it needs to install mods, whether there is an available update, and whether   |
84 + \* the user has globalized yet, to allow mods to be installed.                                  */
85   bool AEInstallerApp::OnInit()
86   {    
87          ////@begin AEInstallerApp initialisation
88          // Remove the comment markers above and below this block
89          // to make permanent changes to the code.
95        
90   #if wxUSE_XPM
91          wxImage::AddHandler(new wxXPMHandler);
92   #endif
# Line 110 | Line 104 | bool AEInstallerApp::OnInit()
104          ////@end AEInstallerApp initialisation
105          TheWindow = mainWindow;
106          
107 +        // Anything after this is done after the window appears...
108 +        
109 +        if (!CheckForRequiredSoftware())
110 +        {
111 +                TheWindow->Close(); // CheckForRequiredSoftware() will have notified the user of what they are missing, so we just quit now
112 +                return true;
113 +        }
114 +        
115 +        if (updateStatus) // updateStatus was set when MainWindow::CreateControls() was called during initialization of the window
116 +        {
117 +                string updateMsg = "An update for the Anniversary Edition is available.\n"
118 +                                                   "Do you wish to update to Edition version " + updateAE.AEVersion + "?\n"
119 +                                                   "(Current version is " + currentAE.AEVersion + ")\n"; // ...so we tack the rest on in a second command
120 +                wxMessageDialog* updateNotification;
121 +                
122 +                switch (updateStatus) // for the meanings of these return values, see the comments preceding installer.cpp's GetUpdateStatus()
123 +                {
124 +                        case UPDATE_LOG_READ_ERR:
125 +                        {
126 +                                if (exists("Update.log")) remove("Update.log");
127 +                                ofstream logfile("Update.log");
128 +                                logfile << "Error: A necessary .cfg file could not be read.";
129 +                        } // brackets are needed due to the initialization of the ofstream; silly C!
130 +                                break;
131 +                        case UPDATE_MNTH_REQD_ERR:
132 +                                updateMsg = "There is a patch in the updates/ folder, but it patches the\n";
133 +                                updateMsg = updateMsg + updateAE.AEVersion.substr(0, updateAE.AEVersion.length() - 1) + " release; it cannot update this version of the Edition.";
134 +                                updateNotification = new wxMessageDialog(TheWindow, updateMsg.c_str(), "AE Installer Alert", wxOK | wxICON_EXCLAMATION, wxDefaultPosition);
135 +                                updateNotification->ShowModal();
136 +                                break;
137 +                        case UPDATE_SIMP_AVAIL: // there's an update with no globalization or Installer strings attached
138 +                                updateNotification = new wxMessageDialog(TheWindow, updateMsg.c_str(), "AE Installer Alert", wxYES_NO | wxICON_EXCLAMATION, wxDefaultPosition);
139 +                                if (updateNotification->ShowModal() == wxID_YES)
140 +                                        ProcessAEUpdate(&currentAE, &updateAE, &installerJustUpdated);
141 +                                break;
142 +                        case UPDATE_PKG_AVAIL: // there's an update with no globalization or Installer strings attached
143 +                                updateMsg = (string)"One or individual package updates for the Anniversary Edition is available.\n\n" +
144 +                                        (string)"Please note that the AE team assumes no responsibility for the content of third party mods " +
145 +                                        (string)"nor effects that a third party mod may have on your install.\n\n" +
146 +                                        (string)"Do you wish to install these update(s)?";
147 +                                updateNotification = new wxMessageDialog(TheWindow, updateMsg.c_str(), "AE Installer Alert", wxYES_NO | wxICON_EXCLAMATION, wxDefaultPosition);
148 +                                if (updateNotification->ShowModal() == wxID_YES)
149 +                                        ProcessPackageUpdates("../updates", "./packages");
150 +                                break;
151 +                        case UPDATE_GLOB_AVAIL: // there's an update with globalization strings attached
152 +                                updateMsg = updateMsg + "**Note that the update requires you to reglobalize, which will take 5-20 minutes.**\n" +
153 +                                                                                "Before clicking Yes, MAKE SURE you have backed up any mods not installed through\n " +
154 +                                                                                "the Installer, such as plug-ins or direct OniSplit imports.";
155 +                                updateNotification = new wxMessageDialog(TheWindow, updateMsg.c_str(), "AE Installer Alert", wxYES_NO | wxICON_EXCLAMATION, wxDefaultPosition);
156 +                                if (updateNotification->ShowModal() == wxID_YES)
157 +                                        ProcessAEUpdate(&currentAE, &updateAE, &installerJustUpdated);
158 +                                break;
159 +                        case UPDATE_INST_AVAIL: // there's an update with Installer strings attached (globalization is irrelevant while the Installer is not yet updated)
160 +                                updateMsg = updateMsg + "**Note that the update requires the Installer to update itself.**\n" +
161 +                                                                                "If you click Yes, the Installer will quit and re-launch itself, then\n" +
162 +                                                                                "you will be prompted to begin the installation.";
163 +                                updateNotification = new wxMessageDialog(TheWindow, updateMsg.c_str(), "AE Installer Alert", wxYES_NO | wxICON_EXCLAMATION, wxDefaultPosition);
164 +                                if (updateNotification->ShowModal() == wxID_YES)
165 +                                {
166 +                                        if (ProcessInstallerUpdate(&currentAE, &updateAE)) // there's an intentional logic gap here: if the user clicks "Yes"...
167 +                                        {                                                                                                  // ...and then ProcessInstallerUpdate has an error and returns false, the logic gap results...
168 +                                                TheWindow->Close();                                                        // ...in the code continuing to execute down through case UPDATE_INST_REPL_ERR
169 +                                                return true;
170 +                                        }
171 +                                }
172 +                                else
173 +                                        break;
174 +                        case UPDATE_INST_REPL_ERR: // the Installer replacement failed, user has to do it :-(
175 +                                updateMsg = "The Installer replacement process failed for some reason.\n";
176 +                                updateMsg = updateMsg + "In order for the update to continue, go into the folder Edition/updates/" + strEUFN + "/install/ and " +
177 +                                                                                "drag the Installer to Edition/install/, replacing the current Installer application, then launch the " +
178 +                                                                                "new version. Click Yes to quit.";
179 +                                updateNotification = new wxMessageDialog(TheWindow, updateMsg.c_str(), "AE Installer Alert", wxYES_NO | wxICON_EXCLAMATION, wxDefaultPosition);
180 +                                if (updateNotification->ShowModal() == wxID_YES)
181 +                                        TheWindow->Close();
182 +                                return true;
183 +                }
184 +        }
185 +
186 +        CheckForGlobalization(false); // function will prompt user and initiate globalization if not done already
187 +        
188 +        return true;
189 + }
190 +
191 + bool CheckForRequiredSoftware(void)
192 + {
193   #ifdef WIN32
194 <         HKEY hKey;
195 <         if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\.NETFramework\\policy\\v2.0", 0L, KEY_READ , &hKey) == ERROR_SUCCESS) {
196 <                 wxMessageDialog* MonoDialogOfDeath = new wxMessageDialog(TheWindow, "You don't have .NET 2.0 installed! .NET is a framework required by the Edition. You can download it from:\nhttp://gumby.oni2.net/dotnet\nPlease install .NET 2.0, then open this Installer again. \n\nWould you like to open the download webpage?",  "AE Installer Alert",  wxYES_NO | wxICON_EXCLAMATION        , wxDefaultPosition);
197 <                 if(MonoDialogOfDeath->ShowModal() == wxID_YES) {
194 >        // test for .NET 2.0 or higher
195 >        HKEY hKey;
196 >        if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\.NETFramework\\policy\\v2.0", 0L, KEY_READ , &hKey) == ERROR_SUCCESS)
197 >        {
198 >                string dotnetMsg = "You don't have .NET 2.0 installed! .NET is a framework required by the Edition.\n";
199 >                dotnetMsg = dotnetMsg + "You can download it from:\n" +
200 >                                                                "http://gumby.oni2.net/dotnet\n" +
201 >                                                                "Please install .NET 2.0, then open this Installer again.\n\n" +
202 >                                                                "Would you like to open the download webpage?";
203 >                wxMessageDialog* DotNetDialogOfDeath = new wxMessageDialog(TheWindow, dotnetMsg.c_str(), "AE Installer Alert",
204 >                                                                                                                                 wxYES_NO | wxICON_EXCLAMATION  , wxDefaultPosition);
205 >                if (DotNetDialogOfDeath->ShowModal() == wxID_YES)
206                          system("start http://www.microsoft.com/downloads/details.aspx?familyid=0856eacb-4362-4b0d-8edd-aab15c5e04f5");
119                 }
207                  RegCloseKey(hKey);
208 <                TheWindow->Close();
122 <         }
123 < #else
124 <        // test for the third-party mono framework, because without it, on Mac, we are up a creek
125 <        char monoCommand[300] = "which mono >> ";
126 <        strcat(monoCommand, escapePath(system_complete("mono_check.log").string()).c_str());
127 <        system(monoCommand);
128 <        fstream file;
129 <        file.open("mono_check.log");
130 <        string line;
131 <        int line_count = 0;
132 <        while (!file.eof())
133 <        {
134 <                line_count++;
135 <                getline(file, line);
208 >                return false;
209          }
210 <        file.close();
211 <        remove("mono_check.log");
210 > #else // on Mac...
211 >        // test for the third-party "mono" framework, because without it, we are up a creek
212 >        FILE *fWhichMono = NULL;
213 >        char chrWhichMono[32];
214 >        fWhichMono = popen("which mono", "r");
215 >        fgets(chrWhichMono, sizeof(chrWhichMono), fWhichMono);
216 >        pclose(fWhichMono);
217 >        string strWhichMono = (string)chrWhichMono;
218 >        string::size_type loc = strWhichMono.find("mono", 0);
219          
220 <        if (line_count <= 1) // this means that "which mono" returned nothing -- abort! abort! abort!
220 >        if (loc == string::npos) // this means that "which mono" did not return a path leading to the mono binary -- abort! abort! abort!
221          {
222 <                wxMessageDialog* MonoDialogOfDeath = new wxMessageDialog(TheWindow, "You don't have 'mono' installed! 'mono' is a command-line tool required by the Edition. You can download it from:\nhttp://www.go-mono.com/mono-downloads/download.html (OS X 10.4+) or\nhttp://edt.oni2.net/AE/MonoFramework10.3.dmg (OS X 10.3)\n\nPlease install 'mono', then open this Installer again.",  "AE Installer Alert",  wxOK | wxICON_EXCLAMATION     , wxDefaultPosition);
222 >                string monoMsg = "You don't have 'mono' installed! 'mono' is a command-line tool required by the Edition.\n";
223 >                monoMsg = monoMsg + "You can download it from: http://www.go-mono.com/mono-downloads/download.html (OS X 10.4+)\n" +
224 >                                                        "or http://edt.oni2.net/AE/MonoFramework10.3.dmg (OS X 10.3)\n\n" +
225 >                                                        "Please install 'mono', then open this Installer again.";
226 >                wxMessageDialog* MonoDialogOfDeath = new wxMessageDialog(TheWindow, monoMsg.c_str(), "AE Installer Alert", wxOK | wxICON_EXCLAMATION, wxDefaultPosition);
227                  MonoDialogOfDeath->ShowModal();
228 <                TheWindow->Close();
145 <                return true; // it's quittin' time, Joe
228 >                return false; // it's quittin' time, Joe
229          }
230   #endif
231 +        return true;
232 + }
233  
234 <        //anything after this is done after the window appears...
235 <
236 <        if ( !exists("../GameDataFolder") )
234 > bool CheckForGlobalization(bool justDoIt)
235 > {
236 >        if (!exists("../GameDataFolder"))
237          {
238 <                wxMessageDialog* YesNoDialog = new wxMessageDialog(TheWindow,           "You haven't globalized yet! \nYou must globalize to use the Anniversary Edition framework. \nWould you like to globalize now? (This could take a while...)\n(Selecting \"No\" will exit this program...)",  "AE Installer Alert",  wxYES_NO | wxICON_EXCLAMATION       , wxDefaultPosition);
239 <
238 >                string globMsg = "You haven't globalized yet!\n";
239 >                globMsg = globMsg + "You must globalize to use the Anniversary Edition framework.\n" +
240 >                                                        "Would you like to globalize now? (This could take a while...)\n" +
241 >                                                        "(Selecting \"No\" will exit this program...)";
242 >                wxMessageDialog* YesNoDialog = new wxMessageDialog(TheWindow, globMsg.c_str(), "AE Installer Alert", wxYES_NO | wxICON_EXCLAMATION, wxDefaultPosition);
243 >                
244                  if (YesNoDialog->ShowModal() == wxID_NO) // if the user said no...
156                        TheWindow->Close();
157                else
245                  {
246 <                        TheWindow->InstallButton->Disable();
247 <                        TheWindow->ReglobalizeButton->Disable();
161 <
162 < #ifdef WIN32
163 <                        boost::thread thrd3(globalizeData);
164 <                //globalizeData();
165 <                //boost::thread::create_thread(&globalizeData);
166 <                //       boost::thread_group Tg;
167 <                // Tg.create_thread( &globalizeData(), this );
168 < #else
169 <                        globalizeData();
170 < #endif
171 <                
172 <                        TheWindow->InstallButton->Enable();
173 <                        TheWindow->ReglobalizeButton->Enable();
246 >                        TheWindow->Close();
247 >                        return true;
248                  }
249          }
250 <
250 >        else if (!justDoIt)
251 >                return false;
252 >        // Code below this point runs if user clicks "Yes" or if they are never asked but justDoIt is true
253 > #ifdef WIN32
254 >        boost::thread thrd3(globalize2);
255 > #else // cannot use multi-threading in Mac build
256 >        TheWindow->InstallButton->Disable();
257 >        TheWindow->ReglobalizeButton->Disable();
258 >        globalizeData();
259 >        TheWindow->InstallButton->Enable();
260 >        TheWindow->ReglobalizeButton->Enable();
261 > #endif
262 >        
263          return true;
264   }
265  
266 <
267 < void setStatusArea( string s ) {
266 > void setStatusArea(string s)
267 > {
268          wxString wxs(s.c_str(), wxConvUTF8);
269          
270 <        TheWindow->StatusArea->SetStatusText(  wxs );
185 <        //TheWindow->StatusArea->SetStatusText(s.c_str());
186 <        //StatusArea->SetStatusText(_(s.c_str()));
187 <        //(*TheStatusBar)->SetStatusText(_(s.c_str()));
188 <        //AEInstallerApp::
189 <        //      TheWindow->StatusArea->SetStatusText("hi");
190 <        //mainWindow
191 <        //itemFrame1->StatusArea->SetStatusText(_"lol");
192 <        //MainWindow.StatusArea->SetStatusText("hi");
193 <        // class AbstractStatusNotifier { public: virtual void NotifyStatus(const wxString &statusString) = 0; };
194 <        //class StatusBarStatusNotifier : public AbstractStatusNotifier { wxStatusBar *statusbar; StatusBarStatusNotifier(wxStatusBar *bar) : statusbar(bar) { } ;
195 <        //void NotifyStatus(const wxString &status) { statusbar->SetStatus(status); } }
196 <        
197 <        
198 <        //MainWindow::StatusArea->
199 <        //MainWindow::MainWindow().SetSize(MainWindow::MainWindow().GetRect().GetWidth(), MainWindow::MainWindow().GetRect().GetHeight()+1);
200 <        
201 <        //MainWindow::StatusBar->SetLabel("Importing Files...");
202 <        //StatusBar->SetLabel(s);
203 <        //->SetLabel(s);
204 <        
270 >        TheWindow->StatusArea->SetStatusText(wxs);
271   }
272  
273  
# Line 215 | Line 281 | int AEInstallerApp::OnExit()
281          return wxApp::OnExit();
282          ////@end AEInstallerApp cleanup
283   }
284 < void doglobalizeData() {
285 <        //TheWindow->Disable();
284 > void doglobalizeData()
285 > {
286          globalizeData();
287   #ifdef WIN32
288          while(1) Sleep(-1);
289   #endif
224        //TheWindow->Enable();
225        //setStatusArea((string)"Test1");
290   }

Diff Legend

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