148 lines
3.8 KiB
Plaintext
148 lines
3.8 KiB
Plaintext
unit DFindRfMain;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
|
|
|
|
type
|
|
TDlgFindRfMain = class(TForm)
|
|
btnFindRf: TButton;
|
|
edSrc: TEdit;
|
|
edResult: TEdit;
|
|
mmLog: TMemo;
|
|
procedure btnFindRfClick(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
public
|
|
{ Public declarations }
|
|
end;
|
|
|
|
var
|
|
DlgFindRfMain: TDlgFindRfMain;
|
|
|
|
implementation
|
|
|
|
uses
|
|
Tocsg.Path, Tocsg.Files, Tocsg.Registry, Tocsg.Safe, Tocsg.Shell;
|
|
|
|
{$R *.dfm}
|
|
|
|
procedure TDlgFindRfMain.btnFindRfClick(Sender: TObject);
|
|
var
|
|
sDocName,
|
|
sResult,
|
|
sDir, sRDir, sChk: String;
|
|
DList: TStringList;
|
|
FList: TModFileList;
|
|
i: Integer;
|
|
// Plf: TParserLinkFile;
|
|
begin
|
|
mmLog.Clear;
|
|
|
|
sResult := '';
|
|
|
|
mmLog.Lines.Add('Step .. 1');
|
|
sDocName := Trim(edSrc.Text);
|
|
if sDocName = '' then
|
|
begin
|
|
MessageBox(Handle, PChar('문서 이름을 입력해주세요.'), PChar(Caption), MB_ICONWARNING or MB_OK);
|
|
exit;
|
|
end;
|
|
|
|
mmLog.Lines.Add('Step .. 2');
|
|
|
|
sDir := GetWindowsDir;
|
|
if sDir = '' then
|
|
exit;
|
|
|
|
mmLog.Lines.Add('Step .. 3');
|
|
|
|
Guard(DList, TStringList.Create);
|
|
Guard(FList, TModFileList.Create(TModeFileComparer.Create));
|
|
|
|
sDir := 'C:\Users\';
|
|
ExtrDirFromDir(sDir, DList);
|
|
|
|
mmLog.Lines.Add('Step .. 4');
|
|
for i := 0 to DList.Count - 1 do
|
|
begin
|
|
sRDir := sDir + DList[i] + '\AppData\Roaming\Microsoft\Windows\Recent\';
|
|
mmLog.Lines.Add('RecentPath = ' + sRDir);
|
|
ExtrModFilesFromDir(sRDir, FList);
|
|
end;
|
|
|
|
if FList.Count > 0 then
|
|
begin
|
|
mmLog.Lines.Add('Step .. 5, RecentFileCount = ' + IntToStr(FList.Count));
|
|
try
|
|
FList.Sort;
|
|
|
|
// if bIgrRB then
|
|
// sDocName := StrsReplace(sDocName, ['(', ')', '[', ']'], '0');
|
|
|
|
for i := 0 to FList.Count - 1 do
|
|
begin
|
|
// if bIgrRB then
|
|
// sChk := StrsReplace(CutFileExt(FList[i].sName), ['(', ')', '[', ']'], '0')
|
|
// else
|
|
sChk := CutFileExt(FList[i].sFName);
|
|
|
|
if Pos(sChk, sDocName) > 0 then
|
|
begin
|
|
sResult := GetTargetExeFromLink(FList[i].sDir + FList[i].sFName);
|
|
if sResult = '' then
|
|
continue;
|
|
|
|
// 간혹 사용자 폴더가 이상하게(?) 표시되는 경우가 있다.. 보정 24_0514 10:09:24 kku
|
|
// if (sResult <> '') and (Pos('windows\system32\config\systemprofile', sResult.ToLower) > 0) then
|
|
// begin
|
|
// mmLog.Lines.Add('보정 전 = ' + sResult);
|
|
// sResult := StringReplace(sResult, 'windows\system32\config\systemprofile',
|
|
// Format('Users\%s', [GetUserNameFromReg]), [rfReplaceAll, rfIgnoreCase]);
|
|
// mmLog.Lines.Add('보정 후 = ' + sResult);
|
|
// end;
|
|
|
|
if DirectoryExists(sResult) then
|
|
continue;
|
|
|
|
// Guard(Plf, TParserLinkFile.Create);
|
|
// if Plf.LoadFromFile(sDir + FList[i].sName) then
|
|
// begin
|
|
// Result := GetLfiValueFromCaption(Plf.LfiEntList, 'Base Path');
|
|
// if not FileExists(Result) then
|
|
// Result := '';
|
|
// end;
|
|
mmLog.Lines.Add('Step .. 6, Idx = ' + IntToStr(i));
|
|
exit;
|
|
end;
|
|
end;
|
|
|
|
// PDF의 경우... 문서 이름에 파일 이름이 안들어 가는 경우가 있다...
|
|
// PDF 파일 최근파일 내역을 찾을 수 없다면 맨 첫번째 있는 PDF 파일을 넘겨준다.. 24_0418 15:10:27 kku
|
|
if Pos('.PDF', sDocName.ToUpper) > 0 then
|
|
begin
|
|
for i := 0 to FList.Count - 1 do
|
|
begin
|
|
sChk := CutFileExt(FList[i].sFName);
|
|
if GetFileExt(sChk).ToUpper = 'PDF' then
|
|
begin
|
|
sResult := sChk;
|
|
exit;
|
|
end;
|
|
end;
|
|
end;
|
|
finally
|
|
if sResult <> '' then
|
|
begin
|
|
edResult.Text := sResult;
|
|
mmLog.Lines.Add('Step .. 7, Success');
|
|
MessageBox(Handle, PChar('성공'), PChar(Caption), MB_ICONINFORMATION or MB_OK);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
end.
|