@@ -545,98 +545,80 @@ fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
545
545
546
546
fs::path GetDefaultDataDir ()
547
547
{
548
- // Windows < Vista: C:\Documents and Settings\Username\Application Data\gridcoinresearch
549
- // Windows >= Vista: C:\Users\Username\AppData\Roaming\gridcoinresearch
550
- // Mac: ~/Library/Application Support/gridcoinresearch
551
- // Unix: ~/.gridcoin
548
+ // Windows < Vista: C:\Documents and Settings\Username\Application Data\GridcoinResearch
549
+ // Windows >= Vista: C:\Users\Username\AppData\Roaming\GridcoinResearch
550
+ // Mac: ~/Library/Application Support/GridcoinResearch
551
+ // Linux/ Unix: ~/.GridcoinResearch
552
552
#ifdef WIN32
553
553
// Windows
554
+
555
+ // This is the user's base roaming AppData path with GridcoinResearch added.
554
556
return GetSpecialFolderPath (CSIDL_APPDATA) / " GridcoinResearch" ;
555
557
#else
556
- // 2-25-2015
557
- fs::path pathRet;
558
- char * pszHome = getenv (" HOME" );
558
+ fs::path pathRet;
559
559
560
- if (mapArgs.count (" -datadir" ))
561
- {
562
- fs::path path2015 = fs::system_complete (mapArgs[" -datadir" ]);
563
- if (fs::is_directory (path2015))
564
- {
565
- pathRet = path2015;
566
- }
567
- }
568
- else
569
- {
570
- if (pszHome == NULL || strlen (pszHome) == 0 )
571
- pathRet = fs::path (" /" );
572
- else
573
- pathRet = fs::path (pszHome);
574
- }
575
- #ifdef MAC_OSX
576
- // Mac
577
- pathRet /= " Library/Application Support" ;
578
- fs::create_directory (pathRet);
560
+ // For everything except for Windows, use the environment variable to get
561
+ // the home path.
562
+ char * pszHome = getenv (" HOME" );
579
563
580
- if (mapArgs.count (" -datadir" ))
581
- {
582
- return pathRet;
583
- }
584
- else
585
- {
586
- return pathRet / " GridcoinResearch" ;
564
+ // There is no home path, so default to the root directory.
565
+ if (pszHome == nullptr || strlen (pszHome) == 0 ) {
566
+ pathRet = fs::path (" /" );
567
+ } else {
568
+ pathRet = fs::path (pszHome);
587
569
}
570
+ #ifdef MAC_OSX
571
+ // The pathRet here represents the HOME directory. Apple
572
+ // applications are expected to store their files in
573
+ // "~/Library/Application Support/[AppDir].
574
+ return pathRet / " Library" / " Application Support" / " GridcoinResearch" ;
588
575
#else
589
- // Unix
590
- if (mapArgs.count (" -datadir" ))
591
- {
592
- return pathRet;
593
- }
594
- else
595
- {
596
- return pathRet / " .GridcoinResearch" ;
597
- }
598
- #endif
599
- #endif
576
+ // Linux/Unix
577
+ return pathRet / " .GridcoinResearch" ;
578
+ #endif // MAC_OSX
579
+ #endif // WIN32
600
580
}
601
581
602
582
const fs::path &GetDataDir (bool fNetSpecific )
603
583
{
604
584
static fs::path pathCached[2 ];
605
- static CCriticalSection csPathCached ;
585
+ static CCriticalSection cs_PathCached ;
606
586
static bool cachedPath[2 ] = {false , false };
607
- // 2-25-2015
587
+
608
588
fs::path &path = pathCached[fNetSpecific ];
609
589
610
590
// This can be called during exceptions by LogPrintf, so we cache the
611
591
// value so we don't have to do memory allocations after that.
612
- if (cachedPath[fNetSpecific ] && ( fs::is_directory (path)) )
592
+ if (cachedPath[fNetSpecific ] && fs::is_directory (path))
613
593
{
614
594
return path;
615
595
}
616
596
617
- LOCK (csPathCached );
597
+ LOCK (cs_PathCached );
618
598
619
599
if (mapArgs.count (" -datadir" ))
620
600
{
621
601
path = fs::system_complete (mapArgs[" -datadir" ]);
622
602
if (!fs::is_directory (path))
623
603
{
624
- path = " " ;
625
- return path ;
604
+ throw std::runtime_error ( " Supplied datadir is invalid! "
605
+ " Please check your datadir argument. Aborting. " ) ;
626
606
}
627
607
}
628
608
else
629
609
{
630
610
path = GetDefaultDataDir ();
631
611
}
632
- if ( (fNetSpecific && GetBoolArg (" -testnet" , false )) || GetBoolArg (" -testnet" ,false ) )
612
+
613
+ if (fNetSpecific && GetBoolArg (" -testnet" , false ))
633
614
{
634
615
path /= " testnet" ;
635
616
}
636
617
637
618
if (!fs::exists (path)) fs::create_directory (path);
638
619
639
- cachedPath[fNetSpecific ]=true ;
620
+ cachedPath[fNetSpecific ] = true ;
621
+
640
622
return path;
641
623
}
642
624
@@ -687,7 +669,7 @@ fs::path GetProgramDir()
687
669
fs::path GetConfigFile ()
688
670
{
689
671
fs::path pathConfigFile (GetArg (" -conf" , " gridcoinresearch.conf" ));
690
- if (!pathConfigFile.is_absolute ()) pathConfigFile = GetDataDir (false ) / pathConfigFile;
672
+ if (!pathConfigFile.is_absolute ()) pathConfigFile = GetDataDir () / pathConfigFile;
691
673
return pathConfigFile;
692
674
}
693
675
0 commit comments