From a08d4818be7263aba4333367cacbf03d5596bd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 18 Nov 2013 14:05:26 +0100 Subject: [PATCH] Move PathBrowser to native --- CMakeLists.txt | 2 + UI/MainScreen.cpp | 97 +---------------------------------------------- native | 2 +- 3 files changed, 4 insertions(+), 97 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c54693d327..1e495448d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -525,6 +525,8 @@ add_library(native STATIC native/file/file_util.h native/file/ini_file.cpp native/file/ini_file.h + native/file/path.cpp + native/file/path.h native/file/vfs.h native/file/zip_read.cpp native/file/zip_read.h diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 6bb99d9382..ca269f2aa1 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -17,6 +17,7 @@ #include "base/colorutil.h" #include "base/timeutil.h" +#include "file/path.h" #include "gfx_es2/draw_buffer.h" #include "math/curves.h" #include "ui/ui_context.h" @@ -202,102 +203,6 @@ void GameButton::Draw(UIContext &dc) { dc.RebindTexture(); } -// Abstraction above path that lets you navigate easily. -// "/" is a special path that means the root of the file system. On Windows, -// listing this will yield drives. -class PathBrowser { -public: - PathBrowser() {} - PathBrowser(std::string path) { SetPath(path); } - - void SetPath(const std::string &path); - void GetListing(std::vector &fileInfo, const char *filter = 0); - void Navigate(const std::string &path); - - std::string GetPath() { - if (path_ != "/") - return path_; - else - return ""; - } - std::string GetFriendlyPath() { - std::string str = GetPath(); - /* -#ifdef ANDROID - if (!memcmp(str.c_str(), g_Config.memCardDirectory.c_str(), g_Config.memCardDirectory.size())) - { - str = str.substr(g_Config.memCardDirectory.size()); - } -#endif*/ - return str; - } - - std::string path_; -}; - -// Normalize slashes. -void PathBrowser::SetPath(const std::string &path) { - if (path[0] == '!') { - path_ = path; - return; - } - path_ = path; - for (size_t i = 0; i < path_.size(); i++) { - if (path_[i] == '\\') path_[i] = '/'; - } - if (!path_.size() || (path_[path_.size() - 1] != '/')) - path_ += "/"; -} - -void PathBrowser::GetListing(std::vector &fileInfo, const char *filter) { -#ifdef _WIN32 - if (path_ == "/") { - // Special path that means root of file system. - std::vector drives = getWindowsDrives(); - for (auto drive = drives.begin(); drive != drives.end(); ++drive) { - FileInfo fake; - fake.fullName = *drive; - fake.name = *drive; - fake.isDirectory = true; - fake.exists = true; - fake.size = 0; - fake.isWritable = false; - fileInfo.push_back(fake); - } - } -#endif - - getFilesInDir(path_.c_str(), &fileInfo, filter); -} - -// TODO: Support paths like "../../hello" -void PathBrowser::Navigate(const std::string &path) { - if (path[0] == '!') - return; - - if (path == ".") - return; - if (path == "..") { - // Upwards. - // Check for windows drives. - if (path_.size() == 3 && path_[1] == ':') { - path_ = "/"; - } else { - size_t slash = path_.rfind('/', path_.size() - 2); - if (slash != std::string::npos) - path_ = path_.substr(0, slash + 1); - } - } - else { - if (path[1] == ':' && path_ == "/") - path_ = path; - else - path_ = path_ + path; - if (path_[path_.size() - 1] != '/') - path_ += "/"; - } -} - class GameBrowser : public UI::LinearLayout { public: GameBrowser(std::string path, bool allowBrowsing, bool *gridStyle_, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams = 0); diff --git a/native b/native index d48c3570fe..c60ea2f96c 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit d48c3570feb572cf9e33ac20e8207f0238060662 +Subproject commit c60ea2f96c8a17fde20c2b580111d159fa0cfa5f