mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Added Installation of BitDHT bootstrap file.
* new DataDirectory Function in rsinit.cc * new copyFile() and checkFile() functions in rsdirutils. * bdboot.txt is checked for and copied over if missing. NB: This has been tested under OSX, but Linux / Windows need checking. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3713 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
dd19278d58
commit
634dbca14f
@ -129,6 +129,8 @@ class RsInit
|
||||
static void setAutoLogin(bool autoLogin);
|
||||
static bool RsClearAutoLogin() ;
|
||||
|
||||
/* used for static install data */
|
||||
static std::string getRetroshareDataDirectory();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -789,6 +789,98 @@ void RsInit::setupBaseDir()
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************
|
||||
* This Directory is used to store data and "template" file that Retroshare requires.
|
||||
* These files will either be copied into Retroshare's configuration directory,
|
||||
* if they are to be modified. Or used directly, if read-only.
|
||||
*
|
||||
* This will initially be used for the DHT bootstrap file.
|
||||
*
|
||||
* Please modify the code below to suit your platform!
|
||||
*
|
||||
* WINDOWS:
|
||||
* WINDOWS PORTABLE:
|
||||
* Linux:
|
||||
* OSX:
|
||||
|
||||
***********/
|
||||
|
||||
#ifdef __APPLE__
|
||||
/* needs CoreFoundation Framework */
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
//#include <CFURL.h>
|
||||
//#include <CFBundle.h>
|
||||
#endif
|
||||
|
||||
std::string RsInit::getRetroshareDataDirectory()
|
||||
{
|
||||
std::string dataDirectory;
|
||||
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
|
||||
#ifdef __APPLE__
|
||||
/* For OSX, applications are Bundled in a directory...
|
||||
* need to get the path to the executable Bundle.
|
||||
*
|
||||
* Code nicely supplied by Qt!
|
||||
*/
|
||||
|
||||
CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
||||
CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
|
||||
kCFURLPOSIXPathStyle);
|
||||
const char *pathPtr = CFStringGetCStringPtr(macPath,
|
||||
CFStringGetSystemEncoding());
|
||||
dataDirectory = pathPtr;
|
||||
CFRelease(pluginRef);
|
||||
CFRelease(macPath);
|
||||
|
||||
dataDirectory += "/Contents/Resources";
|
||||
std::cerr << "getRetroshareDataDirectory() OSX: " << dataDirectory;
|
||||
|
||||
#else
|
||||
/* For Linux, we have a fixed standard data directory */
|
||||
dataDirectory = "/usr/share/Retroshare";
|
||||
std::cerr << "getRetroshareDataDirectory() Linux: " << dataDirectory;
|
||||
|
||||
#endif
|
||||
#else
|
||||
if (RsInitConfig::portable)
|
||||
{
|
||||
/* For Windows Portable, files must be in the data directory */
|
||||
dataDirectory = "Data";
|
||||
std::cerr << "getRetroshareDataDirectory() WINDOWS PORTABLE: " << dataDirectory;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* For Windows: environment variable APPDATA should be suitable */
|
||||
dataDirectory = getenv("APPDATA");
|
||||
dataDirectory += "\\RetroShare";
|
||||
|
||||
std::cerr << "getRetroshareDataDirectory() WINDOWS: " << dataDirectory;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
#endif
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
/* Make sure the directory exists, else return emptyString */
|
||||
if (!RsDirUtil::checkDirectory(dataDirectory))
|
||||
{
|
||||
std::cerr << "Data Directory not Found: " << dataDirectory << std::endl;
|
||||
dataDirectory = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Data Directory Found: " << dataDirectory << std::endl;
|
||||
}
|
||||
|
||||
return dataDirectory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* directories with valid certificates in the expected location */
|
||||
bool getAvailableAccounts(std::list<accountId> &ids)
|
||||
{
|
||||
@ -2233,12 +2325,48 @@ int RsServer::StartupRetroShare()
|
||||
rsUdpStack *mUdpStack = new rsUdpStack(tmpladdr);
|
||||
|
||||
#ifdef RS_USE_BITDHT
|
||||
|
||||
#define BITDHT_BOOTSTRAP_FILENAME "bdboot.txt"
|
||||
|
||||
|
||||
std::string bootstrapfile = RsInitConfig::configDir.c_str();
|
||||
if (bootstrapfile != "")
|
||||
{
|
||||
bootstrapfile += "/";
|
||||
}
|
||||
bootstrapfile += "bdboot.txt";
|
||||
bootstrapfile += BITDHT_BOOTSTRAP_FILENAME;
|
||||
|
||||
std::cerr << "Checking for DHT bootstrap file: " << bootstrapfile << std::endl;
|
||||
|
||||
/* check if bootstrap file exists...
|
||||
* if not... copy from dataDirectory
|
||||
*/
|
||||
|
||||
if (!RsDirUtil::checkFile(bootstrapfile))
|
||||
{
|
||||
std::cerr << "DHT bootstrap file not in ConfigDir: " << bootstrapfile << std::endl;
|
||||
std::string installfile = RsInit::getRetroshareDataDirectory();
|
||||
installfile += RsInitConfig::dirSeperator;
|
||||
installfile += BITDHT_BOOTSTRAP_FILENAME;
|
||||
|
||||
std::cerr << "Checking for Installation DHT bootstrap file " << installfile << std::endl;
|
||||
if ((installfile != "") && (RsDirUtil::checkFile(installfile)))
|
||||
{
|
||||
std::cerr << "Copying Installation DHT bootstrap file..." << std::endl;
|
||||
if (RsDirUtil::copyFile(installfile, bootstrapfile))
|
||||
{
|
||||
std::cerr << "Installed DHT bootstrap file in configDir" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed Installation DHT bootstrap file..." << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "No Installation DHT bootstrap file to copy" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
p3BitDht *mBitDht = new p3BitDht(ownId, mConnMgr,
|
||||
mUdpStack, bootstrapfile);
|
||||
|
@ -360,6 +360,100 @@ int RsDirUtil::breakupDirList(const std::string& path,
|
||||
}
|
||||
|
||||
|
||||
/**** Copied and Tweaked from ftcontroller ***/
|
||||
bool RsDirUtil::copyFile(const std::string& source,const std::string& dest)
|
||||
{
|
||||
#ifdef WINDOWS_SYS
|
||||
std::wstring sourceW;
|
||||
std::wstring destW;
|
||||
librs::util::ConvertUtf8ToUtf16(source,sourceW);
|
||||
librs::util::ConvertUtf8ToUtf16(dest,destW);
|
||||
|
||||
return (CopyFileW(sourceW.c_str(), destW.c_str(), FALSE) != 0);
|
||||
|
||||
#else
|
||||
FILE *in = fopen(source.c_str(),"rb") ;
|
||||
|
||||
if(in == NULL)
|
||||
{
|
||||
return false ;
|
||||
}
|
||||
|
||||
FILE *out = fopen(dest.c_str(),"wb") ;
|
||||
|
||||
if(out == NULL)
|
||||
{
|
||||
fclose (in);
|
||||
return false ;
|
||||
}
|
||||
|
||||
size_t s=0;
|
||||
size_t T=0;
|
||||
|
||||
static const int BUFF_SIZE = 10485760 ; // 10 MB buffer to speed things up.
|
||||
void *buffer = malloc(BUFF_SIZE) ;
|
||||
|
||||
bool bRet = true;
|
||||
|
||||
while( (s = fread(buffer,1,BUFF_SIZE,in)) > 0)
|
||||
{
|
||||
size_t t = fwrite(buffer,1,s,out) ;
|
||||
T += t ;
|
||||
|
||||
if(t != s)
|
||||
{
|
||||
bRet = false ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(in) ;
|
||||
fclose(out) ;
|
||||
|
||||
free(buffer) ;
|
||||
|
||||
return true ;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool RsDirUtil::checkFile(const std::string& filename)
|
||||
{
|
||||
int val;
|
||||
mode_t st_mode;
|
||||
#ifdef WINDOWS_SYS
|
||||
std::wstring wfilename;
|
||||
librs::util::ConvertUtf8ToUtf16(filename, wfilename);
|
||||
struct _stat buf;
|
||||
val = _wstat(wfilename.c_str(), &buf);
|
||||
st_mode = buf.st_mode;
|
||||
#else
|
||||
struct stat buf;
|
||||
val = stat(filename.c_str(), &buf);
|
||||
st_mode = buf.st_mode;
|
||||
#endif
|
||||
if (val == -1)
|
||||
{
|
||||
#ifdef RSDIR_DEBUG
|
||||
std::cerr << "RsDirUtil::checkFile() ";
|
||||
std::cerr << filename << " doesn't exist" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
else if (!S_ISREG(st_mode))
|
||||
{
|
||||
// Some other type - error.
|
||||
#ifdef RSDIR_DEBUG
|
||||
std::cerr << "RsDirUtil::checkFile() ";
|
||||
std::cerr << filename << " is not a Regular File" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RsDirUtil::checkDirectory(const std::string& dir)
|
||||
{
|
||||
|
@ -59,6 +59,8 @@ bool crc32File(FILE *f,uint64_t file_size,uint32_t chunk_size,CRC32Map& map) ;
|
||||
|
||||
int breakupDirList(const std::string& path, std::list<std::string> &subdirs);
|
||||
|
||||
bool copyFile(const std::string& source,const std::string& dest);
|
||||
bool checkFile(const std::string& filename);
|
||||
bool checkDirectory(const std::string& dir);
|
||||
bool checkCreateDirectory(const std::string& dir);
|
||||
bool cleanupDirectory(const std::string& dir, std::list<std::string> keepFiles);
|
||||
|
Loading…
Reference in New Issue
Block a user