mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-24 03:56:34 +00:00
BugFix: checked for NULL pointer when removing a Mod
a lot of improvements and rearrangements in the GUI...
This commit is contained in:
+169
-24
@@ -36,11 +36,14 @@ BEGIN_EVENT_TABLE(OTM_Frame, wxFrame)
|
||||
EVT_BUTTON(ID_Button_Open, OTM_Frame::OnButtonOpen)
|
||||
EVT_BUTTON(ID_Button_Path, OTM_Frame::OnButtonPath)
|
||||
EVT_BUTTON(ID_Button_Update, OTM_Frame::OnButtonUpdate)
|
||||
EVT_BUTTON(ID_Button_Save, OTM_Frame::OnButtonSave)
|
||||
|
||||
EVT_MENU(ID_Menu_Pref, OTM_Frame::OnMenuPref)
|
||||
EVT_MENU(ID_Menu_Quit, OTM_Frame::OnMenuQuit)
|
||||
//EVT_MENU(ID_Menu_Pref, OTM_Frame::OnMenuPref)
|
||||
//EVT_MENU(ID_Menu_Quit, OTM_Frame::OnMenuQuit)
|
||||
EVT_MENU(ID_Menu_Help, OTM_Frame::OnMenuHelp)
|
||||
EVT_MENU(ID_Menu_About, OTM_Frame::OnMenuAbout)
|
||||
EVT_MENU(ID_Menu_AddGame, OTM_Frame::OnMenuAddGame)
|
||||
EVT_MENU(ID_Menu_DeleteGame, OTM_Frame::OnMenuDeleteGame)
|
||||
|
||||
EVT_COMMAND (ID_Add_Game, OTM_EVENT_TYPE, OTM_Frame::OnAddGame)
|
||||
EVT_COMMAND (ID_Delete_Game, OTM_EVENT_TYPE, OTM_Frame::OnDeleteGame)
|
||||
@@ -52,7 +55,7 @@ IMPLEMENT_APP(MyApp)
|
||||
bool MyApp::OnInit(void)
|
||||
{
|
||||
|
||||
OTM_Frame *frame = new OTM_Frame( "OpenTexMod", wxDefaultPosition, wxSize(600,400));
|
||||
OTM_Frame *frame = new OTM_Frame( "OpenTexMod V0.9 alpha by ROTA", wxDefaultPosition, wxSize(600,400));
|
||||
SetTopWindow( frame );
|
||||
|
||||
return true;
|
||||
@@ -73,16 +76,21 @@ OTM_Frame::OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& si
|
||||
Server->Run();
|
||||
|
||||
MenuBar = new wxMenuBar;
|
||||
MenuMain = new wxMenu;
|
||||
//MenuMain = new wxMenu;
|
||||
MenuGame = new wxMenu;
|
||||
MenuHelp = new wxMenu;
|
||||
|
||||
MenuMain->Append( ID_Menu_Pref, Language.MenuPref, Language.MenuPref );
|
||||
MenuMain->Append( ID_Menu_Quit, Language.MenuQuit, Language.MenuQuit );
|
||||
//MenuMain->Append( ID_Menu_Pref, Language.MenuPref, Language.MenuPref );
|
||||
//MenuMain->Append( ID_Menu_Quit, Language.MenuQuit, Language.MenuQuit );
|
||||
|
||||
MenuGame->Append( ID_Menu_AddGame, Language.MenuAddGame, Language.MenuAddGame );
|
||||
MenuGame->Append( ID_Menu_DeleteGame, Language.MenuDeleteGame, Language.MenuDeleteGame );
|
||||
|
||||
MenuHelp->Append( ID_Menu_Help, Language.MenuHelp, Language.MenuHelp );
|
||||
MenuHelp->Append( ID_Menu_About, Language.MenuAbout, Language.MenuAbout );
|
||||
|
||||
MenuBar->Append( MenuMain, Language.MainMenuStart );
|
||||
//MenuBar->Append( MenuMain, Language.MainMenuStart );
|
||||
MenuBar->Append( MenuGame, Language.MainMenuGame );
|
||||
MenuBar->Append( MenuHelp, Language.MainMenuHelp );
|
||||
|
||||
SetMenuBar(MenuBar);
|
||||
@@ -98,9 +106,12 @@ OTM_Frame::OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& si
|
||||
OpenButton = new wxButton( this, ID_Button_Open, Language.ButtonOpen, wxDefaultPosition, wxSize(100,24));
|
||||
DirectoryButton = new wxButton( this, ID_Button_Path, Language.ButtonDirectory, wxDefaultPosition, wxSize(100,24));
|
||||
UpdateButton = new wxButton( this, ID_Button_Update, Language.ButtonUpdate, wxDefaultPosition, wxSize(100,24));
|
||||
SaveButton = new wxButton( this, ID_Button_Save, Language.ButtonSave, wxDefaultPosition, wxSize(100,24));
|
||||
|
||||
ButtonSizer->Add( (wxWindow*) OpenButton, 1, wxEXPAND, 0);
|
||||
ButtonSizer->Add( (wxWindow*) DirectoryButton, 1, wxEXPAND, 0);
|
||||
ButtonSizer->Add( (wxWindow*) UpdateButton, 1, wxEXPAND, 0);
|
||||
ButtonSizer->Add( (wxWindow*) SaveButton, 1, wxEXPAND, 0);
|
||||
MainSizer->Add( ButtonSizer, 0, wxEXPAND , 0 );
|
||||
|
||||
|
||||
@@ -108,7 +119,6 @@ OTM_Frame::OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& si
|
||||
|
||||
NumberOfGames = 0;
|
||||
MaxNumberOfGames = 10;
|
||||
Games = new OTM_GameInfo*[MaxNumberOfGames];
|
||||
Clients = new OTM_Client*[MaxNumberOfGames];
|
||||
|
||||
Show( true );
|
||||
@@ -118,7 +128,6 @@ OTM_Frame::OTM_Frame(const wxString& title, const wxPoint& pos, const wxSize& si
|
||||
typedef void (*fkt_typ)(void);
|
||||
fkt_typ InstallHook = (fkt_typ) GetProcAddress( hMod, "InstallHook");
|
||||
InstallHook();
|
||||
|
||||
}
|
||||
|
||||
OTM_Frame::~OTM_Frame(void)
|
||||
@@ -136,6 +145,8 @@ OTM_Frame::~OTM_Frame(void)
|
||||
fkt_typ RemoveHook = (fkt_typ) GetProcAddress( hMod, "RemoveHook");
|
||||
RemoveHook();
|
||||
FreeLibrary(hMod);
|
||||
|
||||
if (Clients!=NULL) delete [] Clients;
|
||||
}
|
||||
|
||||
int OTM_Frame::KillServer(void)
|
||||
@@ -172,16 +183,14 @@ void OTM_Frame::OnAddGame( wxCommandEvent &event)
|
||||
pipe.In = ((OTM_Event&)event).GetPipeIn();
|
||||
pipe.Out = ((OTM_Event&)event).GetPipeOut();
|
||||
|
||||
OTM_GameInfo *game = new OTM_GameInfo( name);
|
||||
OTM_Client *client = new OTM_Client( pipe, this);
|
||||
client->Create();
|
||||
client->Run();
|
||||
|
||||
OTM_GamePage *page = new OTM_GamePage( Notebook, game, client->Pipe, Language);
|
||||
OTM_GamePage *page = new OTM_GamePage( Notebook, name, client->Pipe, Language);
|
||||
|
||||
Notebook->AddPage( page, name, true);
|
||||
|
||||
Games[NumberOfGames] = game;
|
||||
Clients[NumberOfGames] = client;
|
||||
NumberOfGames++;
|
||||
}
|
||||
@@ -193,12 +202,9 @@ void OTM_Frame::OnDeleteGame( wxCommandEvent &event)
|
||||
for (int i=0; i<NumberOfGames; i++) if (Clients[i]==client)
|
||||
{
|
||||
Notebook->DeletePage(i);
|
||||
//Games[i]->Wait();
|
||||
Clients[i]->Delete();
|
||||
delete Clients[i];
|
||||
delete Games[i];
|
||||
NumberOfGames--;
|
||||
for (int j=i; j<NumberOfGames; j++) Games[j] = Games[j+1];
|
||||
for (int j=i; j<NumberOfGames; j++) Clients[j] = Clients[j+1];
|
||||
return;
|
||||
}
|
||||
@@ -209,9 +215,8 @@ void OTM_Frame::OnClose(wxCloseEvent& event)
|
||||
{
|
||||
if (event.CanVeto() && NumberOfGames>0)
|
||||
{
|
||||
event.Veto();
|
||||
wxMessageBox("Very bad idea to close OpenTexMod before closing the hooked Games!", "ERROR", wxOK);
|
||||
return;
|
||||
|
||||
if (wxMessageBox(Language.ExitGameAnyway, "ERROR", wxYES_NO)!=wxYES) {event.Veto(); return;}
|
||||
}
|
||||
event.Skip();
|
||||
Destroy();
|
||||
@@ -223,10 +228,10 @@ void OTM_Frame::OnButtonOpen(wxCommandEvent& WXUNUSED(event))
|
||||
OTM_GamePage *page = (OTM_GamePage*) Notebook->GetCurrentPage();
|
||||
if (page==NULL) return;
|
||||
|
||||
wxString file_name = wxFileSelector( Language.ChooseFile, TexturePath, "", "*.*", "textures (*.dds)|*.dds|zip (*.zip)|*.zip|tpf (*.tpf)|*.tpf", wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);
|
||||
wxString file_name = wxFileSelector( Language.ChooseFile, page->GetOpenPath(), "", "*.*", "textures (*.dds)|*.dds|zip (*.zip)|*.zip|tpf (*.tpf)|*.tpf", wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);
|
||||
if ( !file_name.empty() )
|
||||
{
|
||||
TexturePath = file_name.BeforeLast( '/');
|
||||
page->SetOpenPath(file_name.BeforeLast( '/'));
|
||||
page->AddTexture( file_name);
|
||||
}
|
||||
}
|
||||
@@ -237,10 +242,10 @@ void OTM_Frame::OnButtonPath(wxCommandEvent& WXUNUSED(event))
|
||||
OTM_GamePage *page = (OTM_GamePage*) Notebook->GetCurrentPage();
|
||||
if (page==NULL) return;
|
||||
|
||||
wxString dir = wxDirSelector(Language.ChooseDir);
|
||||
wxString dir = wxDirSelector( Language.ChooseDir, page->GetSavePath());
|
||||
if ( !dir.empty() )
|
||||
{
|
||||
page->SetPath( dir);
|
||||
page->SetSavePath( dir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,11 +257,151 @@ void OTM_Frame::OnButtonUpdate(wxCommandEvent& WXUNUSED(event))
|
||||
page->UpdateGame();
|
||||
}
|
||||
|
||||
void OTM_Frame::OnButtonSave(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
if (Notebook->GetPageCount()==0) return;
|
||||
OTM_GamePage *page = (OTM_GamePage*) Notebook->GetCurrentPage();
|
||||
if (page==NULL) return;
|
||||
page->SaveToFile();
|
||||
}
|
||||
|
||||
/*
|
||||
void OTM_Frame::OnMenuPref(wxCommandEvent& WXUNUSED(event)) {}
|
||||
void OTM_Frame::OnMenuQuit(wxCommandEvent& WXUNUSED(event)) {Destroy();}
|
||||
void OTM_Frame::OnMenuHelp(wxCommandEvent& WXUNUSED(event)) {}
|
||||
*/
|
||||
|
||||
void OTM_Frame::OnMenuHelp(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxFile dat;
|
||||
if (!dat.Access( "README.txt", wxFile::read)) return;
|
||||
dat.Open("README.txt", wxFile::read);
|
||||
if (!dat.IsOpened()) {return;}
|
||||
unsigned len = dat.Length();
|
||||
|
||||
char* buffer;
|
||||
try {buffer = new char [len+1];}
|
||||
catch (...) {return ;}
|
||||
|
||||
unsigned int result = dat.Read( buffer, len);
|
||||
dat.Close();
|
||||
if (len!=result) {delete [] buffer; return;}
|
||||
|
||||
buffer[len] = 0;
|
||||
|
||||
wxString msg = buffer;
|
||||
wxMessageBox(msg, "help", wxOK);
|
||||
}
|
||||
|
||||
void OTM_Frame::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxMessageBox("OpenTexMod V0.0 by ROTA", "Info", wxOK);
|
||||
wxMessageBox(L"OpenTexMod V0.9 alpha by ROTA\nhttp://code.google.com/p/texmod/", "Info", wxOK);
|
||||
};
|
||||
|
||||
void OTM_Frame::OnMenuAddGame(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxString file_name = wxFileSelector( Language.ChooseFile, "", "", "exe", "binary (*.exe)|*.exe", wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);
|
||||
if ( !file_name.empty() )
|
||||
{
|
||||
file_name = file_name.AfterLast('\\');
|
||||
|
||||
wxArrayString array;
|
||||
GetHookedGames( array);
|
||||
int num = array.GetCount();
|
||||
for (int i=0; i<num; i++) if (array[i] == file_name)
|
||||
{
|
||||
wxMessageBox(Language.GameAlreadyAdded, "ERROR", wxOK);
|
||||
return;
|
||||
}
|
||||
array.Add(file_name);
|
||||
SetHookedGames( array);
|
||||
}
|
||||
}
|
||||
|
||||
void OTM_Frame::OnMenuDeleteGame(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxArrayInt selections;
|
||||
wxArrayString array;
|
||||
GetHookedGames(array);
|
||||
wxGetSelectedChoices( selections, Language.DeleteGame, Language.DeleteGame, array);
|
||||
|
||||
int num = selections.GetCount();
|
||||
for (int i=0; i<num; i++)
|
||||
{
|
||||
array.RemoveAt( selections[i]-i); //this will work only if selections is sorted !!
|
||||
}
|
||||
|
||||
SetHookedGames(array);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int OTM_Frame::GetHookedGames( wxArrayString &array)
|
||||
{
|
||||
wxFile file;
|
||||
wxString name;
|
||||
wchar_t *app_path = _wgetenv( L"APPDATA");
|
||||
name.Printf("%ls\\%ls\\%ls", app_path, OTM_APP_DIR, OTM_APP_DX9);
|
||||
|
||||
if (!file.Access(name, wxFile::read)) return -1;
|
||||
file.Open(name, wxFile::read);
|
||||
if (!file.IsOpened()) {return -1;}
|
||||
|
||||
unsigned len = file.Length();
|
||||
|
||||
unsigned char* buffer;
|
||||
try {buffer = new unsigned char [len+1];}
|
||||
catch (...) {return -1;}
|
||||
|
||||
unsigned int result = file.Read( buffer, len);
|
||||
file.Close();
|
||||
|
||||
if (result != len) return -1;
|
||||
|
||||
buffer[len]=0;
|
||||
|
||||
wxString content;
|
||||
content = buffer;
|
||||
delete [] buffer;
|
||||
|
||||
wxStringTokenizer token( content, "\n");
|
||||
|
||||
int num = token.CountTokens();
|
||||
|
||||
array.Empty();
|
||||
|
||||
for (int i=0; i<num; i++)
|
||||
{
|
||||
array.Add( token.GetNextToken());
|
||||
}
|
||||
|
||||
file.Close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int OTM_Frame::SetHookedGames( const wxArrayString &array)
|
||||
{
|
||||
wxFile file;
|
||||
wxString name;
|
||||
wchar_t *app_path = _wgetenv( L"APPDATA");
|
||||
name.Printf("%ls\\%ls", app_path, OTM_APP_DIR);
|
||||
|
||||
if (! wxDir::Exists(name))
|
||||
{
|
||||
wxDir::Make(name);
|
||||
}
|
||||
|
||||
name.Printf("%ls\\%ls\\%ls", app_path, OTM_APP_DIR, OTM_APP_DX9);
|
||||
file.Open(name, wxFile::write);
|
||||
if (!file.IsOpened()) {return -1;}
|
||||
wxString content;
|
||||
|
||||
int num = array.GetCount();
|
||||
for (int i=0; i<num; i++)
|
||||
{
|
||||
content = array[i];
|
||||
content << "\n";
|
||||
file.Write( content.char_str(), content.Len());
|
||||
}
|
||||
file.Close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user