Skip to content

Commit

Permalink
add method openwithexternalprogram
Browse files Browse the repository at this point in the history
  • Loading branch information
riderkick committed Jun 11, 2015
1 parent 5889a30 commit 4909097
Showing 1 changed file with 33 additions and 42 deletions.
75 changes: 33 additions & 42 deletions mangadownloader/forms/frmMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ TMainForm = class(TForm)
// load language file
procedure LoadLanguage;

procedure OpenWithExternalProgram(const dirPath, Filename: String);

// exception handle
procedure ExceptionHandler(Sender: TObject; E: Exception);
{ public declarations }
Expand Down Expand Up @@ -2558,7 +2560,7 @@ procedure TMainForm.miDownloadOpenFolderClick(Sender: TObject);

procedure TMainForm.miFavoritesOpenWithClick(Sender: TObject);
var
f, fd, ff, s: String;
f, fd: String;
Info: TSearchRec;
l: TStringList;
begin
Expand All @@ -2581,34 +2583,15 @@ procedure TMainForm.miFavoritesOpenWithClick(Sender: TObject);
f := '';
FindCloseUTF8(Info);

fd := Trim(TrimRightChar(Trim(fd), [PathDelim]));
f := Trim(TrimChar(Trim(f), [PathDelim]));

ff := Trim(options.ReadString('general', 'ExternalProgramPath', ''));
s := Trim(options.ReadString('general', 'ExternalProgramParams', DEFAULT_EXPARAM));

if ff <> '' then
begin
if (Pos(EXPARAM_PATH + EXPARAM_CHAPTER, s) <> 0) then
f := PathDelim + f;
s := StringReplace(s, EXPARAM_PATH, fd, [rfReplaceAll]);
s := StringReplace(s, EXPARAM_CHAPTER, f, [rfReplaceAll]);
RunExternalProcess(ff, s, True, False);
end
else
begin
if (fd <> '') and (f <> '') then
s := fd + PathDelim + f;
OpenDocument(s);
end;
OpenWithExternalProgram(fd, f);
except
end;
l.Free;
end;

procedure TMainForm.miDownloadOpenWithClick(Sender: TObject);
var
f, fd, ff, s: String;
f, fd, ff: String;
Info: TSearchRec;
l: TStringList;
begin
Expand Down Expand Up @@ -2650,26 +2633,7 @@ procedure TMainForm.miDownloadOpenWithClick(Sender: TObject);
FindCloseUTF8(Info);
end;

fd := Trim(TrimRightChar(Trim(fd), [PathDelim]));
f := Trim(TrimChar(Trim(f), [PathDelim]));

ff := Trim(options.ReadString('general', 'ExternalProgramPath', ''));
s := Trim(options.ReadString('general', 'ExternalProgramParams', DEFAULT_EXPARAM));

if ff <> '' then
begin
if (Pos(EXPARAM_PATH + EXPARAM_CHAPTER, s) <> 0) then
f := PathDelim + f;
s := StringReplace(s, EXPARAM_PATH, fd, [rfReplaceAll]);
s := StringReplace(s, EXPARAM_CHAPTER, f, [rfReplaceAll]);
RunExternalProcess(ff, s, True, False);
end
else
begin
if (fd <> '') and (f <> '') then
s := fd + PathDelim + f;
OpenDocument(s);
end;
OpenWithExternalProgram(fd, f);
except
end;
l.Free;
Expand Down Expand Up @@ -4843,6 +4807,33 @@ procedure TMainForm.LoadLanguage;
end;
end;

procedure TMainForm.OpenWithExternalProgram(const dirPath, Filename: String);
var
Exe, Params,
p, f: String;
begin
Exe := Trim(options.ReadString('general', 'ExternalProgramPath', ''));
Params := Trim(options.ReadString('general', 'ExternalProgramParams', DEFAULT_EXPARAM));

p := Trim(TrimRightChar(Trim(dirPath), [PathDelim]));
f := Trim(TrimChar(Trim(Filename), [PathDelim]));

if Exe <> '' then
begin
if (Pos(EXPARAM_PATH + EXPARAM_CHAPTER, Params) <> 0) then
f := PathDelim + f;
Params := StringReplace(Params, EXPARAM_PATH, p, [rfIgnoreCase, rfReplaceAll]);
Params := StringReplace(Params, EXPARAM_CHAPTER, f, [rfIgnoreCase, rfReplaceAll]);
RunExternalProcess(Exe, Params, True, False);
end
else
begin
if (p <> '') and (f <> '') then
f := p + PathDelim + f;
OpenDocument(f);
end;
end;

procedure TMainForm.ExceptionHandler(Sender: TObject; E: Exception);
begin
USimpleException.ExceptionHandle(Sender, E);
Expand Down

0 comments on commit 4909097

Please sign in to comment.