39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
#include "Utils.h"
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <fstream>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
#include <cstdlib>
|
|
|
|
std::string strip_whitespaces (const std::string input_str) {
|
|
std::string result = input_str.substr(input_str.find_first_not_of (" \t\n\r"), input_str.size());
|
|
return result.substr (0, result.find_last_not_of(" \t\n\r") + 1);
|
|
}
|
|
|
|
bool create_dir (const std::string &dir_str) {
|
|
boost::filesystem::path dir_str_path(dir_str);
|
|
if(!boost::filesystem::is_directory (dir_str_path)) {
|
|
if (!boost::filesystem::create_directory(dir_str_path)) {
|
|
std::cerr << "Warning: could not create directory " << dir_str<< std::endl;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
std::string test_file_path = dir_str;
|
|
test_file_path += "/fysxasteroids_write_test_delete_me.txt";
|
|
std::ofstream test_file (test_file_path.c_str(), std::ios_base::app);
|
|
if (!test_file) {
|
|
test_file.close();
|
|
std::cerr << "Warning: directory not writable! " << dir_str << std::endl;
|
|
return false;
|
|
} else {
|
|
test_file.close();
|
|
boost::filesystem::remove (test_file_path);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|