mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
remove shlwapi functions and use stat instead
This commit is contained in:
parent
f679f8a8d1
commit
116e53fb0c
|
@ -22,21 +22,17 @@
|
||||||
// @author: see AUTHORS file
|
// @author: see AUTHORS file
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <detail/include_windows.hpp>
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <mach-o/dyld.h>
|
#include <mach-o/dyld.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
#include <Shlwapi.h>
|
|
||||||
#elif defined(__linux)
|
#elif defined(__linux)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <detail/include_windows.hpp>
|
||||||
#include <xlnt/utils/path.hpp>
|
#include <xlnt/utils/path.hpp>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -54,12 +50,6 @@ bool is_root(const std::string &part)
|
||||||
&& part.front() >= 'A' && part.front() <= 'Z';
|
&& part.front() >= 'A' && part.front() <= 'Z';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool file_exists(const std::string &path_string)
|
|
||||||
{
|
|
||||||
std::wstring path_wide(path_string.begin(), path_string.end());
|
|
||||||
return PathFileExists(path_wide.c_str()) && !PathIsDirectory(path_wide.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string get_working_directory()
|
std::string get_working_directory()
|
||||||
{
|
{
|
||||||
TCHAR buffer[MAX_PATH];
|
TCHAR buffer[MAX_PATH];
|
||||||
|
@ -80,22 +70,6 @@ bool is_root(const std::string &part)
|
||||||
return part.empty();
|
return part.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool file_exists(const std::string &path_string)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
struct stat fileAtt;
|
|
||||||
|
|
||||||
if (stat(path.c_str(), &fileAtt) == 0)
|
|
||||||
{
|
|
||||||
return S_ISREG(fileAtt.st_mode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (...) {}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string get_working_directory()
|
std::string get_working_directory()
|
||||||
{
|
{
|
||||||
std::size_t buffer_size = 100;
|
std::size_t buffer_size = 100;
|
||||||
|
@ -153,6 +127,12 @@ std::vector<std::string> split_path_universal(const std::string &path)
|
||||||
return initial;
|
return initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool file_exists(const std::string &path)
|
||||||
|
{
|
||||||
|
struct stat info;
|
||||||
|
return stat(path.c_str(), &info) == 0 && (info.st_mode & S_IFREG);
|
||||||
|
}
|
||||||
|
|
||||||
bool directory_exists(const std::string path)
|
bool directory_exists(const std::string path)
|
||||||
{
|
{
|
||||||
struct stat info;
|
struct stat info;
|
||||||
|
|
26
source/utils/tests/test_path.hpp
Normal file
26
source/utils/tests/test_path.hpp
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cxxtest/TestSuite.h>
|
||||||
|
|
||||||
|
#include <helpers/path_helper.hpp>
|
||||||
|
#include <helpers/temporary_file.hpp>
|
||||||
|
#include <xlnt/xlnt.hpp>
|
||||||
|
|
||||||
|
class test_path : public CxxTest::TestSuite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void test_exists()
|
||||||
|
{
|
||||||
|
temporary_file temp;
|
||||||
|
|
||||||
|
if (temp.get_path().exists())
|
||||||
|
{
|
||||||
|
path_helper::delete_file(temp.get_path());
|
||||||
|
}
|
||||||
|
|
||||||
|
TS_ASSERT(!temp.get_path().exists());
|
||||||
|
std::ofstream stream(temp.get_path().to_string());
|
||||||
|
TS_ASSERT(temp.get_path().exists());
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user