Removed the difference of the separator for Linux and Windows.

Removed extra "/" of the filename (e.g. "E://") of the hashed file when sharing a whole drive.
Recompile of the gui needed.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4200 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-05-15 12:42:55 +00:00
parent 00c1bfcf54
commit 72d9f352e3
12 changed files with 66 additions and 65 deletions

View File

@ -876,7 +876,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
cd.cid.type = rscc->cachetypeid;
cd.cid.subid = rscc->cachesubid;
cd.path = rscc->path;
cd.path = RsDirUtil::convertPathToUnix(rscc->path);
cd.name = rscc->name;
cd.hash = rscc->hash;
cd.size = rscc->size;

View File

@ -868,7 +868,7 @@ void FileIndexMonitor::hashFiles(const std::vector<DirContentToHash>& to_hash)
cb->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, tmpout.str()) ;
std::string real_path(to_hash[i].realpath + "/" + fe.name) ;
std::string real_path = RsDirUtil::makePath(to_hash[i].realpath, fe.name);
// 1st look into the hash cache if this file already exists.
//

View File

@ -1489,7 +1489,7 @@ bool ftController::setDownloadDirectory(std::string path)
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
mDownloadPath = path;
mDownloadPath = RsDirUtil::convertPathToUnix(path);
#ifdef CONTROL_DEBUG
std::cerr << "ftController::setDownloadDirectory() Okay!";
std::cerr << std::endl;
@ -1512,6 +1512,8 @@ bool ftController::setPartialsDirectory(std::string path)
{
RsStackMutex stack(ctrlMutex);
path = RsDirUtil::convertPathToUnix(path);
if (!path.find(mDownloadPath)) {
return false;
}

View File

@ -336,7 +336,7 @@ bool ftFiMonitor::loadList(std::list<RsItem *>& load)
/* ensure that it exists? */
SharedDirInfo info ;
info.filename = fi->file.path;
info.filename = RsDirUtil::convertPathToUnix(fi->file.path);
info.virtualname = fi->file.name;
info.shareflags = fi->flags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE) ;

View File

@ -593,16 +593,19 @@ bool ftServer::setSharedDirectories(std::list<SharedDirInfo> &dirs)
bool ftServer::addSharedDirectory(const SharedDirInfo& dir)
{
SharedDirInfo _dir = dir;
_dir.filename = RsDirUtil::convertPathToUnix(_dir.filename);
std::list<SharedDirInfo> dirList;
mFiMon->getSharedDirectories(dirList);
// check that the directory is not already in the list.
for(std::list<SharedDirInfo>::const_iterator it(dirList.begin());it!=dirList.end();++it)
if((*it).filename == dir.filename)
if((*it).filename == _dir.filename)
return false ;
// ok then, add the shared directory.
dirList.push_back(dir);
dirList.push_back(_dir);
mFiMon->setSharedDirectories(dirList);
return true;
@ -617,6 +620,8 @@ bool ftServer::updateShareFlags(const SharedDirInfo& info)
bool ftServer::removeSharedDirectory(std::string dir)
{
dir = RsDirUtil::convertPathToUnix(dir);
std::list<SharedDirInfo> dirList;
std::list<SharedDirInfo>::iterator it;

View File

@ -209,7 +209,7 @@ bool AuthGPGimpl::InitAuth ()
#ifdef WINDOWS_SYS
if (RsInit::isPortable ()) {
// set home dir of gpg to configdir\gnupg
HomeDir = RsInit::RsConfigDirectory() + RsInit::dirSeperator() + "gnupg";
HomeDir = RsInit::RsConfigDirectory() + "/" + "gnupg";
if (!RsDirUtil::checkCreateDirectory(HomeDir)) {
std::cerr << "Error creating gnupg directory" << std::endl;

View File

@ -65,12 +65,6 @@ class RsInit
*/
static int InitRetroShare(int argc, char **argv, bool strictCheck=true);
/*!
* This return directory seperator for different platforms, not an issue anymore as C library can distinguish
* @returns directory of seperator used for different platforms
*
*/
static char dirSeperator();
static bool isPortable();
static bool isWindowsXP();

View File

@ -71,9 +71,6 @@ class accountId
class RsInitConfig
{
public:
/* OS Specifics */
static char dirSeperator;
/* Directories (SetupBaseDir) */
static std::string basedir;
static std::string homePath;
@ -164,9 +161,6 @@ bool RsInitConfig::autoLogin; /* autoLogin allowed */
bool RsInitConfig::startMinimised; /* Icon or Full Window */
std::string RsInitConfig::RetroShareLink;
/* Win/Unix Differences */
char RsInitConfig::dirSeperator;
/* Directories */
std::string RsInitConfig::basedir;
std::string RsInitConfig::homePath;
@ -224,10 +218,8 @@ static std::string toLowerCase(const std::string& s)
void RsInit::InitRsConfig()
{
#ifndef WINDOWS_SYS
RsInitConfig::dirSeperator = '/'; // For unix.
RsInitConfig::lockHandle = -1;
#else
RsInitConfig::dirSeperator = '\\'; // For windows.
RsInitConfig::lockHandle = NULL;
#endif
@ -967,7 +959,7 @@ bool getAvailableAccounts(std::list<accountId> &ids)
for(it = directories.begin(); it != directories.end(); it++)
{
std::string accountdir = RsInitConfig::basedir + RsInitConfig::dirSeperator + *it;
std::string accountdir = RsInitConfig::basedir + "/" + *it;
#ifdef GPG_DEBUG
std::cerr << "getAvailableAccounts() Checking: " << *it << std::endl;
#endif
@ -990,14 +982,14 @@ static bool checkAccount(std::string accountdir, accountId &id)
{
/* check if the cert/key file exists */
std::string subdir1 = accountdir + RsInitConfig::dirSeperator;
std::string subdir1 = accountdir + "/";
std::string subdir2 = subdir1;
subdir1 += configKeyDir;
subdir2 += configCertDir;
// Create the filename.
std::string basename = accountdir + RsInitConfig::dirSeperator;
basename += configKeyDir + RsInitConfig::dirSeperator;
std::string basename = accountdir + "/";
basename += configKeyDir + "/";
basename += "user";
std::string cert_name = basename + "_cert.pem";
@ -1079,7 +1071,7 @@ int RsInit::GetPGPLoginDetails(std::string id, std::string &name, std::stri
*/
int RsInit::LockConfigDirectory(const std::string& accountDir, std::string& lockFilePath)
{
const std::string lockFile = accountDir + RsInitConfig::dirSeperator + "lock";
const std::string lockFile = accountDir + "/" + "lock";
lockFilePath = lockFile;
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
@ -1224,12 +1216,12 @@ bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std
// Temporary Directory for creating files....
std::string tmpdir = "TMPCFG";
std::string tmpbase = RsInitConfig::basedir + RsInitConfig::dirSeperator + tmpdir + RsInitConfig::dirSeperator;
std::string tmpbase = RsInitConfig::basedir + "/" + tmpdir + "/";
RsInit::setupAccount(tmpbase);
/* create directory structure */
std::string basename = tmpbase + configKeyDir + RsInitConfig::dirSeperator;
std::string basename = tmpbase + configKeyDir + "/";
basename += "user";
std::string key_name = basename + "_pk.pem";
@ -1325,7 +1317,7 @@ bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std
}
/* Move directory to correct id */
std::string finalbase = RsInitConfig::basedir + RsInitConfig::dirSeperator + sslId + RsInitConfig::dirSeperator;
std::string finalbase = RsInitConfig::basedir + "/" + sslId + "/";
/* Rename Directory */
std::cerr << "Mv Config Dir from: " << tmpbase << " to: " << finalbase;
@ -1356,16 +1348,16 @@ bool RsInit::setupAccount(std::string accountdir)
{
/* actual config directory isd */
std::string subdir1 = accountdir + RsInitConfig::dirSeperator;
std::string subdir1 = accountdir + "/";
std::string subdir2 = subdir1;
subdir1 += configKeyDir;
subdir2 += configCertDir;
std::string subdir3 = accountdir + RsInitConfig::dirSeperator;
std::string subdir3 = accountdir + "/";
subdir3 += "cache";
std::string subdir4 = subdir3 + RsInitConfig::dirSeperator;
std::string subdir5 = subdir3 + RsInitConfig::dirSeperator;
std::string subdir4 = subdir3 + "/";
std::string subdir5 = subdir3 + "/";
subdir4 += "local";
subdir5 += "remote";
@ -1417,15 +1409,15 @@ bool RsInit::LoadPassword(std::string id, std::string inPwd)
/* select configDir */
RsInitConfig::preferedId = id;
RsInitConfig::configDir = RsInitConfig::basedir + RsInitConfig::dirSeperator + id;
RsInitConfig::configDir = RsInitConfig::basedir + "/" + id;
RsInitConfig::passwd = inPwd;
// if(inPwd != "")
// RsInitConfig::havePasswd = true;
// Create the filename.
std::string basename = RsInitConfig::configDir + RsInitConfig::dirSeperator;
basename += configKeyDir + RsInitConfig::dirSeperator;
std::string basename = RsInitConfig::configDir + "/";
basename += configKeyDir + "/";
basename += "user";
RsInitConfig::load_key = basename + "_pk.pem";
@ -1523,7 +1515,7 @@ bool RsInit::get_configinit(std::string dir, std::string &id)
// have a config directories.
// Check for config file.
std::string initfile = dir + RsInitConfig::dirSeperator;
std::string initfile = dir + "/";
initfile += configInitFile;
// open and read in the lines.
@ -1553,7 +1545,7 @@ bool RsInit::get_configinit(std::string dir, std::string &id)
bool RsInit::create_configinit(std::string dir, std::string id)
{
// Check for config file.
std::string initfile = dir + RsInitConfig::dirSeperator;
std::string initfile = dir + "/";
initfile += configInitFile;
// open and read in the lines.
@ -1573,8 +1565,6 @@ bool RsInit::create_configinit(std::string dir, std::string id)
return false;
}
std::string make_path_unix(std::string path);
std::string RsInit::getHomePath()
{
std::string home;
@ -1610,29 +1600,14 @@ std::string RsInit::getHomePath()
std::cerr << out.str();
// convert to FLTK desired format.
home = make_path_unix(home);
home = RsDirUtil::convertPathToUnix(home);
#endif
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
return home;
}
std::string make_path_unix(std::string path)
{
for(unsigned int i = 0; i < path.length(); i++)
{
if (path[i] == '\\')
path[i] = '/';
}
return path;
}
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
char RsInit::dirSeperator()
{
return RsInitConfig::dirSeperator;
}
bool RsInit::isPortable()
{
#ifdef WINDOWS_SYS
@ -1652,7 +1627,7 @@ bool RsInit::isWindowsXP()
}
std::string RsInit::RsConfigKeysDirectory()
{
return RsInitConfig::basedir + RsInitConfig::dirSeperator + RsInitConfig::preferedId + RsInitConfig::dirSeperator + configKeyDir ;
return RsInitConfig::basedir + "/" + RsInitConfig::preferedId + "/" + configKeyDir ;
}
std::string RsInit::RsConfigDirectory()
{
@ -1661,7 +1636,7 @@ std::string RsInit::RsConfigDirectory()
std::string RsInit::RsProfileConfigDirectory()
{
std::string dir = RsInitConfig::basedir + RsInitConfig::dirSeperator + RsInitConfig::preferedId;
std::string dir = RsInitConfig::basedir + "/" + RsInitConfig::preferedId;
//std::cerr << "RsInit::RsProfileConfigDirectory() returning : " << dir << std::endl;
return dir;
}
@ -1812,8 +1787,8 @@ int RsServer::StartupRetroShare()
std::cerr << "set the debugging to crashMode." << std::endl;
if ((!RsInitConfig::haveLogFile) && (!RsInitConfig::outStderr))
{
std::string crashfile = RsInitConfig::basedir + RsInitConfig::dirSeperator;
crashfile += ownId + RsInitConfig::dirSeperator + configLogFileName;
std::string crashfile = RsInitConfig::basedir + "/";
crashfile += ownId + "/" + configLogFileName;
setDebugCrashMode(crashfile.c_str());
}
@ -1886,7 +1861,7 @@ int RsServer::StartupRetroShare()
{
std::cerr << "DHT bootstrap file not in ConfigDir: " << bootstrapfile << std::endl;
std::string installfile = RsInit::getRetroshareDataDirectory();
installfile += RsInitConfig::dirSeperator;
installfile += "/";
installfile += BITDHT_BOOTSTRAP_FILENAME;
std::cerr << "Checking for Installation DHT bootstrap file " << installfile << std::endl;
@ -2264,7 +2239,7 @@ int RsServer::StartupRetroShare()
#endif // MINIMAL_LIBRS
// load up the help page
std::string helppage = RsInitConfig::basedir + RsInitConfig::dirSeperator;
std::string helppage = RsInitConfig::basedir + "/";
helppage += configHelpName;
/* Startup this thread! */

View File

@ -720,11 +720,11 @@ bool RsLoginHandler::getSSLPasswdFromGPGFile(const std::string& ssl_id,std::stri
std::string RsLoginHandler::getSSLPasswdFileName(const std::string& ssl_id)
{
return RsInit::RsConfigKeysDirectory() + RsInit::dirSeperator() + "ssl_passphrase.pgp";
return RsInit::RsConfigKeysDirectory() + "/" + "ssl_passphrase.pgp";
}
std::string RsLoginHandler::getAutologinFileName(const std::string& ssl_id)
{
return RsInit::RsConfigKeysDirectory() + RsInit::dirSeperator() + "help.dta" ;
return RsInit::RsConfigKeysDirectory() + "/" + "help.dta" ;
}

View File

@ -14,7 +14,7 @@ FolderIterator::FolderIterator(const std::string& folderName)
return;
}
utf16Name += L"\\*.*";
utf16Name += L"/*.*";
handle = FindFirstFileW(utf16Name.c_str(), &fileInfo);
validity = handle != INVALID_HANDLE_VALUE;

View File

@ -743,6 +743,28 @@ FILE *RsDirUtil::rs_fopen(const char* filename, const char* mode)
#endif
}
std::string RsDirUtil::convertPathToUnix(std::string path)
{
for (unsigned int i = 0; i < path.length(); i++)
{
if (path[i] == '\\')
path[i] = '/';
}
return path;
}
std::string RsDirUtil::makePath(const std::string &path1, const std::string &path2)
{
std::string path = path1;
if (path.empty() == false && *path.rbegin() != '/') {
path += "/";
}
path += path2;
return path;
}
#if 0 // NOT ENABLED YET!
/************************* WIDE STRING ***************************/
/************************* WIDE STRING ***************************/

View File

@ -92,6 +92,9 @@ bool getWideFileHash(std::wstring filepath,
std::string &hash, uint64_t &size);
FILE *rs_fopen(const char* filename, const char* mode);
std::string convertPathToUnix(std::string path);
std::string makePath(const std::string &path1, const std::string &path2);
}