34 #include <boost/filesystem.hpp>
38 namespace fs = boost::filesystem;
44 void createDirectoryIfNotExistent(boost::filesystem::path
const& _path)
46 if (!fs::exists(_path))
48 fs::create_directories(_path);
59 ret <<
"<pre style=\"font-family: Monospace,Lucida Console,Courier,Courier New,sans-serif; font-size: small\">";
60 for (
unsigned i = 0; i < _bytes.size(); i += _width)
62 ret << hex << setw(4) << setfill(
'0') << i <<
" ";
63 for (
unsigned j = i; j < i + _width; ++j)
64 if (j < _bytes.size())
65 if (_bytes[j] >= 32 && _bytes[j] < 127)
66 if ((
char)_bytes[j] ==
'<' && _html)
68 else if ((
char)_bytes[j] ==
'&' && _html)
71 ret << (char)_bytes[j];
77 for (
unsigned j = i; j < i + _width && j < _bytes.size(); ++j)
78 ret << setfill(
'0') << setw(2) << hex << (unsigned)_bytes[j] <<
" ";
86 template <
typename _T>
90 size_t const c_elementSize =
sizeof(
typename _T::value_type);
91 boost::filesystem::ifstream is(_file, std::ifstream::binary);
97 streamoff length = is.tellg();
102 ret.resize((length + c_elementSize - 1) / c_elementSize);
103 is.read(
const_cast<char*
>(
reinterpret_cast<char const*
>(ret.data())), length);
109 return contentsGeneric<bytes>(_file);
114 bytes b = contentsGeneric<bytes>(_file);
122 return contentsGeneric<string>(_file);
127 if (_writeDeleteRename)
132 fs::rename(tempPath, _file);
136 createDirectoryIfNotExistent(_file.parent_path());
138 boost::filesystem::ofstream s(_file, ios::trunc | ios::binary);
139 s.write(
reinterpret_cast<char const*
>(_data.
data()), _data.
size());
141 BOOST_THROW_EXCEPTION(FileError() <<
errinfo_comment(
"Could not write to file: " + _file.string()));
146 void copyDirectory(boost::filesystem::path
const& _srcDir, boost::filesystem::path
const& _dstDir)
148 createDirectoryIfNotExistent(_dstDir);
150 for (fs::directory_iterator file(_srcDir); file != fs::directory_iterator(); ++file)
151 fs::copy_file(file->path(), _dstDir / file->path().filename());
157 cout << _prompt << flush;
160 DWORD fdwSaveOldMode;
161 if ((hStdin = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE)
162 BOOST_THROW_EXCEPTION(
164 if (!GetConsoleMode(hStdin, &fdwSaveOldMode))
165 BOOST_THROW_EXCEPTION(
168 if (!SetConsoleMode(hStdin, fdwSaveOldMode & (~ENABLE_ECHO_INPUT)))
169 BOOST_THROW_EXCEPTION(
173 std::getline(cin, ret);
175 if (!SetConsoleMode(hStdin, fdwSaveOldMode))
176 BOOST_THROW_EXCEPTION(
180 struct termios oflags;
181 struct termios nflags;
185 tcgetattr(fileno(stdin), &oflags);
187 nflags.c_lflag &= ~ECHO;
188 nflags.c_lflag |= ECHONL;
190 if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0)
193 printf(
"%s", _prompt.c_str());
194 if (!fgets(password,
sizeof(password), stdin))
196 password[strlen(password) - 1] = 0;
199 if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0)