Skip to content

Commit

Permalink
Global function GetAppPaths()
Browse files Browse the repository at this point in the history
Introduce a global function "GetAppPaths" to get the IAppPaths interface
from eApp. This eliminates the need to do ugly dynamic_cast<> calls to
get at this information.

Also, moved function to create a temporary file over to the IAppPaths
interface and out of eDocumentPath.
  • Loading branch information
adamv committed Oct 15, 2009
1 parent 1526575 commit 1b1a243
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/BundleManager.cpp
Expand Up @@ -412,7 +412,7 @@ void BundleManager::OnDeleteButton(wxCommandEvent& WXUNUSED(event)) {

if (m_currentBundleInfo->id == -1) {
// We have just installed it, so just delete dir
const wxString installPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppDataPath() + wxT("InstalledBundles") + wxFILE_SEP_PATH + m_currentBundle->m_name;
const wxString installPath = GetAppPaths().AppDataPath() + wxT("InstalledBundles") + wxFILE_SEP_PATH + m_currentBundle->m_name;
DelTree(installPath);

m_installedBundles.erase(p);
Expand Down Expand Up @@ -479,7 +479,7 @@ bool BundleManager::InstallBundle() {
path.SetTimes(NULL, &m_currentBundle->m_modDate, NULL);

// Delete installed version (if any)
wxString installPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppDataPath() + wxT("InstalledBundles") + wxFILE_SEP_PATH;
wxString installPath = GetAppPaths().AppDataPath() + wxT("InstalledBundles") + wxFILE_SEP_PATH;
if (!wxDirExists(installPath)) wxMkdir(installPath);
installPath += m_currentBundle->m_name;
if (wxDirExists(installPath)) DelTree(installPath);
Expand Down
2 changes: 1 addition & 1 deletion src/CygwinDlg.cpp
Expand Up @@ -67,7 +67,7 @@ CygwinDlg::CygwinDlg(wxWindow *parent, cxCygwinDlgMode mode):
}

void CygwinDlg::OnButtonOk(wxCommandEvent& WXUNUSED(event)) {
const wxString appPath = wxGetApp().GetAppPath();
const wxString appPath = wxGetApp().AppPath();
const cxCygwinInstallMode install_mode = m_autoRadio->GetValue() ? cxCYGWIN_AUTO : cxCYGWIN_MANUAL;
new CygwinInstallThread(install_mode, appPath);

Expand Down
4 changes: 2 additions & 2 deletions src/EditorCtrl.cpp
Expand Up @@ -2880,7 +2880,7 @@ bool EditorCtrl::SetDocument(const doc_id& di, const wxString& path, const Remot
// If the path points to a remote file, we have to save it to a temp bufferfile first.
if (eDocumentPath::IsRemotePath(path)) {
m_remoteProfile = rp ? rp : m_parentFrame.GetRemoteProfile(path, false);
m_path = eDocumentPath::GetAppDataTempPath();
m_path = GetAppPaths().CreateTempAppDataFile();
m_remotePath = path;

cxLOCKDOC_WRITE(m_doc)
Expand Down Expand Up @@ -6980,7 +6980,7 @@ void EditorCtrl::SetEnv(cxEnv& env, bool isUnix, const tmBundle* bundle) {
env.SetEnv(eGetSettings().env);

// Add app keys
env.AddSystemVars(isUnix, dynamic_cast<IAppPaths*>(wxTheApp)->GetAppPath());
env.AddSystemVars(isUnix, GetAppPaths().AppPath());

// Add document/editor keys

Expand Down
2 changes: 1 addition & 1 deletion src/EditorFrame.cpp
Expand Up @@ -1838,7 +1838,7 @@ wxString EditorFrame::DownloadFile(const wxString& url, const RemoteProfile* rp)
wxASSERT(rp && rp->IsValid());

// Create temp buffer file
const wxString buffPath = eDocumentPath::GetAppDataTempPath();
const wxString buffPath = GetAppPaths().CreateTempAppDataFile();

// Download file
while(1) {
Expand Down
2 changes: 1 addition & 1 deletion src/ExecuteWin.cpp
Expand Up @@ -47,7 +47,7 @@ int cxExecute::Execute(const wxString& command, const vector<char>& input) {
wxFile logFile;
if (m_debugLog) {
// Create temp file with command
wxFileName logfilePath = wxGetApp().GetAppDataPath();
wxFileName logfilePath = wxGetApp().AppDataPath();
logfilePath.SetFullName(wxT("tmcmd.log"));
logFile.Open(logfilePath.GetFullPath(), wxFile::write);
if (logFile.IsOpened()) {
Expand Down
7 changes: 5 additions & 2 deletions src/IAppPaths.h
Expand Up @@ -3,8 +3,11 @@

class IAppPaths {
public:
virtual const wxString& GetAppPath() const = 0;
virtual const wxString& GetAppDataPath() const = 0;
virtual const wxString& AppPath() const = 0;
virtual const wxString& AppDataPath() const = 0;
virtual wxString CreateTempAppDataFile() = 0;
};

IAppPaths& GetAppPaths(void);

#endif // __IAPPPATHS_H__
2 changes: 1 addition & 1 deletion src/PreviewDlg.cpp
Expand Up @@ -134,7 +134,7 @@ PreviewDlg::PreviewDlg(EditorFrame& parent)

// Do we have XULRunner installed?
bool xulrunner = false;
const wxString xulrunner_path = wxGetApp().GetAppPath() + wxFILE_SEP_PATH + wxT("xr");
const wxString xulrunner_path = wxGetApp().AppPath() + wxFILE_SEP_PATH + wxT("xr");
if (wxDirExists(xulrunner_path)) {
xulrunner = wxWebControl::IsInitialized() || wxWebControl::InitEngine(xulrunner_path);
m_webcontrol = new wxWebControl(this, ID_WEBCONNECT);
Expand Down
6 changes: 3 additions & 3 deletions src/ShellRunner.cpp
Expand Up @@ -26,7 +26,7 @@ long ShellRunner::RawShell(const vector<char>& command, const vector<char>& inpu
#endif

// Create temp file with command
wxFileName tmpfilePath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppDataPath();
wxFileName tmpfilePath = GetAppPaths().AppDataPath();
tmpfilePath.SetFullName(isUnix ? wxT("tmcmd") : wxT("tmcmd.bat"));
wxFile tmpfile(tmpfilePath.GetFullPath(), wxFile::write);
if (!tmpfile.IsOpened()) return -1;
Expand Down Expand Up @@ -69,7 +69,7 @@ long ShellRunner::RawShell(const vector<char>& command, const vector<char>& inpu
s_bashCmd = wxT("bash \"") + tmpfilePath.GetFullPath() + wxT("\"");
#endif

wxFileName initPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppPath();
wxFileName initPath = GetAppPaths().AppPath();
initPath.AppendDir(wxT("Support"));
initPath.AppendDir(wxT("lib"));
initPath.SetFullName(wxT("bash_init.sh"));
Expand Down Expand Up @@ -114,7 +114,7 @@ wxString ShellRunner::GetBashCommand(const wxString& cmd, cxEnv& env) {
#endif

if (s_bashEnv.empty()) {
wxFileName initPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppPath();
wxFileName initPath = GetAppPaths().AppPath();
initPath.AppendDir(wxT("Support"));
initPath.AppendDir(wxT("lib"));
initPath.SetFullName(wxT("bash_init.sh"));
Expand Down
17 changes: 16 additions & 1 deletion src/eApp.cpp
Expand Up @@ -178,7 +178,7 @@ bool eApp::OnInit() {

// Parse syntax files
wxLogDebug(wxT("Loading bundles"));
m_pListHandler = new PListHandler(GetAppPath(), GetAppDataPath(), clearBundleCache);
m_pListHandler = new PListHandler(m_appPath, m_appDataPath, clearBundleCache);
m_pSyntaxHandler = new TmSyntaxHandler(m_pCatalyst->GetDispatcher(), *m_pListHandler);

// Create the main windows
Expand Down Expand Up @@ -713,6 +713,16 @@ wxString eApp::GetAppTitle() {
return title;
}

const wxString& eApp::AppPath() const {return m_appPath;}
const wxString& eApp::AppDataPath() const {return m_appDataPath;}


wxString eApp::CreateTempAppDataFile() {
const wxString tempPath = m_appPath + wxT("temp") + wxFILE_SEP_PATH;
if (!wxDirExists(tempPath)) wxMkdir(tempPath);
return wxFileName::CreateTempFileName(tempPath);
}

void eApp::OnUpdatesAvailable(wxCommandEvent& WXUNUSED(event)) {
// Ask user if he wants to download new release
const int answer = wxMessageBox(_("A new release of e is available.\nDo you wish to go the the website to download it now?"), wxT("Program update!"), wxYES_NO|wxICON_EXCLAMATION, GetTopFrame());
Expand Down Expand Up @@ -752,3 +762,8 @@ void eApp::OnAssertFailure(const wxChar *file, int line, const wxChar *cond, con
eSettings& eGetSettings(void) {
return wxGetApp().GetSettings();
}

// Global function to get eApp's App Path data.
IAppPaths& GetAppPaths(void) {
return wxGetApp();
}
5 changes: 3 additions & 2 deletions src/eApp.h
Expand Up @@ -62,8 +62,9 @@ class eApp : public wxApp,
virtual bool ExecuteCmd(const wxString& cmd);
virtual bool ExecuteCmd(const wxString& cmd, wxString& result);

virtual const wxString& GetAppPath() const {return m_appPath;};
virtual const wxString& GetAppDataPath() const {return m_appDataPath;};
virtual const wxString& AppPath() const;
virtual const wxString& AppDataPath() const;
virtual wxString CreateTempAppDataFile();

// Settings functions
const wxLongLong& GetId() const {cxLOCK_READ((*m_catalyst)) return catalyst.GetId(); cxENDLOCK};
Expand Down
9 changes: 1 addition & 8 deletions src/eDocumentPath.cpp
Expand Up @@ -324,7 +324,7 @@ bool eDocumentPath::InitCygwin(const bool silent) {
}

// Get last cygwin update, and see if we need to reinstall
const wxString supportPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppPath() + wxT("support\\bin\\cygwin-post-install.sh");
const wxString supportPath = GetAppPaths().AppPath() + wxT("support\\bin\\cygwin-post-install.sh");
const wxFileName supportFile(supportPath);

wxDateTime stampTime = get_last_cygwin_update();
Expand Down Expand Up @@ -369,10 +369,3 @@ bool eDocumentPath::IsRemotePath(const wxString& path) {
bool eDocumentPath::IsBundlePath(const wxString& path) {
return (path.StartsWith(wxT("bundle://")));
}

wxString eDocumentPath::GetAppDataTempPath() {
// Create temp buffer file
const wxString tempPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppDataPath() + wxT("temp") + wxFILE_SEP_PATH;
if (!wxDirExists(tempPath)) wxMkdir(tempPath);
return wxFileName::CreateTempFileName(tempPath);
}
2 changes: 0 additions & 2 deletions src/eDocumentPath.h
Expand Up @@ -31,8 +31,6 @@ class eDocumentPath

static bool IsDotDirectory(const wxString& path);

static wxString GetAppDataTempPath();

static bool MakeWritable(const wxString& path);
static FILE_PERMISSIONS GetPermissions(const wxString& path);
static bool SetPermissions(const wxString& path, FILE_PERMISSIONS permissions);
Expand Down

0 comments on commit 1b1a243

Please sign in to comment.