BSOne.SFC/Tocsg.Module/FasooDRM/EXE_bs1fsg/ProcessParam.pas

173 lines
4.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{*******************************************************}
{ }
{ ProcessParam }
{ }
{ Copyright (C) 2025 kku }
{ }
{*******************************************************}
unit ProcessParam;
interface
uses
System.SysUtils, Winapi.Windows, Winapi.Messages, Tocsg.Param, Tocsg.Trace,
System.Classes;
type
TProcessParam = class(TTgParam)
private
sFsDir_,
sOwnerMtx_: String;
Trace_: TTgTrace;
public
Constructor Create;
Destructor Destroy; override;
function IsParamOK: Boolean;
property OwnerMtx: String read sOwnerMtx_;
property FsDir: String read sFsDir_;
end;
var
gParam: TProcessParam = nil;
implementation
uses
Tocsg.Path, superobject, Tocsg.Fasoo.Global, Tocsg.Safe, Tocsg.Strings,
Tocsg.Fasoo.Global.Define;
{ TProcessParam }
Constructor TProcessParam.Create;
begin
Inherited Create;
ASSERT(gParam = nil);
sOwnerMtx_ := '';
Trace_ := nil;
{$IFDEF DEBUG}
var sLog: String := GetRunExePath;
if FileExists(sLog) then
DeleteFile(PChar(sLog));
Trace_ := TTgTrace.Create(sLog);
{$ENDIF}
sFsDir_ := GetRunExePathDir + 'fsdinitg';
if not DirectoryExists(sFsDir_) then
sFsDir_ := GetRunExePathDir + 'conf\fsdinitg';
gParam := Self;
end;
Destructor TProcessParam.Destroy;
begin
if Trace_ <> nil then
FreeAndNil(Trace_);
gParam := nil;
Inherited;
end;
function TProcessParam.IsParamOK: Boolean;
var
sPath, sEncPath, sDecPath, sCPID: String;
O: ISuperObject;
nType: Integer;
InfoList: TStringList;
begin
Result := false;
sPath := GetParamValue('/p');
if sPath = '' then
sPath := GetParamValue('-p');
if (sPath = '') or not FileExists(sPath) then
sPath := GetRunExePathDir + DAT_PARAM;
sEncPath := '';
sDecPath := '';
if LoadJsonObjFromFile(O, sPath) then
begin
{$IFNDEF DEBUG}
DeleteFile(PChar(sPath));
{$ENDIF}
if (Trace_ = nil) and O.B['Trace'] and (O.S['TracePath'] <> '') then
begin
DeleteFile(PChar(O.S['TracePath']));
Trace_ := TTgTrace.Create(O.S['TracePath']);
end;
if (O.S['FsDir'] <> '') and DirectoryExists(O.S['FsDir']) then
sFsDir_ := O.S['FsDir'];
if O.I['Type'] = 1 then
begin
sOwnerMtx_ := O.S['OwnerX'];
Result := true;
exit;
end;
sEncPath := O.S['EncPath'];
sDecPath := O.S['DecPath'];
end else begin
sPath := GetParamValue('/c');
if sPath = '' then
sPath := GetParamValue('-c');
if sPath <> CODE_CMD then
exit;
sEncPath := GetParamValue('/s');
if sEncPath = '' then
sEncPath := GetParamValue('-s');
sDecPath := GetParamValue('/d');
if sDecPath = '' then
sDecPath := GetParamValue('-d');
end;
if not FileExists(sEncPath) then
exit;
TTgTrace.T('<27>ļ<EFBFBD>DRM <20><>ȣȭ <20><><EFBFBD><EFBFBD>. EncPath=%s, DecPath=%s', [sEncPath, sDecPath]);
nType := GetFileTypeW_r(sEncPath);
case nType of
109, // <20>̰<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GetFileTypeW_r()<29><> FED5 <20><>ȣȭ<C8A3><C8AD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.. 25_0217 18:54:27 kku
26, 103, 105, 106 : ;
else begin
TTgTrace.T('<27>ļ<EFBFBD>DRM <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ƴմϴ<D5B4>. Path=%s, Type=%d', [sEncPath, nType]);
exit;
end;
end;
sPath := GetFileHeader_r(sEncPath);
if sPath = '' then
begin
TTgTrace.T('<27><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. Path=%s', [sEncPath]);
exit;
end;
Guard(InfoList, TStringList.Create);
SplitString(sPath, ';', InfoList, true);
if InfoList.Count < 18 then
begin
TTgTrace.T('CPID <20><><EFBFBD><EFBFBD> Ȯ<><C8AE> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.');
exit;
end;
sCPID := InfoList[17]; // 18<31><38>°<EFBFBD><C2B0> <20><><EFBFBD><EFBFBD>
if not DirectoryExists(sFsDir_) then
begin
TTgTrace.T('FSD <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.');
exit;
end;
nType := DoExtract_r(sFsDir_, sCPID, sEncPath, sDecPath);
if nType = FASOO_OK then
TTgTrace.T('<27>ļ<EFBFBD>DRM <20><>ȣȭ <20><><EFBFBD><EFBFBD>')
else
TTgTrace.T('<27>ļ<EFBFBD>DRM <20><>ȣȭ <20><><EFBFBD><EFBFBD>, Error=%d', [nType]);
end;
end.