Browse Source

Allow set DATAFOLDER to pascalcoin_daemon.ini file

Pascal Coin 4 years ago
parent
commit
dfb64698ee
1 changed files with 21 additions and 22 deletions
  1. 21 22
      src/core/upcdaemon.pas

+ 21 - 22
src/core/upcdaemon.pas

@@ -46,6 +46,7 @@ Const
   CT_INI_IDENT_LOWMEMORY = 'LOWMEMORY';
   CT_INI_IDENT_MINPENDINGBLOCKSTODOWNLOADCHECKPOINT = 'MINPENDINGBLOCKSTODOWNLOADCHECKPOINT';
   CT_INI_IDENT_PEERCACHE = 'PEERCACHE';
+  CT_INI_IDENT_DATA_FOLDER = 'DATAFOLDER';
 
 Type
   { TPCDaemonThread }
@@ -55,6 +56,7 @@ Type
     FIniFile : TIniFile;
     FMaxBlockToRead: Int64;
     FLastNodesCacheUpdatedTS : TTickCount;
+    function GetDataFolder : String;
     procedure OnNetDataReceivedHelloMessage(Sender : TObject);
     procedure OnInitSafeboxProgressNotify(sender : TObject; const message : String; curPos, totalCount : Int64);
   protected
@@ -87,7 +89,6 @@ Type
   TPCDaemonMapper = Class(TCustomDaemonMapper)
   private
     FLog : TLog;
-    procedure OnPascalCoinInThreadLog(logtype : TLogType; Time : TDateTime; AThreadID : TThreadID; Const sender, logtext : String);
   protected
     Procedure DoOnCreate; override;
     Procedure DoOnDestroy; override;
@@ -105,6 +106,19 @@ Var _FLog : TLog;
 
 { TPCDaemonThread }
 
+function TPCDaemonThread.GetDataFolder: String;
+Var LIniDataFolder : String;
+begin
+  LIniDataFolder := FIniFile.ReadString(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_DATA_FOLDER,'').Trim;
+  if (LIniDataFolder.Length=0) then begin
+    LIniDataFolder:=TNode.GetPascalCoinDataFolder;
+  end else begin
+    TNode.SetPascalCoinDataFolder(LIniDataFolder);
+  end;
+  ForceDirectories(LIniDataFolder);
+  Result := LIniDataFolder;
+end;
+
 procedure TPCDaemonThread.OnNetDataReceivedHelloMessage(Sender: TObject);
 Var LNsarr : TNodeServerAddressArray;
   i : Integer;
@@ -154,7 +168,7 @@ var
     TLog.NewLog(ltInfo,ClassName,'RPC server is active on port '+IntToStr(port));
     If FIniFile.ReadBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_RPC_SAVELOGS,true) then begin
       FIniFile.WriteBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_RPC_SAVELOGS,true);
-      FRPC.LogFileName:= TNode.GetPascalCoinDataFolder+PathDelim+'pascalcoin_rpc.log';
+      FRPC.LogFileName:= GetDataFolder+PathDelim+'pascalcoin_rpc.log';
       TLog.NewLog(ltInfo,ClassName,'Activating RPC logs on file '+FRPC.LogFileName);
     end else begin
       FIniFile.WriteBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_RPC_SAVELOGS,false);
@@ -233,12 +247,10 @@ begin
       // Load Node
       // Check OpenSSL dll
       if Not LoadSSLCrypt then begin
-        WriteLn('Cannot load '+SSL_C_LIB);
-        WriteLn('To use this software make sure this file is available on you system or reinstall the application');
         raise Exception.Create('Cannot load '+SSL_C_LIB+#10+'To use this software make sure this file is available on you system or reinstall the application');
       end;
       TCrypto.InitCrypto;
-      FWalletKeys.WalletFileName := TNode.GetPascalCoinDataFolder+PathDelim+'WalletKeys.dat';
+      FWalletKeys.WalletFileName := GetDataFolder+PathDelim+'WalletKeys.dat';
       // Creating Node:
       FNode := TNode.Node;
       {$IFDEF TESTNET}
@@ -249,7 +261,7 @@ begin
       Try
         // Check Database
         FNode.Bank.StorageClass := TFileStorage;
-        TFileStorage(FNode.Bank.Storage).DatabaseFolder := TNode.GetPascalCoinDataFolder+PathDelim+'Data';
+        TFileStorage(FNode.Bank.Storage).DatabaseFolder := GetDataFolder+PathDelim+'Data';
         TFileStorage(FNode.Bank.Storage).LowMemoryUsage := FIniFile.ReadBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_LOWMEMORY,False);
         // By default daemon will not download checkpoint except if specified on INI file
         TNetData.NetData.MinFutureBlocksToDownloadNewSafebox := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_MINPENDINGBLOCKSTODOWNLOADCHECKPOINT,0);
@@ -268,7 +280,7 @@ begin
         Try
           Repeat
             Sleep(100);
-          Until Terminated;
+          Until (Terminated) or (Application.Terminated);
         finally
           FreeAndNil(FMinerServer);
         end;
@@ -380,30 +392,17 @@ end;
 
 { TPCDaemonMapper }
 
-procedure TPCDaemonMapper.OnPascalCoinInThreadLog(logtype: TLogType;
-  Time: TDateTime; AThreadID: TThreadID; const sender, logtext: String);
-Var s : AnsiString;
-begin
-//  If Not SameText(sender,TPCDaemonThread.ClassName) then exit;
-  If logtype in [lterror,ltinfo] then begin
-    if AThreadID=MainThreadID then s := ' MAIN:' else s:=' TID:';
-    WriteLn(formatDateTime('dd/mm/yyyy hh:nn:ss.zzz',Time)+s+IntToHex(PtrInt(AThreadID),8)+' ['+CT_LogType[Logtype]+'] <'+sender+'> '+logtext);
-  end;
-end;
-
 procedure TPCDaemonMapper.DoOnCreate;
 Var D : TDaemonDef;
 begin
   inherited DoOnCreate;
-  WriteLn('');
-  WriteLn(formatDateTime('dd/mm/yyyy hh:nn:ss.zzz',now)+' Starting PascalCoin server');
   FLog := TLog.Create(Nil);
-  FLog.OnInThreadNewLog:=@OnPascalCoinInThreadLog;
   _FLog := FLog;
   D:=DaemonDefs.Add as TDaemonDef;
-  D.DisplayName:='Pascal Coin Daemon';
+  D.DisplayName:='PascalCoin Daemon';
   D.Name:='PascalCoinDaemon';
   D.DaemonClassName:='TPCDaemon';
+  D.Options:=[doAllowStop];
   D.WinBindings.ServiceType:=stWin32;
 end;