ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

filesbasehandler.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "backends/networking/sdl_net/handlers/filesbasehandler.h"
00024 #include "backends/saves/default/default-saves.h"
00025 #include "common/config-manager.h"
00026 #include "common/system.h"
00027 
00028 namespace Networking {
00029 
00030 FilesBaseHandler::FilesBaseHandler() {}
00031 
00032 FilesBaseHandler::~FilesBaseHandler() {}
00033 
00034 Common::String FilesBaseHandler::parentPath(Common::String path) {
00035     if (path.size() && (path.lastChar() == '/' || path.lastChar() == '\\')) path.deleteLastChar();
00036     if (!path.empty()) {
00037         for (int i = path.size() - 1; i >= 0; --i)
00038             if (i == 0 || path[i] == '/' || path[i] == '\\') {
00039                 path.erase(i);
00040                 break;
00041             }
00042     }
00043     if (path.size() && path.lastChar() != '/' && path.lastChar() != '\\')
00044         path += '/';
00045     return path;
00046 }
00047 
00048 bool FilesBaseHandler::transformPath(Common::String &path, Common::String &prefixToRemove, Common::String &prefixToAdd, bool isDirectory) {
00049     // <path> is not empty, but could lack the trailing slash
00050     if (isDirectory && path.lastChar() != '/' && path.lastChar() != '\\')
00051         path += '/';
00052 
00053     if (path.hasPrefix("/root") && ConfMan.hasKey("rootpath", "cloud")) {
00054         prefixToAdd = "/root/";
00055         prefixToRemove = ConfMan.get("rootpath", "cloud");
00056         if (prefixToRemove.size() && prefixToRemove.lastChar() != '/' && prefixToRemove.lastChar() != '\\')
00057             prefixToRemove += '/';
00058         if (prefixToRemove == "/") prefixToRemove = "";
00059         path.erase(0, 5);
00060         if (path.size() && (path[0] == '/' || path[0] == '\\'))
00061             path.deleteChar(0); // if that was "/root/ab/c", it becomes "/ab/c", but we need "ab/c"
00062         path = prefixToRemove + path;
00063         if (path == "")
00064             path = "/"; // absolute root is '/'
00065         return true;
00066     }
00067 
00068     if (path.hasPrefix("/saves")) {
00069         prefixToAdd = "/saves/";
00070 
00071         // determine savepath (prefix to remove)
00072 #ifdef USE_LIBCURL
00073         DefaultSaveFileManager *manager = dynamic_cast<DefaultSaveFileManager *>(g_system->getSavefileManager());
00074         prefixToRemove = (manager ? manager->concatWithSavesPath("") : ConfMan.get("savepath"));
00075 #else
00076         prefixToRemove = ConfMan.get("savepath");
00077 #endif
00078         if (prefixToRemove.size() && prefixToRemove.lastChar() != '/' && prefixToRemove.lastChar() != '\\')
00079             prefixToRemove += '/';
00080 
00081         path.erase(0, 6);
00082         if (path.size() && (path[0] == '/' || path[0] == '\\'))
00083             path.deleteChar(0);
00084         path = prefixToRemove + path;
00085         return true;
00086     }
00087 
00088     return false;
00089 }
00090 
00091 } // End of namespace Networking


Generated on Sat Feb 16 2019 05:00:50 for ResidualVM by doxygen 1.7.1
curved edge   curved edge