inline void current_path(const char* directory) { int ec; current_path( directory, ec ); if( ec ) BOOST_THROW_EXCEPTION( std::runtime_error( std::string("Error setting ") + directory + " as current path (current path was " + current_path() + ")" ) ); }
void DictionaryValue::Set(const std::string& path, Value* in_value) { DCHECK(IsStringUTF8(path)); DCHECK(in_value); std::string current_path(path); DictionaryValue* current_dictionary = this; for(size_t delimiter_position=current_path.find('.'); delimiter_position!=std::string::npos; delimiter_position=current_path.find('.')) { // 按路径进入字典中的索引. std::string key(current_path, 0, delimiter_position); DictionaryValue* child_dictionary = NULL; if(!current_dictionary->GetDictionary(key, &child_dictionary)) { child_dictionary = new DictionaryValue; current_dictionary->SetWithoutPathExpansion(key, child_dictionary); } current_dictionary = child_dictionary; current_path.erase(0, delimiter_position+1); } current_dictionary->SetWithoutPathExpansion(current_path, in_value); }
void MPQCInit::init_work_dir() { char *mpqc_work_dir; mpqc_work_dir = std::getenv("MPQC_WORK_DIR"); // if not user defined, use current path if (mpqc_work_dir == nullptr) { path curr_path = current_path(); // set the work dir in FormIO FormIO::set_default_work_dir(curr_path.string()); } else { // check the correctness of path path work_path(mpqc_work_dir); bool path_exists = exists(work_path); if (!path_exists) { throw FileOperationFailed( "Path ${MPQC_WORK_DIR} does not exists! Please set environment " "variable MPQC_WORK_DIR to a valid path.\n", __FILE__, __LINE__, mpqc_work_dir, FileOperationFailed::Exists); } bool is_dir = is_directory(work_path); if (!is_dir) { throw FileOperationFailed( "Path ${MPQC_WORK_DIR} is not a directory! Please set environment " "variable MPQC_WORK_DIR to an existing directory.\n", __FILE__, __LINE__, mpqc_work_dir, FileOperationFailed::Chdir); } // set the work dir in FormIO FormIO::set_default_work_dir(mpqc_work_dir); } }
std::string get_user_data_dir() { static bool inited_dirs = false; const std::string dir_path = preferences::user_data_path(); if(!inited_dirs) { create_directory("userdata"); create_directory("userdata/saves"); create_directory("dlc"); inited_dirs = true; } path p = current_path() / "userdata"; return p.generic_string(); }
inline int remove_all( const char* file_path, int& ec ) { if(is_symlink(file_path) || !is_directory(file_path)) return remove(file_path, ec); int count; { current_path_saver const cps; current_path(file_path); count = details::remove_all_rec(ec); } return count + remove(file_path, ec); }
bool DictionaryValue::Remove(const std::string& path, Value** out_value) { DCHECK(IsStringUTF8(path)); std::string current_path(path); DictionaryValue* current_dictionary = this; size_t delimiter_position = current_path.rfind('.'); if(delimiter_position != std::string::npos) { if(!GetDictionary(current_path.substr(0, delimiter_position), ¤t_dictionary)) { return false; } current_path.erase(0, delimiter_position + 1); } return current_dictionary->RemoveWithoutPathExpansion(current_path, out_value); }
inline int remove_all_rec( int& ec ) { int count = 0; for ( directory_iterator current_dir( "." ); *current_dir; ++current_dir ) { if(is_symlink(*current_dir) || !is_directory(*current_dir)) { count += remove(*current_dir, ec); continue; } { current_path_saver const cps; current_path(*current_dir); count += remove_all_rec(ec); } count += remove(*current_dir, ec); } return count; }
void MakeDirectory::run(chars& params, string param1, string param2) { //mkdir directoryName //check if the parameters is an alias //if alias it will return a file with path //if not alias it will return nullptr then we use param1 path pathh; if (Aliases::fetchAliases()->fetchMap().count(param1)) { File* file = Aliases::fetchAliases()->findObject(param1); pathh = file->filePath(); } else pathh = param1; if (exists(absolute((new File(pathh))->filePath()))) { cout << "That directory already exists" << endl; return; } if (!pathh.is_absolute()) pathh = current_path() /= pathh; if (create_directories(pathh)) { cout << "Created directory " << param1 << endl; } else { cout << "Directory couldn't be created" << endl; } }
bool DictionaryValue::Get(const std::string& path, Value** out_value) const { DCHECK(IsStringUTF8(path)); std::string current_path(path); const DictionaryValue* current_dictionary = this; for(size_t delimiter_position=current_path.find('.'); delimiter_position!=std::string::npos; delimiter_position=current_path.find('.')) { DictionaryValue* child_dictionary = NULL; if(!current_dictionary->GetDictionary(current_path.substr( 0, delimiter_position), &child_dictionary)) { return false; } current_dictionary = child_dictionary; current_path.erase(0, delimiter_position+1); } return current_dictionary->GetWithoutPathExpansion(current_path, out_value); }
inline boost::filesystem::path resolve( boost::filesystem::path const& p, boost::filesystem::path const& base = current_path()) { boost::filesystem::path abspath = boost::filesystem::absolute(p, base); boost::filesystem::path result; for(boost::filesystem::path::iterator it = abspath.begin(); it != abspath.end(); ++it) { if (*it == "..") { // /a/b/.. is not necessarily /a if b is a symbolic link if (boost::filesystem::is_symlink(result)) result /= *it; // /a/b/../.. is not /a/b/.. under most circumstances // We can end up with ..s in our result because of symbolic links else if (result.filename() == "..") result /= *it; // Otherwise it should be safe to resolve the parent else result = result.parent_path(); } else if (*it == ".") { // Ignore } else { // Just cat other path entries result /= *it; } } return result; }
inline std::string absolute(const char* s) { current_path_saver const cps; current_path(s); return current_path(); }
inline void current_path(std::string const & directory, int & ec) { return current_path( directory.c_str(), ec ); }
void UpdaterTest::testSendingUpdateMessageToBumpTop() { // start up an instance of bumptop STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); #ifdef DEBUG path bumptopDirPath = current_path().branch_path() / path("Source/Debug", native); #else path bumptopDirPath = current_path().branch_path() / path("Source/Release", native); #endif path bumptopPath = bumptopDirPath / path("BumpTop.exe"); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line) (LPSTR) bumptopPath.native_file_string().c_str(), // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block (LPSTR) bumptopDirPath.native_directory_string().c_str(), // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure ) { ostringstream error_message; error_message << "CreateProcess failed (" << GetLastError() << ")\n"; CPPUNIT_ASSERT_MESSAGE(error_message.str(), false); } Sleep(500); // Search for BumpTop window bool foundBumptopWindow = false; HWND bumptopHwnd = 0; for (int i = 0; i < 50; i++) { CWindowIterator cwi(1000); for (HWND hwnd = cwi.First(); hwnd; hwnd=cwi.Next()) { if ((GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE)) { DWORD pidwin; GetWindowThreadProcessId(hwnd, &pidwin); TCHAR classnameBuffer[MAX_PATH+1]; GetClassName(hwnd, classnameBuffer, MAX_PATH); TCHAR titleBuffer[MAX_PATH+1]; GetWindowText(hwnd, titleBuffer, MAX_PATH); if (pidwin==pi.dwProcessId && string(classnameBuffer) == string("BumpTop") && string(titleBuffer) == string("BumpTop")) { foundBumptopWindow = true; bumptopHwnd = hwnd; break; } } } if (foundBumptopWindow) break; Sleep(100); // give the window a little time to start } CPPUNIT_ASSERT_MESSAGE("Testing if we found the BumpTop window", foundBumptopWindow); Sleep(500); vector<string> versionStrings; versionStrings.push_back("800"); MockUpdateServer *mus = new MockUpdateServer(versionStrings); Updater *u = new Updater(mus, 99, ".", 0, 0, bumptopHwnd); int updateDownloadedMessageResponse = u->sendUpdateDownloadedMessageToBumpTop(true); SendMessageTimeout(bumptopHwnd, WM_CLOSE, 0, 0, SMTO_NORMAL, 1000, NULL); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); CPPUNIT_ASSERT_EQUAL(3, updateDownloadedMessageResponse); }
current_path_saver() : cwd_(current_path()) { }
inline void current_path(std::string const & directory) { return current_path( directory.c_str() ); }
inline path canonical(const path& p, std::error_code& ec) { return detail::canonical(p, current_path(), &ec); }
inline path canonical(const path& p, const path& base = current_path()) { return detail::canonical(p, base); }
namespace elib { namespace fs { inline namespace v1 { using file_time_type = std::chrono::system_clock::time_point; //////////////////////////////////////////////////////////////////////////// struct space_info // returned by space function { std::uintmax_t capacity; std::uintmax_t free; std::uintmax_t available; // free space available to a non-privileged process }; //////////////////////////////////////////////////////////////////////////// enum class copy_options { none = 0, // copy file skip_existing = 1, overwrite_existing = 2, update_existing = 4, // copy sub-directories recursive = 8, //copy symbolic links copy_symlinks = 16, skip_symlinks = 32, // form of copy directories_only = 64, create_symlinks = 128, create_hard_links = 256, // implementation detail detail_in_recursive_copy = 512 }; //////////////////////////////////////////////////////////////////////////// constexpr copy_options operator~(copy_options lhs) noexcept { return static_cast<copy_options>( ~ static_cast<int>(lhs) ); } //////////////////////////////////////////////////////////////////////////// constexpr copy_options operator&(copy_options lhs, copy_options rhs) noexcept { return static_cast<copy_options>( static_cast<int>(lhs) & static_cast<int>(rhs) ); } //////////////////////////////////////////////////////////////////////////// inline copy_options & operator&=(copy_options & lhs, copy_options rhs) noexcept { return lhs = lhs & rhs; } //////////////////////////////////////////////////////////////////////////// constexpr copy_options operator|(copy_options lhs, copy_options rhs) noexcept { return static_cast<copy_options>( static_cast<int>(lhs) | static_cast<int>(rhs) ); } //////////////////////////////////////////////////////////////////////////// inline copy_options & operator|=(copy_options & lhs, copy_options rhs) noexcept { return lhs = lhs | rhs; } //////////////////////////////////////////////////////////////////////////// constexpr copy_options operator^(copy_options lhs, copy_options rhs) noexcept { return static_cast<copy_options>( static_cast<int>(lhs) ^ static_cast<int>(rhs) ); } //////////////////////////////////////////////////////////////////////////// inline copy_options & operator^=(copy_options & lhs, copy_options rhs) noexcept { return lhs = lhs ^ rhs; } // operations handling is similar to the boost version // both except && no-except function signatures call a wrapper namespace detail { //////////////////////////////////////////////////////////////////////// path canonical(const path& p, const path& base, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// void copy(const path& from, const path& to, copy_options opt, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// bool copy_file(const path& from, const path& to, copy_options option, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// void copy_symlink(const path& existing_symlink, const path& new_symlink, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// bool create_directories(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// bool create_directory(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// bool create_directory(const path& p, const path & attributes, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// void create_directory_symlink(const path& to, const path& new_symlink, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// void create_hard_link(const path& to, const path& new_hard_link, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// void create_symlink(const path& to, const path& new_symlink, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// path current_path(std::error_code *ec=nullptr); void current_path(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// bool equivalent(const path& p1, const path& p2, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// std::uintmax_t file_size(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// std::uintmax_t hard_link_count(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// bool is_empty(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// file_time_type last_write_time(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// void last_write_time(const path& p, file_time_type new_time, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// void permissions(const path& p, perms prms, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// path read_symlink(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// bool remove(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// std::uintmax_t remove_all(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// void rename(const path& from, const path& to, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// void resize_file(const path& p, uintmax_t size, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// space_info space(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// file_status status(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// file_status symlink_status(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// path system_complete(const path& p, std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// path temp_directory_path(std::error_code *ec=nullptr); //////////////////////////////////////////////////////////////////////// path unique_path(const path& model, std::error_code *ec=nullptr); } // namespace detail //////////////////////////////////////////////////////////////////////////////// // OPERATIONS //////////////////////////////////////////////////////////////////////////////// // forward // path current_path(); bool status_known(file_status s) noexcept; //////////////////////////////////////////////////////////////////////////// path absolute(const path& p, const path& base = current_path()); //////////////////////////////////////////////////////////////////////////// inline path canonical(const path& p, const path& base = current_path()) { return detail::canonical(p, base); } inline path canonical(const path& p, std::error_code& ec) { return detail::canonical(p, current_path(), &ec); } inline path canonical(const path& p, const path& base, std::error_code& ec) { return detail::canonical(p, base, &ec); } //////////////////////////////////////////////////////////////////////////// inline void copy(const path& from, const path& to) { detail::copy(from, to, copy_options::none); } inline void copy(const path& from, const path& to, std::error_code& ec) noexcept { detail::copy(from, to, copy_options::none, &ec); } inline void copy(const path& from, const path& to, copy_options option) { detail::copy(from, to, option); } inline void copy(const path& from, const path& to, copy_options option, std::error_code& ec) noexcept { detail::copy(from, to, option, &ec); } //////////////////////////////////////////////////////////////////////////// inline bool copy_file(const path& from, const path& to) { return detail::copy_file(from, to, copy_options::none); } inline bool copy_file(const path& from, const path& to, std::error_code& ec) noexcept { return detail::copy_file(from, to, copy_options::none, &ec); } inline bool copy_file(const path& from, const path& to, copy_options option) { return detail::copy_file(from, to, option); } inline bool copy_file(const path& from, const path& to, copy_options option, std::error_code& ec) noexcept { return detail::copy_file(from, to, option, &ec); } //////////////////////////////////////////////////////////////////////////// inline void copy_symlink(const path& existing_symlink, const path& new_symlink) { detail::copy_symlink(existing_symlink, new_symlink); } inline void copy_symlink(const path& existing_symlink, const path& new_symlink, std::error_code& ec) noexcept { detail::copy_symlink(existing_symlink, new_symlink, &ec); } //////////////////////////////////////////////////////////////////////////// inline bool create_directories(const path& p) { return detail::create_directories(p); } inline bool create_directories(const path& p, std::error_code& ec) noexcept { return detail::create_directories(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline bool create_directory(const path& p) { return detail::create_directory(p); } inline bool create_directory(const path& p, std::error_code& ec) noexcept { return detail::create_directory(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline bool create_directory(const path& p, const path& attributes) { return detail::create_directory(p, attributes); } inline bool create_directory( const path& p, const path& attributes , std::error_code& ec ) noexcept { return detail::create_directory(p, attributes, &ec); } //////////////////////////////////////////////////////////////////////////// inline void create_directory_symlink(const path& to, const path& new_symlink) { detail::create_directory_symlink(to, new_symlink); } inline void create_directory_symlink(const path& to, const path& new_symlink, std::error_code& ec) noexcept { detail::create_directory_symlink(to, new_symlink, &ec); } //////////////////////////////////////////////////////////////////////////// inline void create_hard_link(const path& to, const path& new_hard_link) { detail::create_hard_link(to, new_hard_link); } inline void create_hard_link(const path& to, const path& new_hard_link, std::error_code& ec) noexcept { detail::create_hard_link(to, new_hard_link, &ec); } //////////////////////////////////////////////////////////////////////////// inline void create_symlink(const path& to, const path& new_symlink) { detail::create_symlink(to, new_symlink); } inline void create_symlink(const path& to, const path& new_symlink, std::error_code& ec) noexcept { detail::create_symlink(to, new_symlink, &ec); } //////////////////////////////////////////////////////////////////////////// inline path current_path() { return detail::current_path(); } inline path current_path(std::error_code& ec) { return detail::current_path(&ec); } inline void current_path(const path& p) { detail::current_path(p); } inline void current_path(const path& p, std::error_code& ec) noexcept { detail::current_path(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline bool exists(file_status s) noexcept { return status_known(s) && s.type() != file_type::not_found; } inline bool exists(const path& p) { return exists(detail::status(p)); } inline bool exists(const path& p, std::error_code& ec) noexcept { return exists(detail::status(p, &ec)); } //////////////////////////////////////////////////////////////////////////// inline bool equivalent(const path& p1, const path& p2) { return detail::equivalent(p1, p2); } inline bool equivalent(const path& p1, const path& p2, std::error_code& ec) noexcept { return detail::equivalent(p1, p2, &ec); } //////////////////////////////////////////////////////////////////////////// inline std::uintmax_t file_size(const path& p) { return detail::file_size(p); } inline std::uintmax_t file_size(const path& p, std::error_code& ec) noexcept { return detail::file_size(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline std::uintmax_t hard_link_count(const path& p) { return detail::hard_link_count(p); } inline std::uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcept { return detail::hard_link_count(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline bool is_block_file(file_status s) noexcept { return s.type() == file_type::block; } inline bool is_block_file(const path& p) { return is_block_file(detail::status(p)); } inline bool is_block_file(const path& p, std::error_code& ec) noexcept { return is_block_file(detail::status(p, &ec)); } //////////////////////////////////////////////////////////////////////////// inline bool is_character_file(file_status s) noexcept { return s.type() == file_type::character; } inline bool is_character_file(const path& p) { return is_character_file(detail::status(p)); } inline bool is_character_file(const path& p, std::error_code& ec) noexcept { return is_character_file(detail::status(p, &ec)); } //////////////////////////////////////////////////////////////////////////// inline bool is_regular_file(file_status s) noexcept { return s.type() == file_type::regular; } inline bool is_regular_file(const path& p) { return is_regular_file(detail::status(p)); } inline bool is_regular_file(const path& p, std::error_code& ec) noexcept { return is_regular_file(detail::status(p, &ec)); } //////////////////////////////////////////////////////////////////////////// inline bool is_directory(file_status s) noexcept { return s.type() == file_type::directory; } inline bool is_directory(const path& p) { return is_directory(detail::status(p)); } inline bool is_directory(const path& p, std::error_code& ec) noexcept { return is_directory(detail::status(p, &ec)); } //////////////////////////////////////////////////////////////////////////// inline bool is_empty(const path& p) { return detail::is_empty(p); } inline bool is_empty(const path& p, std::error_code& ec) noexcept { return detail::is_empty(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline bool is_fifo(file_status s) noexcept { return s.type() == file_type::fifo; } inline bool is_fifo(const path& p) { return is_fifo(detail::status(p)); } inline bool is_fifo(const path& p, std::error_code& ec) noexcept { return is_fifo(detail::status(p, &ec)); } //////////////////////////////////////////////////////////////////////////// inline bool is_socket(file_status s) noexcept { return s.type() == file_type::socket; } inline bool is_socket(const path& p) { return is_socket(detail::status(p)); } inline bool is_socket(const path& p, std::error_code& ec) noexcept { return is_socket(detail::status(p, &ec)); } //////////////////////////////////////////////////////////////////////////// inline bool is_symlink(file_status s) noexcept { return s.type() == file_type::symlink; } inline bool is_symlink(const path& p) { return is_symlink(detail::symlink_status(p)); } inline bool is_symlink(const path& p, std::error_code& ec) noexcept { return is_symlink(detail::symlink_status(p, &ec)); } //////////////////////////////////////////////////////////////////////////// inline bool is_other(file_status s) noexcept { return (exists(s) && not is_regular_file(s) && not is_directory(s) && not is_symlink(s)); } inline bool is_other(const path& p) { return is_other(detail::status(p)); } inline bool is_other(const path& p, std::error_code& ec) noexcept { return is_other(detail::status(p, &ec)); } //////////////////////////////////////////////////////////////////////////// inline file_time_type last_write_time(const path& p) { return detail::last_write_time(p); } inline file_time_type last_write_time(const path& p, std::error_code& ec) noexcept { return detail::last_write_time(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline void last_write_time(const path& p, file_time_type new_time) { detail::last_write_time(p, new_time); } inline void last_write_time(const path& p, file_time_type new_time, std::error_code& ec) noexcept { detail::last_write_time(p, new_time, &ec); } //////////////////////////////////////////////////////////////////////////// inline void permissions(path const & p, perms prms) { detail::permissions(p, prms); } inline void permissions(path const & p, perms prms, std::error_code & ec) noexcept { detail::permissions(p, prms, &ec); } //////////////////////////////////////////////////////////////////////////// inline path read_symlink(const path& p) { return detail::read_symlink(p); } inline path read_symlink(const path& p, std::error_code& ec) { return detail::read_symlink(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline bool remove(const path& p) { return detail::remove(p); } inline bool remove(const path& p, std::error_code& ec) noexcept { return detail::remove(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline std::uintmax_t remove_all(const path& p) { return detail::remove_all(p); } inline std::uintmax_t remove_all(const path& p, std::error_code& ec) noexcept { return detail::remove_all(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline void rename(const path& from, const path& to) { detail::rename(from, to); } inline void rename(const path& from, const path& to, std::error_code& ec) noexcept { detail::rename(from, to, &ec); } //////////////////////////////////////////////////////////////////////////// inline void resize_file(const path& p, uintmax_t size) { detail::resize_file(p, size); } inline void resize_file(const path& p, uintmax_t size, std::error_code& ec) noexcept { detail::resize_file(p, size, &ec); } //////////////////////////////////////////////////////////////////////////// inline space_info space(const path& p) { return detail::space(p); } inline space_info space(const path& p, std::error_code& ec) noexcept { return detail::space(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline file_status status(const path& p) { return detail::status(p); } inline file_status status(const path& p, std::error_code& ec) noexcept { return detail::status(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline bool status_known(file_status s) noexcept { return s.type() != file_type::none; } //////////////////////////////////////////////////////////////////////////// inline file_status symlink_status(const path& p) { return detail::symlink_status(p); } inline file_status symlink_status(const path& p, std::error_code& ec) noexcept { return detail::symlink_status(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline path system_complete(const path& p) { return detail::system_complete(p); } inline path system_complete(const path& p, std::error_code& ec) { return detail::system_complete(p, &ec); } //////////////////////////////////////////////////////////////////////////// inline path temp_directory_path() { return detail::temp_directory_path(); } inline path temp_directory_path(std::error_code& ec) { return detail::temp_directory_path(&ec); } //////////////////////////////////////////////////////////////////////////// inline path unique_path(const path& model="%%%%-%%%%-%%%%-%%%%") { return detail::unique_path(model); } inline path unique_path(const path& model, std::error_code& ec) { return detail::unique_path(model, &ec); } }}} // namespace elib::fs
list<AtlasTexture*>* OpenTP::get_supported_images() { list<AtlasTexture*> *supported_images = new list<AtlasTexture*>; path cwd = current_path(); string _path = ""; if(exists(cwd / this->texture_directory)) { _path = (cwd / this->texture_directory).string(); } else if(exists(this->texture_directory)) { _path = path(this->texture_directory).string(); } else { cerr << "Error: Unknown path: " << this->texture_directory << endl; } directory_iterator iterator(_path); for(; iterator != boost::filesystem::directory_iterator(); ++iterator) { string filename = iterator->path().filename().string(); path _tmp_path = path(_path); _tmp_path /= filename; // TODO: improve this statement if(!(extension(_tmp_path) == ".png" || extension(_tmp_path) == ".gif")) { if(verbose) { cout << "Unknown extension: " << extension(_tmp_path) << endl; } continue; } Image *image = Image::from_file(_tmp_path.string()); int width = image->get_width(); int height = image->get_height(); delete image; // if image is bigger than atlas, continue if(width > this->atlas_width || height > this->atlas_height) { if(!be_quiet || verbose) { cout << "opentp: " << filename << " (" << width << "x" << height << ") is too big (atlas size is " << this->atlas_width << "x" << atlas_height << ")" << endl; } continue; } supported_images->push_back(new AtlasTexture(filename, _tmp_path, width, height)); if(verbose) { cout << "found texture: " << filename << " (" << width << "x" << height << ")" << endl; } } return supported_images; }
~current_path_saver() { current_path(cwd_); }
// Returns a file path which is where the engine's executable is located string FileSystem::GetWorkingDirectory() { return current_path().generic_string() + "/"; }
int builtin_directory(Environment &env, const std::vector<std::string> &tokens, const fdmask &fds) { // directory [-q] // directory path // for relative names, uses {DirectoryPath} (if set) rather than . // set DirectoryPath ":,{MPW},{MPW}Projects:" /* * Parameters: * ---------- * directory * Sets the default directory to directory. If you specify directory * as a leafname (that is, the final portion of a full pathname), the * MPW Shell searches for the directory in the current directory path * (for example, searching "{MPW}Examples:" for CExamples). However, if * the MPW Shell fails to find the directory in the current directory * path, it searches the directories listed in the {DirectoryPath} MPW * Shell variable, which contains a list of directories to be searched * in order of precedence. The last example illustrates how to do this. * * Options: * ------- * -q * Inhibits quoting the directory pathname written to standard * output. This option applies only if you omit the directory * parameter Normally the MPW Shell quotes the current default * directory name if it contains spaces or other special characters * * Status: * ------ * Directory can return the following status codes: * * 0 no errors * 1 directory not found; command aborted; or parameter error * */ //io_helper io(fds); bool q = false; bool error = false; std::vector<std::string> argv = getopt(tokens, [&](char c){ switch(tolower(c)) { case 'q': q = true; break; default: fdprintf(stderr, "### Directory - \"-%c\" is not an option.\n", c); error = true; break; } }); if (error) { fdputs("# Usage - Directory [-q | directory]\n", stderr); return 1; } if (argv.size() > 1) { fdputs("### Directory - Too many parameters were specified.\n", stderr); fdputs("# Usage - Directory [-q | directory]\n", stderr); return 1; } if (argv.size() == 1) { //cd if (q) { fdputs("### Directory - Conflicting options or parameters were specified.\n", stderr); return 1; } // todo -- if relative path does not exist, check {DirectoryPath} fs::path path = ToolBox::MacToUnix(argv.front()); std::error_code ec; current_path(path, ec); if (ec) { fdputs("### Directory - Unable to set current directory.\n", stderr); fdprintf(stderr, "# %s\n", ec.message().c_str()); return 1; } } else { // pwd std::error_code ec; fs::path path = fs::current_path(ec); if (ec) { fdputs("### Directory - Unable to get current directory.\n", stderr); fdprintf(stderr, "# %s\n", ec.message().c_str()); return 1; } // todo -- pathname translation? std::string s = path; if (!q) s = quote(std::move(s)); fdprintf(stdout, "%s\n", s.c_str()); } return 0; }