-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagestodepot.pas
291 lines (258 loc) · 8.92 KB
/
imagestodepot.pas
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
unit imagestodepot;
{$mode objfpc}{$H+}
interface
uses
{$IFDEF WINDOWS}
//jwawinbase,
OckWindows,
{$ENDIF WINDOWS}
{$IFDEF LINUX}
OckLinux,
{$ENDIF LINUX}
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, EditBtn,
Process, oslog, FileUtil, LazFileUtils, opsiconnection, //LazProgInfo,
LCLTranslator, ExtCtrls, ComCtrls
{add more units if nedded};
type
{ TFormSaveImagesOnDepot }
TFormSaveImagesOnDepot = class(TForm)
ButtonClose: TButton;
ButtonCopy: TButton;
CheckBoxMountDepot: TCheckBox;
DirectoryEditPathToDepot: TDirectoryEdit;
EditPassword: TEdit;
EditUser: TEdit;
GroupBoxProgress: TGroupBox;
GroupBoxPath: TGroupBox;
GroupBoxMountDepot: TGroupBox;
LabelInfo: TLabel;
LabelPassword: TLabel;
LabelUser: TLabel;
PanelInfo: TPanel;
ProgressBar: TProgressBar;
procedure ButtonCloseClick(Sender: TObject);
procedure ButtonCopyClick(Sender: TObject);
procedure CheckBoxMountDepotChange(Sender: TObject);
procedure DirectoryEditPathToDepotChange(Sender: TObject);
procedure DirectoryEditPathToDepotEnter(Sender: TObject);
procedure FormCreate(Sender: TObject);
//procedure FormDestroy(Sender: TObject);
private
//function InitLogging(const LogFileName: String; MyLogLevel: integer): boolean;
function SaveImagesOnDepot(const PathToDepot: String):boolean;
//function SetRights(Path:String):boolean;
public
end;
var
FormSaveImagesOnDepot: TFormSaveImagesOnDepot;
implementation
{$R *.lfm}
const
PathDepotOnShare = '\var\lib\opsi\depot';
{$IFDEF KIOSK_IN_AGENT} //if the kiosk is in the opsi-client-agent product
PathKioskAppOnShare = '\opsi-client-agent\files\opsi\opsiclientkiosk\app';
{$ELSE} //if the kiosk is a standalone opsi product
PathKioskAppOnShare = '\opsi-client-kiosk\files\app';
{$ENDIF KIOSK_IN_AGENT}
CustomFolder = '\ock_custom';
resourcestring
rsCouldNotSaveIcons = 'Could not save icons on depot.';
rsCouldNotSaveScreenshots = 'Could not save screenshots on depot.';
rsCouldNotUnmount = 'Could not unmount depot.';
rsIsAnInvalidDir = '"%s" is an invalid directory.%sPlease set "%s" to a '
+'valid directory.';
rsImagesNotSaved = 'Images could not be saved on opsi depot. %sPlease'
+' check if depot is mounted with write privileges.';
rsImagesSaved = 'Images saved on';
rsSettingRights = 'Setting rights...';
rsDone = 'done';
rsCopyIcons = 'Copy icons and screenshots...';
rsMounting = 'Mounting';
rsFinished = 'Copy process finished. Closing window...';
{ TFormSaveImagesOnDepot }
procedure TFormSaveImagesOnDepot.ButtonCopyClick(Sender: TObject);
var
PathToDepot : String;
User: String;
AlreadyMounted :boolean;
CopySuccess: boolean;
i,LineNumber:integer;
begin
CopySuccess := False;
PathToDepot := TrimFilename(DirectoryEditPathToDepot.Text);
{Mount opsi depot}
if CheckBoxMountDepot.Checked then
begin
if DirectoryExists(PathToDepot) then AlreadyMounted := True
else
begin
AlreadyMounted := False;
User := EditUser.Text;
MountDepot(User, EditPassword.Text, PathToDepot);
LabelInfo.Caption := rsMounting + ' ' + rsDone;
Application.ProcessMessages;
end;
end;
if DirectoryExists(PathToDepot) then
begin
ProgressBar.Visible := True;
LabelInfo.Caption := rsCopyIcons;
ProgressBar.Position:= 20;
Application.ProcessMessages;
if SaveImagesOnDepot(PathToDepot) then
begin
LabelInfo.Caption := rsCopyIcons + ' ' + rsDone;
Application.ProcessMessages;
sleep(1000);
CopySuccess := True;
LogDatei.log(SwitchPathDelims(PathDepotOnShare + PathKioskAppOnShare + CustomFolder, pdsUnix), LLDebug);
//SetRights(SwitchPathDelims(PathDepotOnShare + PathKioskAppOnShare + CustomFolder, pdsUnix));
ProgressBar.Position:= 80;
Application.ProcessMessages;
end;
end
else
begin
ShowMessage(Format(rsIsAnInvalidDir, [DirectoryEditPathToDepot.Text,
LineEnding, GroupBoxPath.Caption]));
CopySuccess := False;
DirectoryEditPathToDepot.Font.Color:= clRed;
end;
if CheckBoxMountDepot.Checked and (not AlreadyMounted) then
begin
UnmountDepot(PathToDepot);
//LabelInfo.Caption := rsCouldNotUnmount;
end;
if CopySuccess then
begin
ProgressBar.Position:= 100;
LabelInfo.Caption := rsFinished;
Application.ProcessMessages;
sleep(2000); //chance to see that copy process was successful before window is closed
{for i := 5 downto 1 do
begin
LabelInfo.Caption := 'Window will be automatically closed in ' + IntToStr(i) + ' sec';
Application.ProcessMessages;
sleep(1000);
end;}
Close;
end;
end;
procedure TFormSaveImagesOnDepot.CheckBoxMountDepotChange(Sender: TObject);
begin
if CheckBoxMountDepot.Checked then GroupBoxMountDepot.Enabled := True
else GroupBoxMountDepot.Enabled := False;
end;
procedure TFormSaveImagesOnDepot.DirectoryEditPathToDepotChange(Sender: TObject
);
begin
DirectoryEditPathToDepot.Font.Color:= clDefault;
end;
procedure TFormSaveImagesOnDepot.DirectoryEditPathToDepotEnter(Sender: TObject);
begin
DirectoryEditPathToDepot.Font.Color:= clDefault;
end;
procedure TFormSaveImagesOnDepot.FormCreate(Sender: TObject);
begin
//InitLogging('images_to_depot ' + GetUserName_ +'.log', LLDebug);
SetDefaultLang(GetDefaultLang);
end;
(*
procedure TFormSaveImagesOnDepot.FormDestroy(Sender: TObject);
begin
FeeAndNil(LogDatei);
end;
*)
(*
function TFormSaveImagesOnDepot.SetRights(Path:String): boolean;
var
OpsiConnection: TOpsiConnection;
LineNumber: integer;
begin
//LineNumber := MemoInfo.Lines.Add('Please wait while setting rights...');
ProgressBar.Position := 50;
LabelInfo.Caption := rsSettingRights;
//Refresh;
Application.ProcessMessages;
//Refresh;
//MemoInfo.Lines.Text := MemoInfo.Lines.Text+ ('Please wait while setting rights...');
Result := False;
try
try
OpsiConnection := TOpsiConnection.Create(False);
LogDatei.log('ClientID :' + OpsiConnection.MyClientID +
' Service_URL :' + OpsiConnection.MyService_URL +
' Hostkey :' + OpsiConnection.MyHostkey +
' Error :' + OpsiConnection.MyError,LLDebug);
ProgressBar.Position := 80;
Application.ProcessMessages;
OpsiConnection.OpsiData.initOpsiConf(OpsiConnection.MyService_URL,'jan','jan123');
OpsiConnection.SetRights(path);
Result := True;
ProgressBar.Position := 100;
LabelInfo.Caption := rsSettingRights + ' '+ rsDone;;
Application.ProcessMessages;
sleep(1000);
LogDatei.log('SetRights done', LLInfo);
except
Result := False;
end;
finally
OpsiConnection.Free;
end;
end;
*)
function TFormSaveImagesOnDepot.SaveImagesOnDepot(const PathToDepot: String):boolean;
var
PathToKioskOnDepot: String;
PathToIconsOnDepot: String;
PathToKioskOnClient : String;
PathToIconsOnClient: String;
begin
Result := False;
{ Set the right directories }
PathToKioskOnDepot:= SwitchPathDelims(PathKioskAppOnShare, pdsSystem);
PathToKioskOnClient := ExtractFilePath(Application.Location);
//Set path delims dependend on system (e.g. Windows, Unix)
PathToIconsOnClient := SwitchPathDelims(TrimFilename(PathToKioskOnClient + CustomFolder + '\'), pdsSystem);
PathToIconsOnDepot := SwitchPathDelims(TrimFilename(PathToDepot + PathToKioskOnDepot + CustomFolder +'\'), pdsSystem);
LogDatei.log('Copy ' + PathToIconsOnClient + ' to ' + PathToIconsOnDepot, LLInfo);
//if CopyDirTree(PathToIconsOnClient, PathToIconsOnDepot,[cffOverwriteFile, cffCreateDestDirectory]) then
if Copy(PathToIconsOnClient, PathToIconsOnDepot) then
begin
LogDatei.log('Copy done', LLInfo);
Result := True;
Refresh;
end
else
begin
LogDatei.log('Images could not be saved on opsi depot. ' + PathToDepot +
' Possible solution: mount depot with write privileges.' ,LLDebug);
ShowMessage(Format(rsImagesNotSaved, [LineEnding]));
Result := False;
end;
end;
procedure TFormSaveImagesOnDepot.ButtonCloseClick(Sender: TObject);
begin
Close;
end;
(*function TFormSaveImagesOnDepot.InitLogging(const LogFileName:String; MyLogLevel:integer): boolean;
begin
try
//LogDatei.free;
LogDatei := TLogInfo.Create;
LogDatei.WritePartLog := False;
LogDatei.WriteErrFile:= False;
LogDatei.WriteHistFile:= False;
LogDatei.CreateTheLogfile(LogFileName, False);
LogDatei.LogLevel := MylogLevel;
LogDatei.log(' ' + 'Version('+')'
+ ' starting at ' + DateTimeToStr(now), LLEssential);
LogDatei.log('Initialize Logging', LLNotice);
InitLogging := True;
except
InitLogging := False;
LogDatei.log('Error while initialising logging. Calling Method: TFormOpsiClientKiosk.InitLogging',LLDebug);
end;
end;*)
end.