Migrate to ~/.hush/HUSH3 for new installs, fallback to ~/.komodo/HUSH3 if that exists

This commit is contained in:
Duke Leto
2021-07-11 18:03:22 -04:00
parent aa39fc4f49
commit bddd4c5cd3
2 changed files with 46 additions and 27 deletions

View File

@@ -1369,7 +1369,7 @@ void hush_statefname(char *fname,char *symbol,char *str)
void hush_configfile(char *symbol,uint16_t rpcport) void hush_configfile(char *symbol,uint16_t rpcport)
{ {
static char myusername[512],mypassword[8192]; static char myusername[512],mypassword[8192];
FILE *fp; uint16_t kmdport; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i; FILE *fp; uint16_t hushport; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i;
if ( symbol != 0 && rpcport != 0 ) if ( symbol != 0 && rpcport != 0 )
{ {
r = (uint32_t)time(NULL); r = (uint32_t)time(NULL);
@@ -1427,8 +1427,8 @@ void hush_configfile(char *symbol,uint16_t rpcport)
#endif #endif
if ( (fp= fopen(fname,"rb")) != 0 ) if ( (fp= fopen(fname,"rb")) != 0 )
{ {
if ( (kmdport= _hush_userpass(username,password,fp)) != 0 ) if ( (hushport= _hush_userpass(username,password,fp)) != 0 )
HUSH3_PORT = kmdport; HUSH3_PORT = hushport;
sprintf(HUSHUSERPASS,"%s:%s",username,password); sprintf(HUSHUSERPASS,"%s:%s",username,password);
fclose(fp); fclose(fp);
//printf("HUSH.(%s) -> userpass.(%s)\n",fname,HUSHUSERPASS); //printf("HUSH.(%s) -> userpass.(%s)\n",fname,HUSHUSERPASS);
@@ -1441,15 +1441,9 @@ uint16_t hush_userpass(char *userpass,char *symbol)
{ {
FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[HUSH_SMART_CHAIN_MAXLEN]; FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[HUSH_SMART_CHAIN_MAXLEN];
userpass[0] = 0; userpass[0] = 0;
if ( strcmp("SPECIAL",symbol) == 0 )
{ sprintf(confname,"%s.conf",symbol);
#ifdef __APPLE__
sprintf(confname,"Something.conf");
#else
sprintf(confname,"Something.conf");
#endif
}
else sprintf(confname,"%s.conf",symbol);
hush_statefname(fname,symbol,confname); hush_statefname(fname,symbol,confname);
if ( (fp= fopen(fname,"rb")) != 0 ) if ( (fp= fopen(fname,"rb")) != 0 )
{ {

View File

@@ -497,15 +497,30 @@ boost::filesystem::path GetDefaultDataDir()
if ( SMART_CHAIN_SYMBOL[0] != 0 ) if ( SMART_CHAIN_SYMBOL[0] != 0 )
strcpy(symbol,SMART_CHAIN_SYMBOL); strcpy(symbol,SMART_CHAIN_SYMBOL);
else symbol[0] = 0; else symbol[0] = 0;
// OLD NAMES:
// Windows < Vista: C:\Documents and Settings\Username\Application Data\Komodo // Windows < Vista: C:\Documents and Settings\Username\Application Data\Komodo
// Windows >= Vista: C:\Users\Username\AppData\Roaming\Komodo // Windows >= Vista: C:\Users\Username\AppData\Roaming\Komodo
// Mac: ~/Library/Application Support/Komodo // Mac: ~/Library/Application Support/Komodo
// Unix: ~/.komodo // Unix: ~/.komodo
// NEW NAMES:
// Windows < Vista: C:\Documents and Settings\Username\Application Data\Hush
// Windows >= Vista: C:\Users\Username\AppData\Roaming\Hush
// Mac: ~/Library/Application Support/Hush
// Unix: ~/.hush
// ~/.hush was actually used by the original 1.x version of Hush, but we will
// only make subdirectories inside of it, so we won't be able to overwrite
// an old wallet.dat from the Ice Ages :)
#ifdef _WIN32 #ifdef _WIN32
// Windows // Windows
if ( symbol[0] == 0 ) pathRet = GetSpecialFolderPath(CSIDL_APPDATA) / "Komodo" / symbol;
return GetSpecialFolderPath(CSIDL_APPDATA) / "Komodo"; if(fs::is_directory(pathRet)) {
else return GetSpecialFolderPath(CSIDL_APPDATA) / "Komodo" / symbol; // legacy directory, use that
} else {
pathRet = GetSpecialFolderPath(CSIDL_APPDATA) / "Hush" / symbol;
}
return pathRet;
#else #else
fs::path pathRet; fs::path pathRet;
char* pszHome = getenv("HOME"); char* pszHome = getenv("HOME");
@@ -517,19 +532,31 @@ boost::filesystem::path GetDefaultDataDir()
// Mac // Mac
pathRet /= "Library/Application Support"; pathRet /= "Library/Application Support";
TryCreateDirectory(pathRet); TryCreateDirectory(pathRet);
if ( symbol[0] == 0 ) fs::path tmppath;
return pathRet / "Komodo"; tmppath = pathRet;
else tmppath /= "Komodo";
{ if(fs::is_directory(pathRet)) {
pathRet /= "Komodo"; //legacy directory, use that
TryCreateDirectory(pathRet); TryCreateDirectory(tmppath);
return pathRet / symbol; return tmppath / symbol;
} else {
// New directory :)
tmppath = pathRet;
tmppath /= "Hush";
TryCreateDirectory(tmppath);
return tmppath / symbol;
} }
#else #else
// Unix // Unix
if ( symbol[0] == 0 ) fs::path tmppath = pathRet / ".komodo" / symbol;
return pathRet / ".komodo"; if(fs::is_directory(tmppath)) {
else return pathRet / ".komodo" / symbol; // legacy directory, use that for backward compat
return tmppath;
} else {
// New directory :)
tmppath = pathRet / ".hush" / symbol;
return tmppath;
}
#endif #endif
#endif #endif
} }
@@ -638,8 +665,6 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
path /= BaseParams().DataDir(); path /= BaseParams().DataDir();
fs::create_directories(path); fs::create_directories(path);
//std::string assetpath = path + "/assets";
//boost::filesystem::create_directory(assetpath);
return path; return path;
} }