-
Notifications
You must be signed in to change notification settings - Fork 312
Expand file tree
/
Copy pathflinker.pas
More file actions
230 lines (201 loc) · 6.41 KB
/
Copy pathflinker.pas
File metadata and controls
230 lines (201 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
{
Double Commander
-------------------------------------------------------------------------
Take selected files and put them together to form one single file.
Copyright (C) 2018-2023 Alexander Koblov (alexx2000@mail.ru)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Original comment:
----------------------------
Seksi Commander
----------------------------
Licence : GNU GPL v 2.0
Author : Pavel Letko (letcuv@centrum.cz)
File combiner
contributors:
Radek Cervinka
}
unit fLinker;
{$mode objfpc}{$H+}
interface
uses
//Lazarus, Free-Pascal, etc.
SysUtils, Classes, Forms, Dialogs, StdCtrls,
//DC
fButtonForm, uFileSource, uFile;
type
{ TfrmLinker }
TfrmLinker = class(TfrmButtonForm)
lblFileName: TLabel;
lstFile: TListBox;
gbSaveTo: TGroupBox;
edSave: TEdit;
btnSave: TButton;
grbxControl: TGroupBox;
spbtnUp: TButton;
spbtnDown: TButton;
spbtnRem: TButton;
dlgSaveAll: TSaveDialog;
procedure spbtnUpClick(Sender: TObject);
procedure spbtnDownClick(Sender: TObject);
procedure spbtnRemClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{ ShowLinkerFilesForm:
"TMainCommands.cm_FileLinker" function from "uMainCommands.pas" is calling this routine.}
function ShowLinkerFilesForm(TheOwner: TComponent; aFileSource: IFileSource; aFiles: TFiles; TargetPath: String): Boolean;
{ DoDynamicFilesLinking:
"TMainCommands.cm_FileLinker" function from "uMainCommands.pas" is calling this routine.}
procedure DoDynamicFilesLinking(aFileSource: IFileSource; aFiles: TFiles; TargetPath, aFirstFilenameOfSeries: String);
implementation
{$R *.lfm}
uses
//Lazarus, Free-Pascal, etc.
LCLProc, Controls,
//DC
DCStrUtils, uLng, uFileProcs, uOperationsManager, uFileSourceCombineOperation,
DCOSUtils, uShowMsg, uGlobs;
{ ShowLinkerFilesForm:
"TMainCommands.cm_FileLinker" function from "uMainCommands.pas" is calling this routine.}
function ShowLinkerFilesForm(TheOwner: TComponent; aFileSource: IFileSource;
aFiles: TFiles; TargetPath: String): Boolean;
var
I: Integer;
AFileName: String;
ADirectory: String;
xFiles: TFiles = nil;
Operation: TFileSourceCombineOperation = nil;
begin
with TfrmLinker.Create(TheOwner) do
begin
try
// Fill file list box
for I:= 0 to aFiles.Count - 1 do
with lstFile.Items do
begin
AddObject(aFiles[I].Name, aFiles[I]);
end;
// Use first file name without extension as target file name
edSave.Text:= TargetPath + aFiles[0].NameNoExt;
// Show form
Result:= (ShowModal = mrOk);
if Result then
begin
ADirectory:= ExtractFileDir(edSave.Text);
if Length(ADirectory) > 0 then
begin
AFileName:= edSave.Text
end
else begin
AFileName:= aFiles.Path + edSave.Text;
ADirectory:= ExcludeTrailingBackslash(aFiles.Path);
end;
for I:= 0 to lstFile.Count - 1 do
begin
with lstFile.Items do
if mbCompareFileNames(TFile(Objects[I]).FullPath, AFileName) then
begin
msgError(Format(rsMsgCanNotCopyMoveItSelf, [AFileName]));
Exit;
end;
end;
if mbForceDirectory(ADirectory) then
try
// Fill file list with new file order
xFiles:= TFiles.Create(aFiles.Path);
for I:= 0 to lstFile.Count - 1 do
with lstFile.Items do
begin
xFiles.Add(TFile(Objects[I]).Clone);
end;
Operation:= aFileSource.CreateCombineOperation(xFiles, AFileName) as TFileSourceCombineOperation;
OperationsManager.AddOperation(Operation, QueueIdentifier, False);
finally
FreeAndNil(xFiles);
end;
end;
finally
Free;
end;
end;
end;
{ DoDynamicFilesLinking:
"TMainCommands.cm_FileLinker" function from "uMainCommands.pas" is calling this routine.}
procedure DoDynamicFilesLinking(aFileSource: IFileSource; aFiles: TFiles; TargetPath, aFirstFilenameOfSeries: String);
var
xFiles: TFiles = nil;
Operation: TFileSourceCombineOperation = nil;
begin
xFiles:= TFiles.Create(aFiles.Path);
try
//Fill file list with new file order
xFiles.Add(aFiles[0].Clone);
Operation:= aFileSource.CreateCombineOperation(xFiles, TargetPath + aFiles[0].NameNoExt) as TFileSourceCombineOperation;
Operation.RequireDynamicMode:=TRUE;
OperationsManager.AddOperation(Operation);
finally
FreeAndNil(xFiles);
end;
end;
{ TfrmLinker.spbtnDownClick }
procedure TfrmLinker.spbtnDownClick(Sender: TObject);
var
iSelected: Integer;
begin
with lstFile do
begin
if ItemIndex < 0 then Exit;
if ItemIndex = Items.Count - 1 then Exit;
iSelected:= ItemIndex;
Items.Move(iSelected, iSelected + 1);
ItemIndex:= iSelected + 1;
end;
end;
{ TfrmLinker.spbtnUpClick }
procedure TfrmLinker.spbtnUpClick(Sender: TObject);
var
iSelected: Integer;
begin
with lstFile do
begin
if ItemIndex < 1 then Exit;
iSelected:= ItemIndex;
Items.Move(iSelected, iSelected - 1);
ItemIndex:= iSelected - 1;
end;
end;
{ TfrmLinker.spbtnRemClick }
procedure TfrmLinker.spbtnRemClick(Sender: TObject);
begin
with lstFile do
begin
if ItemIndex > -1 then Items.Delete(ItemIndex);
end;
end;
{ TfrmLinker.btnSaveClick }
procedure TfrmLinker.btnSaveClick(Sender: TObject);
begin
dlgSaveAll.InitialDir:= ExtractFileDir(edSave.Text);
dlgSaveAll.FileName:= ExtractFileName(edSave.Text);
if dlgSaveAll.Execute then edSave.Text:= dlgSaveAll.FileName;
end;
{TfrmLinker.FormCreate }
procedure TfrmLinker.FormCreate(Sender: TObject);
begin
InitPropStorage(Self); // Initialize property storage
dlgSaveAll.Filter := ParseLineToFileFilter([rsFilterAnyFiles, AllFilesMask]);
end;
end.