From 69a3a25345527072f2f3ca0199eb24857791c0b4 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 3 Feb 2010 11:03:51 +0100 Subject: [PATCH] Store job files in the application data folder. Also moved mmg's config file from ~/.mkvmergeGUI to ~/.mkvtoolnix/config on non-Windows systems. Fix for bug 466. --- ChangeLog | 13 ++++++++++++ src/common/fs_sys_helpers.cpp | 21 +++++++++++++++++++ src/common/fs_sys_helpers.h | 1 + src/mmg/jobs.cpp | 6 +++--- src/mmg/mmg.cpp | 38 +++++++++++++++++++++++++++++++++++ src/mmg/mmg.h | 3 +++ src/mmg/mmg_dialog.cpp | 3 +-- 7 files changed, 80 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 34608457b..d4954d636 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-02-03 Moritz Bunkus + + * mmg: bug fix: The jobs will be saved in the 'mkvtoolnix/jobs' + sub-directory of the 'application data' folder instead of the + 'jobs' folder in the current directory. On Windows this is the + special 'application data' folder inside the user's profile + directory, e.g. 'C:\Users\mbunkus\AppData\mkvtoolnix'. On + non-Windows systems this is the folder '.mkvtoolnix' in the user's + home directory. + mmg's configuration file has also been moved from ~/.mkvmergeGUI + to ~/.mkvtoolnix/config on non-Windows systems. + Fix for bug 466. + 2010-01-28 Moritz Bunkus * mkvextract: bug fix: Files are only opened for reading, not for diff --git a/src/common/fs_sys_helpers.cpp b/src/common/fs_sys_helpers.cpp index 2c00486e8..ad07611cc 100644 --- a/src/common/fs_sys_helpers.cpp +++ b/src/common/fs_sys_helpers.cpp @@ -166,6 +166,18 @@ get_windows_version() { return (os_version_info.dwMajorVersion << 16) | os_version_info.dwMinorVersion; } +std::string +get_application_data_folder() { + wchar_t szPath[MAX_PATH]; + + if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, szPath))) { + PathAppend(szPath, TEXT("mkvtoolnix")); + return to_utf8(std::wstring(szPath)); + } + + return ""; +} + #else // SYS_WINDOWS # include @@ -198,6 +210,15 @@ get_current_time_millis() { return (int64_t)tv.tv_sec * 1000 + (int64_t)tv.tv_usec / 1000; } +std::string +get_application_data_folder() { + const char *home = getenv("HOME"); + if (NULL == home) + return ""; + + return std::string(home) + "/.mkvtoolnix"; +} + #endif // SYS_WINDOWS // ----------------------------------------------------------------- diff --git a/src/common/fs_sys_helpers.h b/src/common/fs_sys_helpers.h index 41430f5a5..3a2c3155d 100644 --- a/src/common/fs_sys_helpers.h +++ b/src/common/fs_sys_helpers.h @@ -20,6 +20,7 @@ int MTX_DLL_API fs_entry_exists(const char *path); void MTX_DLL_API create_directory(const char *path); int64_t MTX_DLL_API get_current_time_millis(); +std::string MTX_DLL_API get_application_data_folder(); #if defined(SYS_WINDOWS) diff --git a/src/mmg/jobs.cpp b/src/mmg/jobs.cpp index a1d89aec5..c199d6e65 100644 --- a/src/mmg/jobs.cpp +++ b/src/mmg/jobs.cpp @@ -144,7 +144,7 @@ job_run_dialog::start_next_job() { st_jobs->SetLabel(wxString::Format(Z("Processing job %d/%d"), current_job + 1, (int)jobs_to_start.size())); st_current->SetLabel(wxString::Format(Z("Current job ID %d:"), jobs[ndx].id)); - mdlg->load(wxString::Format(wxT("%s/jobs/%d.mmg"), wxGetCwd().c_str(), jobs[ndx].id)); + mdlg->load(wxString::Format(wxT("%s/%d.mmg"), app->get_jobs_folder().c_str(), jobs[ndx].id)); opt_file_name.Printf(wxT("%smmg-mkvmerge-options-%d-%d"), get_temp_dir().c_str(), (int)wxGetProcessId(), (int)wxGetUTCTime()); @@ -542,7 +542,7 @@ job_dialog::on_delete(wxCommandEvent &evt) { int k = 0; while (jobs.size() > i) { if (selected[k]) { - wxRemoveFile(wxString::Format(wxT("jobs/%d.mmg"), jobs[i].id)); + wxRemoveFile(wxString::Format(wxT("%s/%d.mmg"), app->get_jobs_folder().c_str(), jobs[i].id)); jobs.erase(jobs.begin() + i); lv_jobs->DeleteItem(i); } else @@ -698,7 +698,7 @@ job_dialog::on_item_selected(wxListEvent &evt) { void job_dialog::start_jobs(std::vector &jobs_to_start) { - wxString temp_settings = wxGetCwd() + wxT("/jobs/temp.mmg"); + wxString temp_settings = app->get_jobs_folder() + wxT("/temp.mmg"); mdlg->save(temp_settings, true); mdlg->Show(false); diff --git a/src/mmg/mmg.cpp b/src/mmg/mmg.cpp index eff473837..3c5e6efa7 100644 --- a/src/mmg/mmg.cpp +++ b/src/mmg/mmg.cpp @@ -21,6 +21,7 @@ #include "common/common.h" #include "common/extern_data.h" #include "common/extern_data.h" +#include "common/fs_sys_helpers.h" #include "common/mm_io.h" #include "common/strings/formatting.h" #include "common/translation.h" @@ -89,6 +90,37 @@ mmg_app::init_ui_locale() { init_locales(locale); } +wxString +mmg_app::get_config_file_name() { + return wxU(get_application_data_folder()) + wxT("/config"); +} + +wxString +mmg_app::get_jobs_folder() { + return wxU(get_application_data_folder()) + wxT("/jobs"); +} + +void +mmg_app::prepare_mmg_data_folder() { + // The 'jobs' folder is part of the application data + // folder. Therefore both directories will be creatd. + // 'prepare_path' treats the last part of the path as a file name; + // therefore append a dummy file name so that all directory parts + // will be created. + mm_file_io_c::prepare_path(wxMB(get_jobs_folder() + wxT("/dummy"))); + +#if !defined(SYS_WINDOWS) + // Migrate the config file from its old location ~/.mkvmergeGUI to + // the new location ~/.mkvtoolnix/config + wxString old_config_name; + wxGetEnv(wxT("HOME"), &old_config_name); + old_config_name += wxT("/.mkvmergeGUI"); + + if (wxFileExists(old_config_name)) + wxRenameFile(old_config_name, get_config_file_name()); +#endif +} + bool mmg_app::OnInit() { mtx_common_init(); @@ -98,7 +130,13 @@ mmg_app::OnInit() { wxString k, v; int index; + prepare_mmg_data_folder(); + +#if defined(SYS_WINDOWS) cfg = new wxConfig(wxT("mkvmergeGUI")); +#else + cfg = new wxFileConfig(wxT("mkvmergeGUI"), wxEmptyString, get_config_file_name()); +#endif wxConfigBase::Set(cfg); init_ui_locale(); diff --git a/src/mmg/mmg.h b/src/mmg/mmg.h index 5fae9cbaf..6ece578e0 100644 --- a/src/mmg/mmg.h +++ b/src/mmg/mmg.h @@ -276,6 +276,9 @@ public: virtual int OnExit(); virtual void init_ui_locale(); virtual void handle_command_line_arguments(); + virtual wxString get_config_file_name(); + virtual wxString get_jobs_folder(); + virtual void prepare_mmg_data_folder(); }; extern mmg_app *app; diff --git a/src/mmg/mmg_dialog.cpp b/src/mmg/mmg_dialog.cpp index 74f118833..228fcf067 100644 --- a/src/mmg/mmg_dialog.cpp +++ b/src/mmg/mmg_dialog.cpp @@ -1386,8 +1386,7 @@ mmg_dialog::on_add_to_jobqueue(wxCommandEvent &evt) { job.log = new wxString(); jobs.push_back(job); - description.Printf(wxT("/jobs/%d.mmg"), job.id); - save(wxGetCwd() + description); + save(wxString::Format(wxT("%s/%d.mmg"), app->get_jobs_folder().c_str(), job.id)); save_job_queue();