mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
fix windows bug
This commit is contained in:
parent
0b62d1e1d6
commit
ef2b8de33d
|
@ -73,7 +73,7 @@ std::string join_path(const std::vector<std::string> &parts)
|
|||
|
||||
if (i++ != parts.size() - 1)
|
||||
{
|
||||
joined.append(1, directory_separator);
|
||||
joined.append(1, '/');
|
||||
}
|
||||
}
|
||||
return joined;
|
||||
|
@ -687,10 +687,14 @@ void zip_file::extract(const std::string &member)
|
|||
|
||||
void zip_file::extract(const std::string &member, const std::string &path)
|
||||
{
|
||||
auto fullpath = join_path({ path, member });
|
||||
auto split = split_path(fullpath);
|
||||
split.pop_back();
|
||||
mkdir_recursive(join_path(split));
|
||||
auto member_split = split_path(member);
|
||||
auto fullpath_parts = split_path(path);
|
||||
fullpath_parts.insert(fullpath_parts.end(), member_split.begin(), member_split.end());
|
||||
auto fullpath = join_path(fullpath_parts);
|
||||
|
||||
auto directory = fullpath_parts;
|
||||
directory.pop_back();
|
||||
mkdir_recursive(join_path(directory));
|
||||
|
||||
std::fstream stream(fullpath, std::ios::binary | std::ios::out);
|
||||
stream << open(member).rdbuf();
|
||||
|
|
|
@ -279,7 +279,7 @@ public:
|
|||
xlnt::zip_file f;
|
||||
f.load(PathHelper::GetDataDirectory("/genuine/empty.xlsx"));
|
||||
|
||||
auto expected = PathHelper::GetExecutableDirectory() + "xl/styles.xml";
|
||||
auto expected = PathHelper::GetWorkingDirectory() + "/xl/styles.xml";
|
||||
|
||||
TS_ASSERT(!PathHelper::FileExists(expected));
|
||||
f.extract("xl/styles.xml");
|
||||
|
|
|
@ -90,6 +90,20 @@ public:
|
|||
|
||||
}
|
||||
|
||||
static std::string GetWorkingDirectory()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
TCHAR buffer[MAX_PATH];
|
||||
GetCurrentDirectory(MAX_PATH, buffer);
|
||||
std::basic_string<TCHAR> working_directory(buffer);
|
||||
return WindowsToUniversalPath(std::string(working_directory.begin(), working_directory.end()));
|
||||
#else
|
||||
char buffer[2048];
|
||||
getcwd(buffer, 2048);
|
||||
return std::string(buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
static std::string GetDataDirectory(const std::string &append = "")
|
||||
{
|
||||
return GetExecutableDirectory() + "../../tests/data" + append;
|
||||
|
|
Loading…
Reference in New Issue
Block a user