mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2024-11-23 11:15:34 +08:00
common files used by crash printer
This commit is contained in:
parent
85abf09650
commit
d15441a30e
38
crash_printer/common.cpp
Normal file
38
crash_printer/common.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "crash_printer/common.hpp"
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
||||
static bool create_dir_impl(std::filesystem::path &dirpath)
|
||||
{
|
||||
if (std::filesystem::is_directory(dirpath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (std::filesystem::exists(dirpath)) // a file, we can't do anything
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::filesystem::create_directories(dirpath);
|
||||
}
|
||||
|
||||
bool crash_printer::create_dir(const std::string &filepath)
|
||||
{
|
||||
std::filesystem::path dirpath = std::filesystem::path(filepath).parent_path();
|
||||
return create_dir_impl(dirpath);
|
||||
}
|
||||
|
||||
bool crash_printer::create_dir(const std::wstring &filepath)
|
||||
{
|
||||
std::filesystem::path dirpath = std::filesystem::path(filepath).parent_path();
|
||||
return create_dir_impl(dirpath);
|
||||
}
|
||||
|
||||
void crash_printer::write(std::ofstream &file, const std::string &data)
|
||||
{
|
||||
if (!file.is_open()) {
|
||||
return;
|
||||
}
|
||||
|
||||
file << data << std::endl;
|
||||
}
|
18
crash_printer/crash_printer/common.hpp
Normal file
18
crash_printer/crash_printer/common.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef _CRASH_PRINTER_COMMON_H
|
||||
#define _CRASH_PRINTER_COMMON_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
namespace crash_printer {
|
||||
|
||||
bool create_dir(const std::string &dir);
|
||||
|
||||
bool create_dir(const std::wstring &dir);
|
||||
|
||||
void write(std::ofstream &file, const std::string &data);
|
||||
|
||||
}
|
||||
|
||||
#endif // _CRASH_PRINTER_COMMON_H
|
Loading…
Reference in New Issue
Block a user