Skip to content

Commit

Permalink
Add base::set_current_path() function
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Apr 24, 2024
1 parent 0b25692 commit 9769a5b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion base/fs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF Base Library
// Copyright (c) 2020-2021 Igara Studio S.A.
// Copyright (c) 2020-2024 Igara Studio S.A.
// Copyright (c) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
Expand Down Expand Up @@ -39,6 +39,8 @@ namespace base {
void remove_directory(const std::string& path);

std::string get_current_path();
void set_current_path(const std::string& path);

std::string get_app_path();
std::string get_temp_path();
std::string get_user_docs_folder();
Expand Down
9 changes: 7 additions & 2 deletions base/fs_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,16 @@ void remove_directory(const std::string& path)
std::string get_current_path()
{
std::vector<char> path(MAXPATHLEN);
if (getcwd(&path[0], path.size()))
return std::string(&path[0]);
if (getcwd(path.data(), path.size()))
return std::string(path.data());
return std::string();
}

void set_current_path(const std::string& path)
{
chdir(path.data());
}

std::string get_app_path()
{
std::vector<char> path(MAXPATHLEN);
Expand Down
7 changes: 6 additions & 1 deletion base/fs_win32.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF Base Library
// Copyright (c) 2020 Igara Studio S.A.
// Copyright (c) 2020-2024 Igara Studio S.A.
// Copyright (c) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
Expand Down Expand Up @@ -123,6 +123,11 @@ std::string get_current_path()
return "";
}

void set_current_path(const std::string& path)
{
::SetCurrentDirectory(from_utf8(path).c_str());
}

std::string get_app_path()
{
TCHAR buffer[MAX_PATH+1];
Expand Down

0 comments on commit 9769a5b

Please sign in to comment.