bool File::move_file_nt(const wstring& file_path, const wstring& new_path, DWORD flags) { ArclitePrivateInfo* system_functions = Far::get_system_functions(); if (system_functions) return system_functions->MoveFileEx(long_path(file_path).c_str(), long_path(new_path).c_str(), flags) != 0; else return MoveFileExW(long_path(file_path).c_str(), long_path(new_path).c_str(), flags) != 0; }
void FilePanel::scan_dir( const std::string& root_path, const std::string& rel_path, std::list<PanelItemData>& pid_list, FileListProgress& progress ) { std::string path = add_trailing_slash( root_path ) + rel_path; bool more = true; WIN32_FIND_DATAW find_data; HANDLE h_find = FindFirstFileW( long_path( add_trailing_slash( path ) + L"*" ).data( ), &find_data ); try { if ( h_find == INVALID_HANDLE_VALUE ) { // special case: symlink that denies access to directory, try real path if ( GetLastError( ) == ERROR_ACCESS_DENIED ) { DWORD attr = GetFileAttributesW( long_path( path ).data( ) ); CHECK_SYS( attr != INVALID_FILE_ATTRIBUTES ); if ( attr & FILE_ATTRIBUTE_REPARSE_POINT ) { h_find = FindFirstFileW( long_path( add_trailing_slash( get_real_path( path ) ) + L"*" ).data( ), &find_data ); } else CHECK_SYS( false ); } } if ( h_find == INVALID_HANDLE_VALUE ) { CHECK_SYS( GetLastError( ) == ERROR_NO_MORE_FILES ); more = false; } } catch ( ... ) { if ( flat_mode ) { more = false; } else throw; } ALLOC_RSRC( ; );
bool File::create_dir_nt(const wstring& file_path) { ArclitePrivateInfo* system_functions = Far::get_system_functions(); if (system_functions) return system_functions->CreateDirectory(long_path(file_path).c_str(), nullptr) != 0; else return CreateDirectoryW(long_path(file_path).c_str(), nullptr) != 0; }
bool File::remove_dir_nt(const wstring& file_path) { ArclitePrivateInfo* system_functions = Far::get_system_functions(); if (system_functions) return system_functions->RemoveDirectory(long_path(file_path).c_str()) != 0; else return RemoveDirectoryW(long_path(file_path).c_str()) != 0; }
bool File::set_attr_nt(const wstring& file_path, DWORD attr) { ArclitePrivateInfo* system_functions = Far::get_system_functions(); if (system_functions) return system_functions->SetFileAttributes(long_path(file_path).c_str(), attr) != 0; else return SetFileAttributesW(long_path(file_path).c_str(), attr) != 0; }
bool File::delete_file_nt(const wstring& file_path) { ArclitePrivateInfo* system_functions = Far::get_system_functions(); if (system_functions) return system_functions->DeleteFile(long_path(file_path).c_str()) != 0; else return DeleteFileW(long_path(file_path).c_str()) != 0; }
bool File::exists(const wstring& file_path) { ArclitePrivateInfo* system_functions = Far::get_system_functions(); if (system_functions) return system_functions->GetFileAttributes(long_path(file_path).c_str()) != INVALID_FILE_ATTRIBUTES; else return GetFileAttributesW(long_path(file_path).c_str()) != INVALID_FILE_ATTRIBUTES; }
bool File::open_nt(const wstring& file_path, DWORD desired_access, DWORD share_mode, DWORD creation_disposition, DWORD flags_and_attributes) { close(); this->file_path = file_path; ArclitePrivateInfo* system_functions = Far::get_system_functions(); if (system_functions) h_file = system_functions->CreateFile(long_path(file_path).c_str(), desired_access, share_mode, nullptr, creation_disposition, flags_and_attributes, nullptr); else h_file = CreateFileW(long_path(file_path).c_str(), desired_access, share_mode, nullptr, creation_disposition, flags_and_attributes, nullptr); return h_file != INVALID_HANDLE_VALUE; }
FindData get_find_data(const wstring& path) { FindData find_data; HANDLE h_find = FindFirstFileW(long_path(path).c_str(), &find_data); CHECK_SYS(h_find != INVALID_HANDLE_VALUE); FindClose(h_find); return find_data; }
bool File::get_find_data_nt(const wstring& file_path, FindData& find_data) { HANDLE h_find = FindFirstFileW(long_path(file_path).c_str(), &find_data); if (h_find != INVALID_HANDLE_VALUE) { FindClose(h_find); return true; } else return false; }
bool FileEnum::next_nt(bool& more) { while (true) { if (h_find == INVALID_HANDLE_VALUE) { h_find = FindFirstFileW(long_path(file_mask).c_str(), &find_data); if (h_find == INVALID_HANDLE_VALUE) return false; } else { if (!FindNextFileW(h_find, &find_data)) { if (GetLastError() == ERROR_NO_MORE_FILES) { more = false; return true; } return false; } } if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if ((find_data.cFileName[0] == L'.') && ((find_data.cFileName[1] == 0) || ((find_data.cFileName[1] == L'.') && (find_data.cFileName[2] == 0)))) continue; } more = true; return true; } }
bool file_exists(const wstring& file_path) { return GetFileAttributesW(long_path(get_full_path_name(file_path)).c_str()) != INVALID_FILE_ATTRIBUTES; }
bool File::open_nt(const wstring& file_path, DWORD desired_access, DWORD share_mode, DWORD creation_disposition, DWORD flags_and_attributes) { close(); h_file = CreateFileW(long_path(file_path).c_str(), desired_access, share_mode, nullptr, creation_disposition, flags_and_attributes, nullptr); return h_file != INVALID_HANDLE_VALUE; }
int main() try { adobe::forest<char> forest; adobe::forest<char>::iterator a(forest.insert(forest.begin(), 'a')); a = adobe::trailing_of(a); adobe::forest<char>::iterator b(forest.insert(a, 'b')); adobe::forest<char>::iterator c(forest.insert(a, 'c')); b = adobe::trailing_of(b); forest.insert(b, 'd'); forest.insert(b, 'e'); forest.insert(b, 'f'); forest.insert(adobe::trailing_of(forest.insert(adobe::trailing_of(c), 'g')), 'h'); output(depth_range(forest)); forest_map<char>::type index_map; { adobe::forest<char>::const_preorder_iterator iter(forest.begin()); adobe::forest<char>::const_preorder_iterator last(forest.end()); for (; iter != last; ++iter) { std::cout << *iter << " has_next_sibling : " << std::boolalpha << has_next_sibling(iter.base()) << std::endl; } } build_index_map<char>(index_map, adobe::bitpath_t(), forest.begin()); { forest_map<char>::type::const_iterator iter(index_map.begin()); forest_map<char>::type::const_iterator last(index_map.end()); for (; iter != last; ++iter) { std::cout << *iter->second << " has index : " << iter->first << std::endl; } } { forest_map<char>::type::const_iterator iter(index_map.begin()); forest_map<char>::type::const_iterator last(index_map.end()); for (; iter != last; ++iter) { adobe::forest<char>::iterator parent(find_index_parent<char>(index_map, iter->first)); if (parent == adobe::forest<char>::iterator()) { std::cout << *iter->second << " has no parent." << std::endl; } else { std::cout << *iter->second << " has parent : " << *parent << std::endl; } } } { adobe::forest<char>::preorder_iterator iter(forest.begin()); adobe::forest<char>::preorder_iterator last(forest.end()); for (; iter != last; ++iter) { std::cout << *iter << " has index : " << iterator_to_index(forest, iter.base()) << std::endl; } } { forest_map<char>::type::const_iterator iter(index_map.begin()); forest_map<char>::type::const_iterator last(index_map.end()); for (; iter != last; ++iter) { std::cout << "index " << iter->first << " has value " << *index_to_iterator(forest, iter->first) << std::endl; } } { forest_map<char>::type::const_iterator iter(index_map.begin()); forest_map<char>::type::const_iterator last(index_map.end()); for (; iter != last; ++iter) { adobe::bitpath_t path(iter->first); adobe::vector<unsigned char> exported(path.portable()); adobe::bitpath_t imported(exported); std::cout << "path: " << path << ", round-trip: " << imported << std::endl; } } { adobe::bitpath_t small_path; small_path.push(1); small_path.push(0); small_path.push(1); small_path.push(1); small_path.push(0); adobe::bitpath_t med_path(small_path); med_path.push(0); med_path.push(1); med_path.push(1); med_path.push(0); med_path.push(1); adobe::bitpath_t long_path(med_path); long_path.push(1); long_path.push(0); long_path.push(0); long_path.push(1); long_path.push(1); std::cout << "small_path: " << small_path << std::endl; std::cout << " med_path: " << med_path << std::endl; std::cout << " long_path: " << long_path << std::endl; std::cout << "pass_through(invalid, invalid): " << std::boolalpha << passes_through(adobe::nbitpath(), adobe::nbitpath()) << std::endl; std::cout << "pass_through(invalid, small): " << std::boolalpha << passes_through(adobe::nbitpath(), small_path) << std::endl; std::cout << "pass_through(invalid, med): " << std::boolalpha << passes_through(adobe::nbitpath(), med_path) << std::endl; std::cout << "pass_through(invalid, long): " << std::boolalpha << passes_through(adobe::nbitpath(), long_path) << std::endl; std::cout << "pass_through(small, invalid): " << std::boolalpha << passes_through(small_path, adobe::nbitpath()) << std::endl; std::cout << "pass_through(small, small): " << std::boolalpha << passes_through(small_path, small_path) << std::endl; std::cout << "pass_through(small, med): " << std::boolalpha << passes_through(small_path, med_path) << std::endl; std::cout << "pass_through(small, long): " << std::boolalpha << passes_through(small_path, long_path) << std::endl; std::cout << "pass_through(med, invalid): " << std::boolalpha << passes_through(med_path, adobe::nbitpath()) << std::endl; std::cout << "pass_through(med, small): " << std::boolalpha << passes_through(med_path, small_path) << std::endl; std::cout << "pass_through(med, med): " << std::boolalpha << passes_through(med_path, med_path) << std::endl; std::cout << "pass_through(med, long): " << std::boolalpha << passes_through(med_path, long_path) << std::endl; std::cout << "pass_through(long, invalid): " << std::boolalpha << passes_through(long_path, adobe::nbitpath()) << std::endl; std::cout << "pass_through(long, small): " << std::boolalpha << passes_through(long_path, small_path) << std::endl; std::cout << "pass_through(long, med): " << std::boolalpha << passes_through(long_path, med_path) << std::endl; std::cout << "pass_through(long, long): " << std::boolalpha << passes_through(long_path, long_path) << std::endl; } return 0; } catch(const std::exception& error) { std::cerr << "Exception: " << error.what() << std::endl; return 1; } catch(...) { std::cerr << "Exception: unknown" << std::endl; return 1; }