| 1 |
/* |
| 2 |
Copyright (C) 2009-2011 wxLauncher Team |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License |
| 6 |
as published by the Free Software Foundation; either version 2 |
| 7 |
of the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef FLAGLISTMANAGER_H |
| 20 |
#define FLAGLISTMANAGER_H |
| 21 |
|
| 22 |
#include <wx/wx.h> |
| 23 |
#include <wx/filename.h> |
| 24 |
#include <wx/process.h> |
| 25 |
|
| 26 |
#include "datastructures/FlagFileData.h" |
| 27 |
#include "apis/EventHandlers.h" |
| 28 |
|
| 29 |
/** Flag file processing status has changed. |
| 30 |
The event's int value indicates the FlagFileProcessingStatus. */ |
| 31 |
LAUNCHER_DECLARE_EVENT_TYPE(EVT_FLAG_FILE_PROCESSING_STATUS_CHANGED); |
| 32 |
|
| 33 |
WX_DECLARE_OBJARRAY(wxFileName, FlagFileArray); |
| 34 |
|
| 35 |
class FlagListManager: public wxEvtHandler { |
| 36 |
public: |
| 37 |
static bool Initialize(); |
| 38 |
static void DeInitialize(); |
| 39 |
static bool IsInitialized(); |
| 40 |
static FlagListManager* GetFlagListManager(); |
| 41 |
|
| 42 |
~FlagListManager(); |
| 43 |
|
| 44 |
/** FlagFileProcessingStatus is a high-level description of the status of flag file processing. */ |
| 45 |
enum FlagFileProcessingStatus { |
| 46 |
FLAG_FILE_PROCESSING_OK = 0, |
| 47 |
FLAG_FILE_PROCESSING_WAITING, |
| 48 |
FLAG_FILE_PROCESSING_RESET, |
| 49 |
FLAG_FILE_PROCESSING_ERROR |
| 50 |
}; |
| 51 |
|
| 52 |
enum CapabilityFlags { |
| 53 |
BUILD_CAPS_OPENAL = 1 << 0, |
| 54 |
BUILD_CAPS_NO_D3D = 1 << 1, |
| 55 |
BUILD_CAPS_NEW_SND = 1 << 2, |
| 56 |
BUILD_CAPS_SDL = 1 << 3, |
| 57 |
}; |
| 58 |
|
| 59 |
void OnBinaryChanged(wxCommandEvent &event); |
| 60 |
|
| 61 |
static void RegisterFlagFileProcessingStatusChanged(wxEvtHandler *handler); |
| 62 |
static void UnRegisterFlagFileProcessingStatusChanged(wxEvtHandler *handler); |
| 63 |
|
| 64 |
void BeginFlagFileProcessing(); |
| 65 |
|
| 66 |
/** Returns true when the flag file processing has succeeded, false otherwise. */ |
| 67 |
inline bool IsProcessingOK() const { return (this->processingStatus == PROCESSING_OK); } |
| 68 |
|
| 69 |
/** Returns the message to display when processing has not (yet) succeded. |
| 70 |
This function should not called when processing has succeeded. */ |
| 71 |
wxString GetStatusMessage() const; |
| 72 |
|
| 73 |
/** Returns the extracted data from the flag file. |
| 74 |
Should only be called when processing succeeds and only once per flag file processed. */ |
| 75 |
FlagFileData* GetFlagFileData(); |
| 76 |
|
| 77 |
/** Returns the extracted data in a form suitable for use by the profile proxy. |
| 78 |
Should only be called when processing succeeds and only once per flag file processed. */ |
| 79 |
ProxyFlagData* GetProxyFlagData(); |
| 80 |
|
| 81 |
/** Gets the build capabilities of the currently selected FSO executable. |
| 82 |
Should only be called when processing succeeds. */ |
| 83 |
wxByte GetBuildCaps() const; |
| 84 |
|
| 85 |
private: |
| 86 |
FlagListManager(); |
| 87 |
void DeleteExistingData(); |
| 88 |
|
| 89 |
static FlagListManager* flagListManager; |
| 90 |
|
| 91 |
static EventHandlers ffProcessingStatusChangedHandlers; |
| 92 |
|
| 93 |
static void GenerateFlagFileProcessingStatusChanged(const FlagFileProcessingStatus& status); |
| 94 |
|
| 95 |
/** ProcessingStatus is a low-level description of the status of flag file processing. */ |
| 96 |
enum ProcessingStatus { |
| 97 |
PROCESSING_OK = 0, |
| 98 |
INITIAL_STATUS, |
| 99 |
MISSING_TC, |
| 100 |
NONEXISTENT_TC, |
| 101 |
INVALID_TC, |
| 102 |
MISSING_EXE, |
| 103 |
INVALID_BINARY, |
| 104 |
WAITING_FOR_FLAG_FILE, |
| 105 |
FLAG_FILE_NOT_GENERATED, |
| 106 |
FLAG_FILE_NOT_VALID, |
| 107 |
FLAG_FILE_NOT_SUPPORTED, |
| 108 |
CANNOT_CREATE_FLAGFILE_FOLDER, |
| 109 |
CANNOT_CHANGE_WORKING_FOLDER, |
| 110 |
MAX_PROCESSINGSTATUS |
| 111 |
}; |
| 112 |
ProcessingStatus processingStatus; //!< has processing succeeded |
| 113 |
ProcessingStatus ParseFlagFile(const wxFileName& flagfile); |
| 114 |
|
| 115 |
void SetProcessingStatus(const ProcessingStatus& processingStatus); |
| 116 |
inline const ProcessingStatus& GetProcessingStatus() const { return this->processingStatus; } |
| 117 |
FlagFileProcessingStatus GetFlagFileProcessingStatus() const; |
| 118 |
|
| 119 |
FlagFileData* data; |
| 120 |
ProxyFlagData* proxyData; |
| 121 |
|
| 122 |
wxByte buildCaps; |
| 123 |
|
| 124 |
class FlagProcess: public wxProcess { |
| 125 |
public: |
| 126 |
FlagProcess(FlagFileArray flagFileLocations); |
| 127 |
virtual void OnTerminate(int pid, int status); |
| 128 |
private: |
| 129 |
FlagFileArray flagFileLocations; |
| 130 |
}; |
| 131 |
|
| 132 |
DECLARE_EVENT_TABLE() |
| 133 |
}; |
| 134 |
#endif |