Skip to content

Commit

Permalink
added user dir for wide.ini file
Browse files Browse the repository at this point in the history
Added USER DIR for wide.ini file
  • Loading branch information
silverslade committed Aug 2, 2014
1 parent 5e2efda commit fef0da3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Expand Up @@ -6,4 +6,11 @@ src/.codelite/wide.tags
src/.codelite/wide.workspace.user
src/.codelite/sftp-workspace-settings.conf
src/.codelite/wide.session
src/.codelite/wide.workspace.neo
src/.codelite/wide.workspace.neo
/src/.kdev4/src.kdev4
/src/edit.o
/src/main.o
/src/prefs.o
/src/src.kdev4
/src/wide
/src/.kdev_include_paths
52 changes: 39 additions & 13 deletions src/main.cpp
Expand Up @@ -19,6 +19,7 @@
#include "wx/fileconf.h"
#include "wx/generic/numdlgg.h"
// #include "wx/filefn.h"
#include "wx/stdpaths.h"

#include "images/fileopen.xpm"
#include "images/filesave.xpm"
Expand Down Expand Up @@ -50,6 +51,7 @@
#include "myframe.h"

wxFileConfig *pConfig;
wxString inipath;

// #define wxDEBUG_LEVEL 0
//#define NDEBUG
Expand All @@ -64,27 +66,51 @@
bool OnInit()
{

// Load config file
pConfig = new wxFileConfig(
_T(NOMEAPPLICAZIONE),
_T(NOMEAPPLICAZIONE),
_T(CONFIG_FILE),
_T(""),
wxCONFIG_USE_RELATIVE_PATH,
wxConvISO8859_1);
// 1) try to load wide.ini config file within the same wide wxSetWorkingDirectory
// 2) if wide.ini exists -> will be loaded
// 3) is not exists, try to load USERDIR/wide.ini file
// 4) if not exists neither USERDIR/wide.ini and wide.ini file, the config file will be saved to USERDIR path

if (!wxFile::Exists(_T(CONFIG_FILE)))
{
inipath = wxStandardPaths::Get().GetUserLocalDataDir() + wxFileName::GetPathSeparator() + _T(CONFIG_FILE);

wxFileName userdir = wxFileName::DirName( wxStandardPaths::Get().GetUserLocalDataDir());
if (!wxDirExists(wxStandardPaths::Get().GetUserLocalDataDir())){
userdir.Mkdir(0777);
wxMessageBox ("Warning, no local/userdir wide.ini file found: a new file will be created in the user dir", "Wide configuration file PATH", wxOK | wxICON_ERROR);
}

}
else{
inipath = _T(CONFIG_FILE);
}

// Load config file
pConfig = new wxFileConfig(
_T(NOMEAPPLICAZIONE),
_T(NOMEAPPLICAZIONE),
inipath,
_T(""),
wxCONFIG_USE_RELATIVE_PATH,
wxConvISO8859_1);


wxConfigBase::Set(pConfig);
pConfig->SetPath(_T("/"));

// Window position and dimension
int width = pConfig->Read(_T("WINDOW_WIDTH"), 1l);
int height = pConfig->Read(_T("WINDOW_HEIGHT"), 1l);;
wxPoint point = wxPoint(pConfig->Read(_T("WINDOW_LOCATION_X"), 1l),
pConfig->Read(_T("WINDOW_LOCATION_Y"), 1l));
int width = pConfig->Read(_T("WINDOW_WIDTH"), 800l);
int height = pConfig->Read(_T("WINDOW_HEIGHT"), 600l);;
wxPoint point = wxPoint(pConfig->Read(_T("WINDOW_LOCATION_X"), 1l), pConfig->Read(_T("WINDOW_LOCATION_Y"), 1l));

wxFrame* frame = new MyFrame(NULL,point,width,height);
MyFrame* frame = new MyFrame(NULL,point,width,height);
SetTopWindow(frame);
frame->Show();


(frame)->OnOutput(_T("Wide Configuration file saved with path ") +inipath);

return true;
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/myframe.h
Expand Up @@ -148,6 +148,7 @@ class MyFrame : public wxFrame {

public:
void RefreshTree();
void OnOutput(wxString string);

// Funzioni
private:
Expand Down Expand Up @@ -226,7 +227,7 @@ class MyFrame : public wxFrame {

// Metodi della console
void OnConsoleClicked(wxStyledTextEvent &event);
void OnOutput(wxString string);

void OnClear();

// HELP MENU
Expand Down

0 comments on commit fef0da3

Please sign in to comment.