Skip to content

Commit

Permalink
File chooser path fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Jun 29, 2024
1 parent b716a61 commit a775f54
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion source/g_wolf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ bool wolf_game_interface_c::Start(const char *ext)

chooser.title(_("Select output directory"));

chooser.directory(BestDirectory().c_str());
chooser.directory(SanitizePath(BestDirectory()).c_str());

chooser.type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);

Expand Down
13 changes: 13 additions & 0 deletions source/lib_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,19 @@ std::string PathAppend(std::string_view parent, std::string_view child)
return new_path;
}

std::string SanitizePath(std::string_view path)
{
std::string sani_path;
for (const char ch : path)
{
if (ch == '\\')
sani_path.push_back('/');
else
sani_path.push_back(ch);
}
return sani_path;
}

std::string GetDirectory(std::string_view path)
{
SYS_ASSERT(!path.empty());
Expand Down
1 change: 1 addition & 0 deletions source/lib_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ std::string GetExtension(std::string_view path);
std::string PathAppend(std::string_view parent, std::string_view child);
bool IsPathAbsolute(std::string_view path);
void ReplaceExtension(std::string &path, std::string_view ext);
std::string SanitizePath(std::string_view path);

std::string CurrentDirectoryGet();
bool MakeDirectory(std::string_view dir);
Expand Down
4 changes: 2 additions & 2 deletions source/m_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ std::string DLG_OutputFilename(const char *ext, const char *preset)

chooser.filter(kind_buf.c_str());

auto best_dir = BestDirectory();
std::string best_dir = SanitizePath(BestDirectory());

if (preset)
{
Expand Down Expand Up @@ -633,7 +633,7 @@ tryagain:;

if (!last_directory.empty())
{
chooser.directory(last_directory.c_str());
chooser.directory(SanitizePath(last_directory).c_str());
}

switch (chooser.show())
Expand Down
8 changes: 4 additions & 4 deletions source/m_manage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ class UI_Manage_Config : public Fl_Double_Window

if (!last_directory.empty())
{
chooser.directory(last_directory.c_str());
chooser.directory(SanitizePath(last_directory).c_str());
}
else
{
chooser.directory(install_dir.c_str());
chooser.directory(SanitizePath(install_dir).c_str());
}

switch (chooser.show())
Expand Down Expand Up @@ -479,11 +479,11 @@ class UI_Manage_Config : public Fl_Double_Window

if (!last_directory.empty())
{
chooser.directory(last_directory.c_str());
chooser.directory(SanitizePath(last_directory).c_str());
}
else
{
chooser.directory(install_dir.c_str());
chooser.directory(SanitizePath(install_dir).c_str());
}

switch (chooser.show())
Expand Down
2 changes: 1 addition & 1 deletion source/m_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ class UI_OptionsWin : public Fl_Window

chooser.title(_("Select default save directory"));
chooser.type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
chooser.directory(BestDirectory().c_str());
chooser.directory(SanitizePath(BestDirectory()).c_str());

int result = chooser.show();

Expand Down
4 changes: 2 additions & 2 deletions source/m_theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ std::string Theme_OutputFilename()
chooser.filter("Text files\t*.txt");

std::string theme_dir = PathAppend(install_dir, "theme");
chooser.directory(theme_dir.c_str());
chooser.directory(SanitizePath(theme_dir).c_str());

FL_NORMAL_SIZE = old_font_h;

Expand Down Expand Up @@ -102,7 +102,7 @@ std::string Theme_AskLoadFilename()
chooser.filter("Text files\t*.txt");

std::string theme_dir = PathAppend(install_dir, "theme");
chooser.directory(theme_dir.c_str());
chooser.directory(SanitizePath(theme_dir).c_str());

int result = chooser.show();

Expand Down

0 comments on commit a775f54

Please sign in to comment.