mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Add base::make_all_directories function
This commit is contained in:
parent
fb68969ba5
commit
87857f5a95
@ -1,5 +1,5 @@
|
|||||||
# Aseprite
|
# Aseprite
|
||||||
# Copyright (C) 2001-2013 David Capello
|
# Copyright (C) 2001-2014 David Capello
|
||||||
|
|
||||||
add_library(app-lib
|
add_library(app-lib
|
||||||
app.cpp
|
app.cpp
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Aseprite Base Library
|
# Aseprite Base Library
|
||||||
# Copyright (c) 2001-2013 David Capello
|
# Copyright (c) 2001-2014 David Capello
|
||||||
|
|
||||||
include(CheckCSourceCompiles)
|
include(CheckCSourceCompiles)
|
||||||
|
|
||||||
|
@ -9,9 +9,36 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "base/fs.h"
|
#include "base/fs.h"
|
||||||
|
#include "base/split_string.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "base/fs_win32.h"
|
#include "base/fs_win32.h"
|
||||||
#else
|
#else
|
||||||
#include "base/fs_unix.h"
|
#include "base/fs_unix.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace base {
|
||||||
|
|
||||||
|
void make_all_directories(const std::string& path)
|
||||||
|
{
|
||||||
|
std::vector<std::string> parts;
|
||||||
|
split_string(path, parts, "/\\");
|
||||||
|
|
||||||
|
std::string intermediate;
|
||||||
|
for (const std::string& component : parts) {
|
||||||
|
if (component.empty()) {
|
||||||
|
if (intermediate.empty())
|
||||||
|
intermediate += "/";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
intermediate = join_path(intermediate, component);
|
||||||
|
|
||||||
|
if (is_file(intermediate))
|
||||||
|
throw std::runtime_error("Error creating directory (a component is a file name)");
|
||||||
|
else if (!is_directory(intermediate))
|
||||||
|
make_directory(intermediate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace base
|
||||||
|
@ -23,6 +23,7 @@ namespace base {
|
|||||||
void remove_readonly_attr(const std::string& path);
|
void remove_readonly_attr(const std::string& path);
|
||||||
|
|
||||||
void make_directory(const std::string& path);
|
void make_directory(const std::string& path);
|
||||||
|
void make_all_directories(const std::string& path);
|
||||||
void remove_directory(const std::string& path);
|
void remove_directory(const std::string& path);
|
||||||
|
|
||||||
std::string get_app_path();
|
std::string get_app_path();
|
||||||
|
@ -6,8 +6,10 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <shlobj.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "base/path.h"
|
||||||
#include "base/string.h"
|
#include "base/string.h"
|
||||||
#include "base/win32_exception.h"
|
#include "base/win32_exception.h"
|
||||||
|
|
||||||
@ -66,7 +68,6 @@ void make_directory(const std::string& path)
|
|||||||
throw Win32Exception("Error creating directory");
|
throw Win32Exception("Error creating directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void remove_directory(const std::string& path)
|
void remove_directory(const std::string& path)
|
||||||
{
|
{
|
||||||
BOOL result = ::RemoveDirectory(from_utf8(path).c_str());
|
BOOL result = ::RemoveDirectory(from_utf8(path).c_str());
|
||||||
@ -86,7 +87,7 @@ std::string get_app_path()
|
|||||||
std::string get_temp_path()
|
std::string get_temp_path()
|
||||||
{
|
{
|
||||||
TCHAR buffer[MAX_PATH+1];
|
TCHAR buffer[MAX_PATH+1];
|
||||||
DWORD result = GetTempPath(sizeof(buffer)/sizeof(TCHAR), buffer);
|
DWORD result = ::GetTempPath(sizeof(buffer)/sizeof(TCHAR), buffer);
|
||||||
return to_utf8(buffer);
|
return to_utf8(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user