xlnt/tests/helpers/path_helper.hpp

50 lines
1.1 KiB
C++
Raw Normal View History

2014-05-18 21:29:19 -04:00
#pragma once
2014-05-19 20:47:15 -04:00
#include <array>
2014-05-21 10:20:30 -04:00
#include <fstream>
2015-10-14 00:03:48 -04:00
#include <string>
#include <sstream>
2014-05-19 20:47:15 -04:00
#include <detail/include_windows.hpp>
2016-10-18 19:27:26 -04:00
#include <xlnt/utils/path.hpp>
2014-05-18 21:29:19 -04:00
#ifdef __APPLE__
#include <mach-o/dyld.h>
2014-05-21 10:20:30 -04:00
#include <sys/stat.h>
#elif defined(_MSC_VER)
2014-05-21 10:20:30 -04:00
#include <Shlwapi.h>
#elif defined(__linux)
2014-05-30 18:42:25 -04:00
#include <unistd.h>
#include <linux/limits.h>
#include <sys/types.h>
2014-05-21 19:17:56 -04:00
#include <sys/stat.h>
2014-05-18 21:29:19 -04:00
#endif
class path_helper
2014-05-18 21:29:19 -04:00
{
public:
2016-08-03 00:12:18 -04:00
static xlnt::path get_data_directory(const std::string &append = "")
2014-05-18 21:29:19 -04:00
{
return xlnt::path("data")
2016-08-03 00:12:18 -04:00
.append(xlnt::path(append));
2014-05-18 21:29:19 -04:00
}
2014-05-21 10:20:30 -04:00
2016-08-03 00:12:18 -04:00
static void copy_file(const xlnt::path &source, const xlnt::path &destination, bool overwrite)
2014-05-21 10:20:30 -04:00
{
2016-08-03 00:12:18 -04:00
if(!overwrite && destination.exists())
2014-05-21 10:20:30 -04:00
{
throw std::runtime_error("destination file already exists and overwrite==false");
}
std::ifstream src(source.string(), std::ios::binary);
std::ofstream dst(destination.string(), std::ios::binary);
2014-05-21 10:20:30 -04:00
dst << src.rdbuf();
}
2014-06-04 18:42:17 -04:00
2016-08-03 00:12:18 -04:00
static void delete_file(const xlnt::path &path)
2014-06-04 18:42:17 -04:00
{
std::remove(path.string().c_str());
2014-05-21 10:20:30 -04:00
}
2014-05-21 19:17:56 -04:00
};