Skip to content

Commit

Permalink
Merge pull request #253 from gdt050579/249-gview-when-opened-and-gvie…
Browse files Browse the repository at this point in the history
…wini-is-not-found-generate-and-also-load-it

Closes #249. Fixed GView not loading config when it doesn't exist
  • Loading branch information
rzaharia authored Mar 8, 2024
2 parents 1089c0c + c10ad12 commit e8e2262
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions GViewCore/src/App/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,26 @@ bool Instance::Init()
initData.Flags =
InitializationFlags::Menu | InitializationFlags::CommandBar | InitializationFlags::LoadSettingsFile | InitializationFlags::AutoHotKeyForWindow;

const auto settingsPath = AppCUI::Application::GetAppSettingsFile();
AppCUI::OS::File settingsFile;
if (!settingsFile.OpenRead(settingsPath)) {
CHECK(GView::App::ResetConfiguration(), false, "");
}
settingsFile.Close();

CHECK(AppCUI::Application::Init(initData), false, "Fail to initialize AppCUI framework !");
// reserve some space fo type
this->typePlugins.reserve(128);
if (!LoadSettings())
{
const auto settingsPath = AppCUI::Application::GetAppSettingsFile();
AppCUI::OS::File oldSettingsFile;
if (!oldSettingsFile.OpenRead(settingsPath))
{
CHECK(GView::App::ResetConfiguration(), false, "");
}
else
{
oldSettingsFile.Close();
auto preservedSettingsNewPath = settingsPath;
preservedSettingsNewPath.replace_extension(".ini.bak");
std::filesystem::rename(settingsPath, preservedSettingsNewPath);
AppCUI::Log::Report(
AppCUI::Log::Severity::Warning, __FILE__, __FUNCTION__, "!LoadSettings()", __LINE__, "found an invalid ini file, will generate a new one");
CHECK(GView::App::ResetConfiguration(), false, "");
}
if (!LoadSettings()) {
auto preservedSettingsNewPath = settingsPath;
preservedSettingsNewPath.replace_extension(".ini.bak");
std::filesystem::rename(settingsPath, preservedSettingsNewPath);
AppCUI::Log::Report(
AppCUI::Log::Severity::Warning, __FILE__, __FUNCTION__, "!LoadSettings()", __LINE__, "found an invalid ini file, will generate a new one");
CHECK(GView::App::ResetConfiguration(), false, "");

AppCUI::Dialogs::MessageBox::ShowError(
"Erorr reading configuration", "Found an invalid configuration, it will be renamed as \".ini.bak\". Will generated a new one! Please restart GView.");
}
CHECK(BuildMainMenus(), false, "Fail to create bundle menus !");
this->defaultPlugin.Init();
Expand Down

0 comments on commit e8e2262

Please sign in to comment.