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
|
|
|
|
2015-11-03 08:38:09 -05:00
|
|
|
#include <detail/include_windows.hpp>
|
2016-10-18 19:27:26 -04:00
|
|
|
#include <xlnt/utils/path.hpp>
|
2015-11-03 08:38:09 -05:00
|
|
|
|
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>
|
2015-11-03 08:38:09 -05:00
|
|
|
#elif defined(_MSC_VER)
|
2014-05-21 10:20:30 -04:00
|
|
|
#include <Shlwapi.h>
|
2015-11-03 08:38:09 -05:00
|
|
|
#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
|
|
|
|
|
2016-07-20 19:04:44 -04:00
|
|
|
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
|
|
|
{
|
2016-10-25 20:21:58 -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");
|
|
|
|
}
|
|
|
|
|
2016-08-12 00:22:14 -04:00
|
|
|
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
|
|
|
{
|
2016-08-12 00:22:14 -04:00
|
|
|
std::remove(path.string().c_str());
|
2014-05-21 10:20:30 -04:00
|
|
|
}
|
2014-05-21 19:17:56 -04:00
|
|
|
};
|