fix windows bug

This commit is contained in:
Thomas Fussell 2016-07-20 10:28:12 +08:00
parent 0b62d1e1d6
commit ef2b8de33d
3 changed files with 24 additions and 6 deletions

View File

@ -73,7 +73,7 @@ std::string join_path(const std::vector<std::string> &parts)
if (i++ != parts.size() - 1) if (i++ != parts.size() - 1)
{ {
joined.append(1, directory_separator); joined.append(1, '/');
} }
} }
return joined; 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) void zip_file::extract(const std::string &member, const std::string &path)
{ {
auto fullpath = join_path({ path, member }); auto member_split = split_path(member);
auto split = split_path(fullpath); auto fullpath_parts = split_path(path);
split.pop_back(); fullpath_parts.insert(fullpath_parts.end(), member_split.begin(), member_split.end());
mkdir_recursive(join_path(split)); 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); std::fstream stream(fullpath, std::ios::binary | std::ios::out);
stream << open(member).rdbuf(); stream << open(member).rdbuf();

View File

@ -279,7 +279,7 @@ public:
xlnt::zip_file f; xlnt::zip_file f;
f.load(PathHelper::GetDataDirectory("/genuine/empty.xlsx")); 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)); TS_ASSERT(!PathHelper::FileExists(expected));
f.extract("xl/styles.xml"); f.extract("xl/styles.xml");

View File

@ -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 = "") static std::string GetDataDirectory(const std::string &append = "")
{ {
return GetExecutableDirectory() + "../../tests/data" + append; return GetExecutableDirectory() + "../../tests/data" + append;