~ubuntu-branches/ubuntu/precise/winff/precise

« back to all changes in this revision

Viewing changes to .pc/prevent_overwrite_on_preview/unit1.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers
  • Date: 2012-01-12 21:42:51 UTC
  • mfrom: (4.2.9 sid)
  • Revision ID: package-import@ubuntu.com-20120112214251-jcfcnmraero64v2l
Tags: 1.4.1-1
* Import upstream version 1.4.1
* Remove all patches, now applied upsteam
* Update d/presets.xml and d/presets-libavcodec53.xml with upstream
  changes
* Update d/control to depend on libav-tools as (near future)
  replacement for ffmpeg
* Add patch to remove win32 as target OS to allow building
* Add patch to prevent unnecessary linking against libraries
* Add patch to allow the debugging symbols to be generated

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
unit Unit1; 
2
 
 
3
 
// WInFF 1.0 Copyright 2006-2009 Matthew Weatherford
4
 
// WinFF 1.3.2 Copyright 2011 Alexey Osipov <lion-simba@pridelands.ru>
5
 
// http://winff.org
6
 
// Licensed under the GPL v3 or any later version
7
 
//
8
 
// This program is free software: you can redistribute it and/or modify
9
 
// it under the terms of the GNU General Public License as published by
10
 
// the Free Software Foundation, either version 3 of the License, or
11
 
// any later version.
12
 
//
13
 
// This program is distributed in the hope that it will be useful,
14
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
// GNU General Public License for more details.
17
 
//
18
 
//    You should have received a copy of the GNU General Public License
19
 
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
 
21
 
{$mode objfpc}{$H+}
22
 
 
23
 
interface
24
 
 
25
 
uses
26
 
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
27
 
  {$IFDEF WIN32} windows, shellapi, dos,{$endif}
28
 
  {$IFDEF unix} baseunix, unix, {$endif}
29
 
  laz_xmlcfg, dom, xmlread, xmlwrite, StdCtrls, Buttons, ActnList, Menus, unit2, unit3,
30
 
  unit4, unit5, gettext, translations, process
31
 
  {$IFDEF TRANSLATESTRING}, DefaultTranslator{$ENDIF}, ExtCtrls, ComCtrls, MaskEdit, Spin,
32
 
  PoTranslator;
33
 
 
34
 
type
35
 
 
36
 
  { TfrmMain }
37
 
 
38
 
  TfrmMain = class(TForm)
39
 
    audbitrate: TEdit;
40
 
    audchannels: TEdit;
41
 
    audsamplingrate: TEdit;
42
 
    btnAdd: TBitBtn;
43
 
    btnOptions: TBitBtn;
44
 
    btnPreview: TBitBtn;
45
 
    categorybox: TComboBox;
46
 
    cbx2Pass: TCheckBox;
47
 
    cbxDeinterlace: TCheckBox;
48
 
    btnClear: TBitBtn;
49
 
    ChooseFolderBtn: TButton;
50
 
    commandlineparams: TEdit;
51
 
    DestFolder: TEdit;
52
 
    edtAspectRatio: TEdit;
53
 
    edtAudioSync: TEdit;
54
 
    edtCropBottom: TEdit;
55
 
    edtCropLeft: TEdit;
56
 
    edtCropRight: TEdit;
57
 
    edtCropTop: TEdit;
58
 
    edtSeekHH: TSpinEdit;
59
 
    edtSeekMM: TSpinEdit;
60
 
    edtSeekSS: TSpinEdit;
61
 
    edtTTRHH: TSpinEdit;
62
 
    edtTTRMM: TSpinEdit;
63
 
    edtTTRSS: TSpinEdit;
64
 
    edtVolume: TEdit;
65
 
    gbxSettings: TGroupBox;
66
 
    grpOutputSettings: TGroupBox;
67
 
    Label1: TLabel;
68
 
    Label10: TLabel;
69
 
    Label11: TLabel;
70
 
    Label19: TLabel;
71
 
    Label20: TLabel;
72
 
    Label21: TLabel;
73
 
    label22: TLabel;
74
 
    label23: TLabel;
75
 
    label24: TLabel;
76
 
    Label3: TLabel;
77
 
    Label7: TLabel;
78
 
    Label8: TLabel;
79
 
    Label9: TLabel;
80
 
    lblAspectRatio: TLabel;
81
 
    lblCropBottom: TLabel;
82
 
    lblCropLeft: TLabel;
83
 
    lblCropRight: TLabel;
84
 
    //label22: TLabel;
85
 
    lblCropRight2: TLabel;
86
 
    lblCropTop: TLabel;
87
 
    lblFrameRate: TLabel;
88
 
    lblVideoBitRate: TLabel;
89
 
    lblVideoSize: TLabel;
90
 
//    mitPlaySoundonFinish: TMenuItem;
91
 
    mitDisplayCmdline: TMenuItem;
92
 
    dlgOpenFile: TOpenDialog;
93
 
    filelist: TListBox;
94
 
    Label2: TLabel;
95
 
    mitDocs: TMenuItem;
96
 
    mitAbout: TMenuItem;
97
 
    mnuHelp: TMenuItem;
98
 
    mitWinff: TMenuItem;
99
 
    mitForums: TMenuItem;
100
 
    MenuItem9: TMenuItem;
101
 
    dlgOpenPreset: TOpenDialog;
102
 
    nbkSettings: TNotebook;
103
 
    Panel1: TPanel;
104
 
    Panel10: TPanel;
105
 
    Panel11: TPanel;
106
 
    Panel12: TPanel;
107
 
    Panel13: TPanel;
108
 
    Panel14: TPanel;
109
 
    pnlSpacer: TPanel;
110
 
    Panel2: TPanel;
111
 
    Panel3: TPanel;
112
 
    Panel4: TPanel;
113
 
    Panel5: TPanel;
114
 
    Panel6: TPanel;
115
 
    Panel7: TPanel;
116
 
    Panel8: TPanel;
117
 
    Panel9: TPanel;
118
 
    PresetBox: TComboBox;
119
 
    StatusBar1: TStatusBar;
120
 
    pnlTop: TPanel;
121
 
    btnPlay: TBitBtn;
122
 
    pnlbottom: TPanel;
123
 
    pnlAdditionalOptions: TPanel;
124
 
    pnlMain: TPanel;
125
 
    mitPauseOnFinish: TMenuItem;
126
 
    mitPlaySoundOnFinish: TMenuItem;
127
 
    btnRemove: TBitBtn;
128
 
    mitShutdownOnFinish: TMenuItem;
129
 
    mnuEdit: TMenuItem;
130
 
    mitExit: TMenuItem;
131
 
    mitPresets: TMenuItem;
132
 
    mitPreferences: TMenuItem;
133
 
    mitImportPreset: TMenuItem;
134
 
    mitShowOptions: TMenuItem;
135
 
    mnuOptions: TMenuItem;
136
 
    mnuFile: TMenuItem;
137
 
    MainMenu1: TMainMenu;
138
 
    //dlgOpenFile: TOpenDialog;
139
 
    SelectDirectoryDialog1: TSelectDirectoryDialog;
140
 
    btnConvert: TBitBtn;
141
 
    tabAudioSettings: TPage;
142
 
    tabCmdLineSettings: TPage;
143
 
    tabPageCrop: TPage;
144
 
    tabPageTime: TPage;
145
 
    tabVideoSettings: TPage;
146
 
    UpDown1: TUpDown;
147
 
    UpDown10: TUpDown;
148
 
    UpDown2: TUpDown;
149
 
    UpDown3: TUpDown;
150
 
    UpDown4: TUpDown;
151
 
    UpDown6: TUpDown;
152
 
    UpDown7: TUpDown;
153
 
    Vidbitrate: TEdit;
154
 
    Vidframerate: TEdit;
155
 
    VidsizeX: TEdit;
156
 
    VidsizeY: TEdit;
157
 
 
158
 
    procedure btnPreviewClick(Sender: TObject);
159
 
    procedure Button1Click(Sender: TObject);
160
 
    procedure categoryboxChange(Sender: TObject);
161
 
    procedure edtCropBottomChange(Sender: TObject);
162
 
    procedure edtCropLeftChange(Sender: TObject);
163
 
    procedure edtCropRightChange(Sender: TObject);
164
 
    procedure edtCropTopChange(Sender: TObject);
165
 
    procedure edtSeekMMChange(Sender: TObject);
166
 
    procedure filelistKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
167
 
    procedure LaunchBrowser(URL:string);
168
 
    procedure LaunchPdf(pdffile:string);
169
 
    procedure ChooseFolderBtnClick(Sender: TObject);
170
 
    procedure btnAddClick(Sender: TObject);
171
 
    procedure btnClearClick(Sender: TObject);
172
 
    procedure lblCropRight1Click(Sender: TObject);
173
 
    procedure edtSeekHHChange(Sender: TObject);
174
 
    procedure mitDisplayCmdlineClick(Sender: TObject);
175
 
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
176
 
    procedure FormCreate(Sender: TObject);
177
 
    procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
178
 
    procedure mitImportPresetClick(Sender: TObject);
179
 
    procedure mitAboutClick(Sender: TObject);
180
 
    procedure MenuItem2Click(Sender: TObject);
181
 
    procedure mitExitClick(Sender: TObject);
182
 
    procedure mitPlaySoundonFinishClick(Sender: TObject);
183
 
    procedure mitPresetsClick(Sender: TObject);
184
 
    procedure mitPreferencesClick(Sender: TObject);
185
 
    procedure mitDocsClick(Sender: TObject);
186
 
    procedure mitForumsClick(Sender: TObject);
187
 
    procedure mitWinffClick(Sender: TObject);
188
 
    procedure mitPauseOnFinishClick(Sender: TObject);
189
 
    procedure btnPlayClick(Sender: TObject);
190
 
    procedure btnRemoveClick(Sender: TObject);
191
 
    function GetDeskTopPath() : string;
192
 
    function GetMydocumentsPath() : string ;
193
 
    procedure PresetBoxChange(Sender: TObject);
194
 
    procedure setconfigvalue(key:string;value:string);
195
 
    function getconfigvalue(key:string):string;
196
 
    procedure populatepresetbox(selectedcategory:string);
197
 
    function getcurrentpresetname(currentpreset:string):string;
198
 
    function getpresetparams(presetname:string):string;
199
 
    function getpresetcategory(presetname:string):string;
200
 
    function getpresetextension(presetname:string):string;
201
 
    procedure mitShowOptionsClick(Sender: TObject);
202
 
    procedure mitShutdownOnFinishClick(Sender: TObject);
203
 
    procedure btnConvertClick(Sender: TObject);
204
 
    procedure importpresetfromfile(presetfilename: string);
205
 
    function GetappdataPath() : string ;
206
 
    function replaceparam(commandline:string;param:string;replacement:string):string;
207
 
    procedure VidbitrateChange(Sender: TObject);
208
 
    {$IFDEF WIN32}function GetWin32System(): Integer;{$endif}
209
 
 
210
 
  private
211
 
    { private declarations }
212
 
 
213
 
  public
214
 
    { public declarations }
215
 
 
216
 
  end; 
217
 
 
218
 
 
219
 
{$IFDEF WIN32}
220
 
const
221
 
  shfolder = 'ShFolder.dll';
222
 
  { win32 custom directory constants }
223
 
  CSIDL_PERSONAL: longint = $0005;
224
 
  CSIDL_DESKTOPDIRECTORY: longint = $0010;
225
 
  CSIDL_APPDATA: longint = $001a;
226
 
  { win32 operating system (OS)constants }
227
 
  cOsUnknown: Integer = -1;
228
 
  cOsWin95:   Integer =  0;
229
 
  cOsWin98:   Integer =  1;
230
 
  cOsWin98SE: Integer =  2;
231
 
  cOsWinME:   Integer =  3;
232
 
  cOsWinNT:   Integer =  4;
233
 
  cOsWin2000: Integer =  5;
234
 
  cOsXP:      Integer =  6;
235
 
{$ENDIF}
236
 
 
237
 
var
238
 
  frmMain: TfrmMain;
239
 
  {$IFDEF WIN32}
240
 
  PIDL : PItemIDList;
241
 
  ansicodepage: longint;
242
 
  usechcp: string;
243
 
  {$ENDIF}
244
 
  extraspath: string;
245
 
  lastpreset: string;
246
 
  presetsfile: Txmldocument;
247
 
  presetspath: string;
248
 
  configpath: string;
249
 
  presets: tdomnode;
250
 
  ffmpeg: string;
251
 
  ffplay: string;
252
 
  terminal: string;
253
 
  termoptions: string;
254
 
  rememberlast: string;
255
 
  insertpoint: string;
256
 
  showopts: string;
257
 
  rememberpreset: string;
258
 
  pass2encoding: string ;
259
 
  pausescript: string;
260
 
  playscript: string;
261
 
  multithreading: string;
262
 
  PODirectory, Lang, FallbackLang, POFile: String;
263
 
  preview: boolean;
264
 
  Resourcestring
265
 
 
266
 
  //messages
267
 
  rsCouldNotFindPresetFile = 'Could not find presets file.';
268
 
  rsCouldNotFindFFmpeg = 'Could not find FFmpeg.';
269
 
  rsCouldNotFindFFplay = 'Could not find FFPlay.';
270
 
  rsSelectVideoFiles = 'Select Video Files';
271
 
  rsSelectPresetFile = 'Select Preset File';
272
 
  rsPleaseSelectAPreset = 'Please select a preset';
273
 
  rsPleaseAdd1File = 'Please add at least 1 file to convert';
274
 
  rsConverting = 'Converting';
275
 
  rsPressEnter = 'Press Enter to Continue';
276
 
  rsCouldNotFindFile = 'Could Not Find File';
277
 
  rsInvalidPreset = 'Invalid Preset File';
278
 
  rsPresetAlreadyExist = 'Preset: %s%s%s already exists';
279
 
  rsPresetHasNoLabel = 'The preset to import does not have a label';
280
 
  rsThePresetHasIllegalChars = 'The preset contains illegal characters';
281
 
  rsPresetWithLabelExists = 'Preset with label: %s%s%s already exists';
282
 
  rsPresethasnoExt = 'The preset to import does not have an extension';
283
 
  rsNameMustBeAllpha = 'Name Must be alphanumeric (a-z,A-Z,0-9)';
284
 
  rsExtensionnoperiod = 'Extension can not contain a period';
285
 
  rsFileDoesNotExist = 'file does not exist';
286
 
  rsPresettoExport = 'Please select a preset to export';
287
 
  rsSelectDirectory = 'Select Directory';
288
 
 
289
 
implementation
290
 
 
291
 
 
292
 
// Initialize everything
293
 
procedure TfrmMain.FormCreate(Sender: TObject);
294
 
var
295
 
f1,f2:textfile;
296
 
ch: char;
297
 
i:integer;
298
 
formheight,formwidth,formtop,formleft:integer;
299
 
sformheight,sformwidth,sformtop,sformleft:string;
300
 
currentpreset, destdir: string;
301
 
 
302
 
begin
303
 
   ExtrasPath:= ExtractFilePath(ParamStr(0));
304
 
 
305
 
 
306
 
               // do translations
307
 
   TranslateUnitResourceStrings('unit1', PODirectory + 'winff.%s.po', Lang, FallbackLang);
308
 
 
309
 
                    // start setup
310
 
  {$IFDEF WIN32}
311
 
  ansicodepage:=getacp();
312
 
  presetspath :=GetappdataPath() + '\Winff\';
313
 
 
314
 
  if not DirectoryExists(presetspath) then
315
 
    createdir(presetspath);
316
 
    
317
 
  ffmpeg := getconfigvalue('win32/ffmpeg');
318
 
  if ffmpeg = '' then
319
 
     begin
320
 
       ffmpeg := extraspath + 'ffmpeg.exe';
321
 
       setconfigvalue('win32/ffmpeg',ffmpeg);
322
 
     end;
323
 
 
324
 
  ffplay := getconfigvalue('win32/ffplay');
325
 
   if ffplay = '' then
326
 
     begin
327
 
       ffplay := extraspath + 'ffplay.exe';
328
 
       setconfigvalue('win32/ffplay',ffplay);
329
 
     end;
330
 
 
331
 
  if (GetWIn32System >=0) and (GetWIn32System <4)
332
 
      then
333
 
        terminal:='command.com'
334
 
      else
335
 
        terminal:='cmd.exe';
336
 
  termoptions := '/c';
337
 
  
338
 
  usechcp:= getconfigvalue('win32/chcp');
339
 
  if usechcp = '' then
340
 
     begin
341
 
       usechcp := 'true';
342
 
       setconfigvalue('win32/chcp','true');
343
 
     end;
344
 
 
345
 
  {$endif}
346
 
 
347
 
  {$IFDEF UNIX}
348
 
  presetbox.Height:=30;
349
 
  categorybox.Height:=30;
350
 
 
351
 
  extraspath:='/usr/share/winff/';
352
 
  if not directoryexists(extraspath) then
353
 
     ExtrasPath:= ExtractFilePath(ParamStr(0));
354
 
     
355
 
  presetspath := GetMydocumentsPath() + '/.winff/';
356
 
 
357
 
  if not DirectoryExists(presetspath) then
358
 
    createdir(presetspath);
359
 
    
360
 
  ffmpeg := getconfigvalue('unix/ffmpeg');
361
 
  if ffmpeg = '' then
362
 
     begin
363
 
       ffmpeg := '/usr/bin/ffmpeg';
364
 
       if not fileexists(ffmpeg) then
365
 
         if fileexists('/usr/local/bin/ffmpeg') then
366
 
            ffmpeg := '/usr/local/bin/ffmpeg'
367
 
         else
368
 
            showmessage(rsCouldNotFindFFmpeg);
369
 
       setconfigvalue('unix/ffmpeg',ffmpeg)
370
 
     end;
371
 
     
372
 
  ffplay := getconfigvalue('unix/ffplay');
373
 
  if ffplay = '' then
374
 
     begin
375
 
       ffplay := '/usr/bin/ffplay';
376
 
       if not fileexists(ffplay) then
377
 
         if fileexists('/usr/local/bin/ffplay') then
378
 
            ffplay := '/usr/local/bin/ffplay'
379
 
         else
380
 
            showmessage(rsCouldNotFindFFPlay);
381
 
       setconfigvalue('unix/ffplay',ffplay);
382
 
     end;
383
 
     
384
 
  terminal := getconfigvalue('unix/terminal');
385
 
  if terminal = '' then
386
 
     begin
387
 
       terminal := '/usr/bin/xterm';
388
 
       if fileexists('/usr/bin/gnome-terminal') then terminal:='/usr/bin/gnome-terminal';
389
 
       if fileexists('/usr/bin/x-terminal-emulator') then terminal:='/usr/bin/x-terminal-emulator';
390
 
       setconfigvalue('unix/terminal',terminal);
391
 
     end;
392
 
 
393
 
  termoptions := getconfigvalue('unix/termoptions');
394
 
  if termoptions = '' then
395
 
     begin
396
 
       termoptions := '-e';
397
 
       if terminal = '/usr/bin/gnome-terminal' then termoptions := '-x';
398
 
       setconfigvalue('unix/termoptions',termoptions);
399
 
     end;
400
 
  {$ENDIF}
401
 
 
402
 
 
403
 
          // prepare preset
404
 
 
405
 
  if (not fileexists(presetspath + 'presets.xml')) and (fileexists(extraspath + directoryseparator +'presets.xml')) then
406
 
     begin
407
 
      AssignFile(F1, extraspath + directoryseparator +'presets.xml');
408
 
      Reset(F1);
409
 
      AssignFile(F2, presetspath + 'presets.xml');
410
 
      Rewrite(F2);
411
 
      while not Eof(F1) do
412
 
        begin
413
 
          Read(F1, Ch);
414
 
          Write(F2, Ch);
415
 
        end;
416
 
      CloseFile(F2);
417
 
      CloseFile(F1);
418
 
     end;
419
 
 
420
 
  if not fileexists(presetspath + 'presets.xml') then
421
 
     begin
422
 
     showmessage(rsCouldNotFindPresetFile);
423
 
     frmMain.close;
424
 
     end;
425
 
 
426
 
  presetsfile.Create;                         // load the presets file
427
 
  try
428
 
   ReadXMLFile(presetsfile, presetspath+'presets.xml');
429
 
   presets:=presetsfile.DocumentElement;
430
 
  except
431
 
   showmessage(rsCouldNotFindPresetFile);
432
 
   frmMain.close;
433
 
  end;
434
 
                                      // import preset from command line
435
 
  if upcase(rightstr(paramstr(1),4)) = '.WFF' then
436
 
   begin
437
 
   importpresetfromfile(paramstr(1));
438
 
   end;
439
 
 
440
 
                                // fill combobox with presets
441
 
  rememberpreset:=getconfigvalue('general/currentpreset');
442
 
  currentpreset:=getcurrentpresetname(rememberpreset);
443
 
  populatepresetbox(getpresetcategory(currentpreset));
444
 
  for i:= 0 to  presetbox.items.Count - 1 do
445
 
    begin
446
 
     if presetbox.Items[i]=rememberpreset then
447
 
        begin
448
 
        presetbox.ItemIndex:=i;
449
 
        break;
450
 
        end;
451
 
    end;
452
 
                                          // set window size and position
453
 
  showopts:=getconfigvalue('general/showoptions');
454
 
  sformheight:=getconfigvalue('window/height');
455
 
  sformwidth:=getconfigvalue('window/width');
456
 
  sformtop:=getconfigvalue('window/top');
457
 
  sformleft:=getconfigvalue('window/left');
458
 
 
459
 
  formtop := 0;
460
 
  if sformtop <> '' then formtop:=strtoint(sformtop);
461
 
  if formtop > 0 then frmMain.Top := formtop;
462
 
 
463
 
  formleft := 0;
464
 
  if sformleft <> '' then formleft:=strtoint(sformleft);
465
 
  if formleft >0 then frmMain.Left := formleft;
466
 
 
467
 
  if sformheight = '' then formheight:=400
468
 
  else formheight := strtoint(sformheight);
469
 
 
470
 
  if sformwidth = '' then formwidth:=400
471
 
  else formwidth := strtoint(sformwidth);
472
 
 
473
 
  if formheight<400 then formheight:=400;
474
 
  if formwidth<400 then formheight:=400;
475
 
  if showopts='' then showopts:='false';
476
 
  if showopts='true' then
477
 
        begin
478
 
        mitShowOptions.Checked:=true;
479
 
        pnlAdditionalOptions.Visible :=true;
480
 
        frmMain.height := formheight;
481
 
        frmMain.width := formwidth;
482
 
        frmMain.invalidate;
483
 
        end
484
 
  else
485
 
        begin
486
 
        mitShowOptions.Checked:=false;
487
 
        pnlAdditionalOptions.Visible :=false;
488
 
        frmMain.height := formheight;
489
 
        frmMain.width := formwidth;
490
 
        frmMain.invalidate;
491
 
        end;
492
 
 
493
 
 
494
 
  destfolder.text := getconfigvalue('general/destfolder');   // get destination folder
495
 
  if destfolder.text='' then DestFolder.Text:= getmydocumentspath();
496
 
  rememberlast := getconfigvalue('general/rememberlast');
497
 
 
498
 
 
499
 
                                         // check 2 pass encoding
500
 
  pass2encoding:=getconfigvalue('general/pass2');
501
 
  if pass2encoding='' then cbx2Pass.checked:=false;
502
 
  if pass2encoding='true' then cbx2Pass.checked:=true;
503
 
  
504
 
                                      // check pause before finished
505
 
  pausescript:=getconfigvalue('general/pause');
506
 
  if pausescript='' then
507
 
    begin
508
 
     pausescript:= 'true';
509
 
     setconfigvalue('general/pause',pausescript);
510
 
    end;
511
 
  if pausescript='true' then
512
 
     mitPauseOnFinish.Checked:=true
513
 
  else
514
 
     mitPauseOnFinish.Checked:=false;
515
 
 
516
 
  playscript:=getconfigvalue('general/playsound');
517
 
  if playscript='' then
518
 
    begin
519
 
     playscript:= 'true';
520
 
     setconfigvalue('general/playsound',playscript);
521
 
    end;
522
 
  if playscript='true' then
523
 
     mitplaysoundOnFinish.Checked:=true
524
 
  else
525
 
     mitplaysoundOnFinish.Checked:=false;
526
 
 
527
 
 
528
 
 
529
 
                                        // check for multithreading
530
 
  multithreading:=getconfigvalue('general/multithreading');
531
 
 
532
 
 
533
 
end;
534
 
 
535
 
 
536
 
// clean up and shut down
537
 
procedure TfrmMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
538
 
var
539
 
s:string;
540
 
begin
541
 
  if rememberlast = 'true' then   // save destination folder
542
 
     setconfigvalue('general/destfolder',destfolder.text);
543
 
 
544
 
  s := presetbox.text;   // save default preset
545
 
  if s <> '' then setconfigvalue('general/currentpreset',s);
546
 
 
547
 
  if mitShowOptions.Checked then // save show mnuOptions
548
 
     setconfigvalue('general/showoptions','true')
549
 
  else
550
 
     setconfigvalue('general/showoptions','false');
551
 
 
552
 
  if mitPauseOnFinish.Checked then // save pause on finish
553
 
     setconfigvalue('general/pause','true')
554
 
  else
555
 
     setconfigvalue('general/pause','false');
556
 
 
557
 
 
558
 
  if mitPlaySoundOnFinish.Checked then // save pause on finish
559
 
     setconfigvalue('general/playsound','true')
560
 
  else
561
 
     setconfigvalue('general/playsound','false');
562
 
 
563
 
 
564
 
  if cbx2Pass.Checked then // save 2 pass
565
 
     setconfigvalue('general/pass2','true')
566
 
  else
567
 
     setconfigvalue('general/pass2','false');
568
 
 
569
 
     // save window position and size
570
 
  setconfigvalue('window/height',inttostr(frmMain.height));
571
 
  setconfigvalue('window/width',inttostr(frmMain.width));
572
 
  setconfigvalue('window/top',inttostr(frmMain.Top));
573
 
  setconfigvalue('window/left',inttostr(frmMain.Left));
574
 
 
575
 
  presetsfile.Free;           // cleanup
576
 
 
577
 
end;
578
 
 
579
 
// get the params from the preset
580
 
function TfrmMain.getpresetparams(presetname:string):string;
581
 
var
582
 
paramnode : tdomnode;
583
 
param:string;
584
 
begin
585
 
   try
586
 
    if presets.FindNode(presetname).FindNode('params').HasChildNodes then
587
 
    begin
588
 
      paramnode:=presets.FindNode(presetname).FindNode('params').FindNode('#text');
589
 
      param:=paramnode.NodeValue;
590
 
    end
591
 
   except
592
 
    param:='';
593
 
   end;
594
 
   result:=param;
595
 
end;
596
 
 
597
 
// get the category from the preset
598
 
function TfrmMain.getpresetcategory(presetname:string):string;
599
 
var
600
 
catnode : tdomnode;
601
 
category:string;
602
 
begin
603
 
 result := '';
604
 
 if presetname <> '' then
605
 
 begin
606
 
   try
607
 
    if presets.FindNode(presetname).FindNode('category').HasChildNodes then
608
 
    begin
609
 
      catnode:=presets.FindNode(presetname).FindNode('category').FindNode('#text');
610
 
      category:=catnode.NodeValue;
611
 
    end
612
 
   except
613
 
    category:='';
614
 
   end;
615
 
   result:=category;
616
 
 end;
617
 
end;
618
 
 
619
 
// get the extension of the preset
620
 
function TfrmMain.getpresetextension(presetname:string):string;
621
 
begin
622
 
   result:=presets.FindNode(presetname).FindNode('extension').FindNode('#text').NodeValue;
623
 
end;
624
 
 
625
 
 
626
 
// get the name of the selected preset
627
 
function TfrmMain.getcurrentpresetname(currentpreset:string):string;
628
 
var
629
 
i:integer;
630
 
node,subnode: tdomnode;
631
 
begin
632
 
   for i:= 0 to presets.childnodes.count -1 do
633
 
   begin
634
 
     node := presets.childnodes.item[i];
635
 
     subnode:= node.FindNode('label');
636
 
     if currentpreset = subnode.findnode('#text').nodevalue then
637
 
       result := node.nodename;
638
 
   end;
639
 
end;
640
 
 
641
 
 
642
 
// clear and load the preset box with current list
643
 
procedure TfrmMain.populatepresetbox(selectedcategory:string);
644
 
var
645
 
i,j:integer;
646
 
ispresent: boolean;
647
 
node,subnode, catnode,catsubnode : tdomnode;
648
 
category,presetcategory: string;
649
 
begin
650
 
   selectedcategory:=trim(selectedcategory);
651
 
   categorybox.Clear;
652
 
   categorybox.items.add('------');
653
 
   for i:= 0 to presets.ChildNodes.Count -1  do
654
 
     begin
655
 
       try
656
 
         node:= presets.ChildNodes.item[i];
657
 
         subnode:= node.FindNode('category');
658
 
         category:=subnode.findnode('#text').NodeValue;
659
 
         category:=trim(category)
660
 
       except
661
 
         category:='';
662
 
       end;
663
 
       ispresent:=false;
664
 
       for j:= 0 to categorybox.Items.Count-1 do
665
 
          if categorybox.Items[j]=category then
666
 
             ispresent:=true;
667
 
       if not ispresent then
668
 
          categorybox.Items.Add(category);
669
 
     end;
670
 
 
671
 
 
672
 
 
673
 
   for I:= 0 to categorybox.Items.Count -1 do
674
 
       if categorybox.items[i]=selectedcategory then
675
 
          begin
676
 
          categorybox.ItemIndex:=i;
677
 
          break;
678
 
          end;
679
 
 
680
 
 
681
 
   presetbox.Clear;
682
 
   if selectedcategory='------' then
683
 
      category:=''
684
 
   else
685
 
      category:=trim(categorybox.Text);
686
 
      
687
 
   for i:= 0 to presets.ChildNodes.Count -1  do
688
 
   begin
689
 
      try
690
 
        node:= presets.ChildNodes.item[i];
691
 
        subnode:= node.FindNode('label');
692
 
        catnode:= presets.ChildNodes.item[i];
693
 
        catsubnode:= catnode.FindNode('category');
694
 
        presetcategory:=catsubnode.FindNode('#text').NodeValue;
695
 
      except
696
 
        presetcategory:='';
697
 
      end;
698
 
      if category = '' then
699
 
         try
700
 
         presetbox.items.add(subnode.findnode('#text').NodeValue)
701
 
         except
702
 
         end
703
 
      else
704
 
         if (presetcategory = category) then
705
 
            try
706
 
            presetbox.items.add(subnode.findnode('#text').NodeValue);
707
 
            except
708
 
            end;
709
 
   end;
710
 
   presetbox.sorted:=true;
711
 
   presetbox.sorted:=false;
712
 
end;
713
 
 
714
 
// change category
715
 
procedure TfrmMain.categoryboxChange(Sender: TObject);
716
 
var
717
 
i:integer;
718
 
node,subnode, catnode,catsubnode : tdomnode;
719
 
selectedcategory, category,presetcategory: string;
720
 
 
721
 
begin
722
 
   selectedcategory:=categorybox.Text;
723
 
 
724
 
   presetbox.Clear;
725
 
   if selectedcategory='------' then
726
 
      category:=''
727
 
   else
728
 
      category:=trim(categorybox.Text);
729
 
  try
730
 
    for i:= 0 to presets.ChildNodes.Count -1  do
731
 
     begin
732
 
        try
733
 
        node:= presets.ChildNodes.item[i];
734
 
        subnode:= node.FindNode('label');
735
 
 
736
 
        catnode:= presets.ChildNodes.item[i];
737
 
        catsubnode:= catnode.FindNode('category');
738
 
        presetcategory:=catsubnode.FindNode('#text').NodeValue;
739
 
        except
740
 
        presetcategory:='';
741
 
        end;
742
 
        try
743
 
          if category = '' then
744
 
             presetbox.items.add(subnode.findnode('#text').NodeValue)
745
 
          else
746
 
             if (presetcategory = category) then
747
 
                presetbox.items.add(subnode.findnode('#text').NodeValue);
748
 
        except
749
 
        end;
750
 
     end;
751
 
  finally
752
 
  end;
753
 
  presetbox.sorted:=true;
754
 
  presetbox.sorted:=false;
755
 
end;
756
 
 
757
 
// cropbootom change
758
 
procedure TfrmMain.edtCropBottomChange(Sender: TObject);
759
 
var
760
 
i:integer;
761
 
begin
762
 
 try
763
 
 i:=strtoint(edtcropbottom.text);
764
 
 except
765
 
 edtcropbottom.text:='0';
766
 
 end;
767
 
 i:=i;
768
 
end;
769
 
 
770
 
// cropleft change
771
 
procedure TfrmMain.edtCropLeftChange(Sender: TObject);
772
 
var
773
 
i:integer;
774
 
begin
775
 
 try
776
 
 i:=strtoint(edtcropleft.text);
777
 
 except
778
 
 edtcropleft.text:='0';
779
 
 end;
780
 
 i:=i;
781
 
end;
782
 
 
783
 
// cropright change
784
 
procedure TfrmMain.edtCropRightChange(Sender: TObject);
785
 
var
786
 
i:integer;
787
 
begin
788
 
 try
789
 
 i:=strtoint(edtcropright.text);
790
 
 except
791
 
 edtcropright.text:='0';
792
 
 end;
793
 
 i:=i;
794
 
end;
795
 
 
796
 
// croptop change
797
 
procedure TfrmMain.edtCropTopChange(Sender: TObject);
798
 
var
799
 
i:integer;
800
 
begin
801
 
 try
802
 
 i:=strtoint(edtcroptop.text);
803
 
 except
804
 
 edtcroptop.text:='0';
805
 
 end;
806
 
 i:=i;
807
 
end;
808
 
 
809
 
procedure TfrmMain.edtSeekMMChange(Sender: TObject);
810
 
begin
811
 
end;
812
 
 
813
 
procedure TfrmMain.Button1Click(Sender: TObject);
814
 
begin
815
 
end;
816
 
// preview button clicked
817
 
procedure TfrmMain.btnPreviewClick(Sender: TObject);
818
 
begin
819
 
preview := true;
820
 
btnConvertClick(Self);
821
 
end;
822
 
 
823
 
// change preset
824
 
procedure TfrmMain.PresetBoxChange(Sender: TObject);
825
 
var
826
 
destdir: string;
827
 
currentpreset:string;
828
 
begin
829
 
currentpreset := getcurrentpresetname(presetbox.Text);
830
 
   destdir := '' ;
831
 
//  destdir:= getpresetdestdir(currentpreset);     // get dest folder from preset
832
 
if destdir <> '' then destfolder.text:= destdir;
833
 
if destfolder.Text='' then destfolder.text := getconfigvalue('general/destfolder');
834
 
if destfolder.text='' then DestFolder.Text:= getmydocumentspath();
835
 
end;
836
 
 
837
 
 
838
 
// launch browser
839
 
procedure TfrmMain.launchbrowser(URL:string);
840
 
{$IFDEF linux}
841
 
var
842
 
launcher:tprocess;
843
 
s:string;
844
 
{$endif}
845
 
begin
846
 
  {$ifdef linux}
847
 
  s:='';
848
 
  if fileexists('/usr/bin/konqueror') then s:='/usr/bin/konqueror';
849
 
  if fileexists('/usr/bin/mozilla-firefox') then s:='/usr/bin/mozilla-firefox';
850
 
  if fileexists('/usr/bin/firefox') then s:='/usr/bin/firefox';
851
 
  if fileexists('/usr/bin/sensible-browser') then s:='/usr/bin/sensible-browser';
852
 
  if s='' then
853
 
     begin
854
 
     Showmessage('More information can be found at ' + URL);
855
 
     exit;
856
 
     end;
857
 
 
858
 
  launcher := tprocess.Create(nil);
859
 
  launcher.CommandLine:= s + ' ' + URL;
860
 
  launcher.Execute;
861
 
  launcher.free;
862
 
  {$endif}
863
 
 
864
 
  {$ifdef win32}
865
 
  ShellExecute(self.Handle,'open',PChar(URL),nil,nil, SW_SHOWNORMAL);
866
 
  {$endif}
867
 
end;
868
 
 
869
 
// launch pdf
870
 
procedure TfrmMain.LaunchPdf(pdffile:string);
871
 
{$IFDEF linux}
872
 
var
873
 
launcher:tprocess;
874
 
s:string;
875
 
{$endif}
876
 
begin
877
 
  {$ifdef linux}
878
 
  s:='';
879
 
  if fileexists('/usr/bin/evince') then s:='/usr/bin/evince';
880
 
  if fileexists('/usr/bin/kpdf') then s:='/usr/bin/kpdf';
881
 
  if fileexists('/usr/bin/xpdf') then s:='/usr/bin/xpdf';
882
 
  if fileexists('/usr/bin/acroread') then s:='/usr/bin/acroread';
883
 
  if s='' then
884
 
     begin
885
 
     Showmessage('More information can be found at ' + pdffile);
886
 
     exit;
887
 
     end;
888
 
 
889
 
  launcher := tprocess.Create(nil);
890
 
  launcher.CommandLine:= s + ' ' + pdffile;
891
 
  launcher.Execute;
892
 
  launcher.free;
893
 
  {$endif}
894
 
 
895
 
  {$ifdef win32}
896
 
  ShellExecute(self.Handle,'open',PChar(pdffile),nil,nil, SW_SHOWNORMAL);
897
 
  {$endif}
898
 
end;
899
 
 
900
 
// set a value in the config file
901
 
procedure TfrmMain.setconfigvalue(key:string;value:string);
902
 
var
903
 
cfg: TXMLConfig;
904
 
begin
905
 
 cfg := TXMLConfig.create(presetspath+'cfg.xml');
906
 
 cfg.SetValue(key,value);
907
 
 cfg.free;
908
 
end;
909
 
 
910
 
// get a value from the config file
911
 
function TfrmMain.getconfigvalue(key:string): string;
912
 
var
913
 
cfg: TXMLConfig;
914
 
begin
915
 
 cfg := TXMLConfig.create(presetspath+'cfg.xml');
916
 
 result := cfg.GetValue(key, '');
917
 
 cfg.free;
918
 
end;
919
 
 
920
 
// get the user's desktop path
921
 
function TfrmMain.GetDeskTopPath() : string ;
922
 
{$ifdef win32}
923
 
var
924
 
  ppidl: PItemIdList;
925
 
begin
926
 
  ppidl := nil;
927
 
  SHGetSpecialFolderLocation(frmMain.Handle,CSIDL_DESKTOPDIRECTORY , ppidl);
928
 
  SetLength(Result, MAX_PATH);
929
 
   if not SHGetPathFromIDList(ppidl, PChar(Result)) then
930
 
        raise exception.create('SHGetPathFromIDList failed : invalid pidl');
931
 
   SetLength(Result, lStrLen(PChar(Result)));
932
 
end;
933
 
{$endif}
934
 
{$ifdef unix}
935
 
begin
936
 
 result := GetEnvironmentVariable('HOME') + DirectorySeparator  + 'Desktop';
937
 
end;
938
 
{$endif}
939
 
 
940
 
// get the user's document's path
941
 
function TfrmMain.GetMydocumentsPath() : string ;
942
 
{$ifdef win32}
943
 
var
944
 
  ppidl: PItemIdList;
945
 
begin
946
 
  ppidl := nil;
947
 
  SHGetSpecialFolderLocation(frmMain.Handle,CSIDL_PERSONAL , ppidl);
948
 
  SetLength(Result, MAX_PATH);
949
 
   if not SHGetPathFromIDList(ppidl, PChar(Result)) then
950
 
        raise exception.create('SHGetPathFromIDList failed : invalid pidl');
951
 
   SetLength(Result, lStrLen(PChar(Result)));
952
 
end;
953
 
{$endif}
954
 
{$ifdef unix}
955
 
begin
956
 
 result := GetEnvironmentVariable('HOME') ;
957
 
end;
958
 
{$endif}
959
 
 
960
 
// get the user's application data path
961
 
function TfrmMain.GetappdataPath() : string ;
962
 
{$ifdef win32}
963
 
var
964
 
  ppidl: PItemIdList;
965
 
begin
966
 
  ppidl := nil;
967
 
  SHGetSpecialFolderLocation(frmMain.Handle,CSIDL_APPDATA , ppidl);
968
 
  SetLength(Result, MAX_PATH);
969
 
   if not SHGetPathFromIDList(ppidl, PChar(Result)) then
970
 
        raise exception.create('SHGetPathFromIDList failed : invalid pidl');
971
 
   SetLength(Result, lStrLen(PChar(Result)));
972
 
end;
973
 
{$endif}
974
 
{$ifdef unix}
975
 
begin
976
 
 result := GetEnvironmentVariable('HOME') ;
977
 
end;
978
 
{$endif}
979
 
 
980
 
// get windows version
981
 
{$ifdef win32}
982
 
function TfrmMain.GetWIn32System(): Integer;
983
 
var
984
 
  osVerInfo: TOSVersionInfo;
985
 
  majorVer, minorVer: Integer;
986
 
begin
987
 
  Result := cOsUnknown;
988
 
  { set operating system type flag }
989
 
  osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
990
 
  if GetVersionEx(osVerInfo) then
991
 
  begin
992
 
    majorVer := osVerInfo.dwMajorVersion;
993
 
    minorVer := osVerInfo.dwMinorVersion;
994
 
    case osVerInfo.dwPlatformId of
995
 
      VER_PLATFORM_WIN32_NT: { Windows NT/2000 }
996
 
        begin
997
 
          if majorVer <= 4 then
998
 
            Result := cOsWinNT
999
 
          else if (majorVer = 5) and (minorVer = 0) then
1000
 
            Result := cOsWin2000
1001
 
          else if (majorVer = 5) and (minorVer = 1) then
1002
 
            Result := cOsXP
1003
 
          else
1004
 
            Result := cOsUnknown;
1005
 
        end;
1006
 
      VER_PLATFORM_WIN32_WINDOWS:  { Windows 9x/ME }
1007
 
        begin
1008
 
          if (majorVer = 4) and (minorVer = 0) then
1009
 
            Result := cOsWin95
1010
 
          else if (majorVer = 4) and (minorVer = 10) then
1011
 
          begin
1012
 
            if osVerInfo.szCSDVersion[1] = 'A' then
1013
 
              Result := cOsWin98SE
1014
 
            else
1015
 
              Result := cOsWin98;
1016
 
          end
1017
 
          else if (majorVer = 4) and (minorVer = 90) then
1018
 
            Result := cOsWinME
1019
 
          else
1020
 
            Result := cOsUnknown;
1021
 
        end;
1022
 
      else
1023
 
        Result := cOsUnknown;
1024
 
    end;
1025
 
  end
1026
 
  else
1027
 
    Result := cOsUnknown;
1028
 
end;
1029
 
{$endif}
1030
 
 
1031
 
// choose a folder
1032
 
procedure TfrmMain.ChooseFolderBtnClick(Sender: TObject);
1033
 
begin
1034
 
  selectdirectorydialog1.Title:= rsSelectDirectory;
1035
 
  if SelectDirectoryDialog1.execute then
1036
 
     DestFolder.Text := SelectDirectoryDialog1.FileName;
1037
 
end;
1038
 
 
1039
 
 
1040
 
// drop files into list
1041
 
procedure TfrmMain.FormDropFiles(Sender: TObject; const FileNames: array of String
1042
 
  );
1043
 
var
1044
 
numfiles, i:integer;
1045
 
begin
1046
 
numfiles := high(Filenames);
1047
 
for i:= 0 to numfiles do
1048
 
   filelist.Items.add(Filenames[i]);
1049
 
end;
1050
 
 
1051
 
// add files to the list
1052
 
procedure TfrmMain.btnAddClick(Sender: TObject);
1053
 
begin
1054
 
   dlgOpenFile.Title:=rsSelectVideoFiles;
1055
 
   dlgOpenFile.InitialDir := getconfigvalue('general/addfilesfolder');
1056
 
   if dlgOpenFile.Execute then
1057
 
      begin
1058
 
       setconfigvalue('general/addfilesfolder',dlgOpenFile.InitialDir);
1059
 
       filelist.items.AddStrings(dlgOpenFile.Files);
1060
 
      end;
1061
 
end;
1062
 
 
1063
 
// remove a file from the list
1064
 
procedure TfrmMain.btnRemoveClick(Sender: TObject);
1065
 
var
1066
 
i: integer;
1067
 
begin
1068
 
  i:=0;
1069
 
  while i< filelist.Items.Count do
1070
 
    if filelist.Selected[i] then
1071
 
      filelist.Items.Delete(i)
1072
 
    else
1073
 
       i+=1;
1074
 
end;
1075
 
 
1076
 
// clear the file list
1077
 
procedure TfrmMain.btnClearClick(Sender: TObject);
1078
 
begin
1079
 
  filelist.Clear;
1080
 
end;
1081
 
 
1082
 
procedure TfrmMain.lblCropRight1Click(Sender: TObject);
1083
 
begin
1084
 
 
1085
 
end;
1086
 
 
1087
 
procedure TfrmMain.edtSeekHHChange(Sender: TObject);
1088
 
begin
1089
 
 
1090
 
end;
1091
 
 
1092
 
// filelist on key up
1093
 
procedure TfrmMain.filelistKeyUp(Sender: TObject; var Key: Word;
1094
 
  Shift: TShiftState);
1095
 
var
1096
 
i:integer;
1097
 
begin
1098
 
  // delete
1099
 
  if (key = 46) then
1100
 
   begin
1101
 
    i:=0;
1102
 
   while i< filelist.Items.Count do
1103
 
    if filelist.Selected[i] then
1104
 
     filelist.Items.Delete(i)
1105
 
    else
1106
 
       i+=1;
1107
 
   end;
1108
 
 
1109
 
end;
1110
 
 
1111
 
 
1112
 
 
1113
 
 
1114
 
// menu: edit the presets
1115
 
procedure TfrmMain.mitPresetsClick(Sender: TObject);
1116
 
begin
1117
 
  frmEditPresets.show;
1118
 
end;
1119
 
 
1120
 
// menu: edit preferences
1121
 
procedure TfrmMain.mitPreferencesClick(Sender: TObject);
1122
 
begin
1123
 
frmPreferences.show;
1124
 
end;
1125
 
 
1126
 
//menu: help documentation
1127
 
procedure TfrmMain.mitDocsClick(Sender: TObject);
1128
 
var s : string;
1129
 
language: string;
1130
 
begin
1131
 
  language:=leftstr(lang,2);
1132
 
  {$ifdef linux}
1133
 
  s :='';
1134
 
  if fileexists('/usr/share/doc/winff/WinFF.' + language + '.pdf.gz') then s:='/usr/share/doc/winff/WinFF.' + language + '.pdf.gz';
1135
 
  if fileexists('/usr/share/doc/winff/WinFF.' + language + '.pdf') then s:='/usr/share/doc/winff/WinFF.' + language + '.pdf';
1136
 
  if fileexists('/usr/share/winff/WinFF.' + language + '.pdf') then s:='/usr/share/winff/WinFF.' + language + '.pdf';
1137
 
  if fileexists('/usr/share/winff/WinFF.' + language + '.pdf.gz') then s:='/usr/share/winff/WinFF.' + language + '.pdf.gz';
1138
 
  if fileexists('/usr/share/doc/packages/winff/WinFF.' + language + '.pdf.gz') then s:='/usr/share/doc/packages/winff/WinFF.' + language + '.pdf.gz';
1139
 
  if fileexists('/usr/share/doc/packages/winff/WinFF.' + language + '.pdf') then s:='/usr/share/doc/packages/winff/WinFF.' + language + '.pdf';
1140
 
  if s='' then
1141
 
     begin
1142
 
       s := '/usr/share/doc/winff/WinFF.en.pdf.gz';
1143
 
       if fileexists('/usr/share/doc/winff/WinFF.en.pdf') then s:='/usr/share/doc/winff/WinFF.en.pdf';
1144
 
       if fileexists('/usr/share/winff/WinFF.en.pdf') then s:='/usr/share/winff/WinFF.en.pdf';
1145
 
       if fileexists('/usr/share/winff/WinFF.en.pdf.gz') then s:='/usr/share/winff/WinFF.en.pdf.gz';
1146
 
       if fileexists('/usr/share/doc/packages/winff/WinFF.en.pdf.gz') then s:='/usr/share/doc/packages/winff/WinFF.en.pdf.gz';
1147
 
       if fileexists('/usr/share/doc/packages/winff/WinFF.en.pdf') then s:='/usr/share/doc/packages/winff/WinFF.en.pdf';
1148
 
     end;
1149
 
  {$endif}
1150
 
  {$ifdef win32}
1151
 
  s := extraspath + 'Docs\WinFF.' + language + '.pdf';
1152
 
  if not (fileexists(s)) then s := extraspath + 'Docs\WinFF.en.pdf';
1153
 
  {$endif}
1154
 
  Launchpdf(s);
1155
 
end;
1156
 
 
1157
 
//menu: Help Forums
1158
 
procedure TfrmMain.mitForumsClick(Sender: TObject);
1159
 
 
1160
 
begin
1161
 
  launchbrowser('http://www.winff.org/forums/');
1162
 
end;
1163
 
 
1164
 
//menu: Help Forums
1165
 
procedure TfrmMain.mitWinffClick(Sender: TObject);
1166
 
 
1167
 
begin
1168
 
  launchbrowser('http://www.winff.org/');
1169
 
end;
1170
 
 
1171
 
// menu: about
1172
 
procedure TfrmMain.MenuItem2Click(Sender: TObject);
1173
 
begin
1174
 
  frmAbout.show;
1175
 
end;
1176
 
 
1177
 
// menu: exit the program
1178
 
procedure TfrmMain.mitExitClick(Sender: TObject);
1179
 
begin
1180
 
  frmMain.close;
1181
 
end;
1182
 
 
1183
 
procedure TfrmMain.mitPlaySoundonFinishClick(Sender: TObject);
1184
 
begin
1185
 
  if mitplaysoundOnFinish.Checked then
1186
 
    begin
1187
 
    mitplaysoundOnFinish.checked:=false;
1188
 
    playscript:='false'
1189
 
    end
1190
 
  else
1191
 
    begin
1192
 
    mitplaysoundOnFinish.checked:=true;
1193
 
    playscript:='true';
1194
 
    end;
1195
 
end;
1196
 
 
1197
 
// menu: import preset
1198
 
procedure TfrmMain.mitImportPresetClick(Sender: TObject);
1199
 
begin
1200
 
  dlgOpenPreset.Title:=rsSelectPresetFile;
1201
 
  dlgOpenPreset.InitialDir:=GetMydocumentsPath();
1202
 
  if dlgOpenPreset.Execute then
1203
 
     importpresetfromfile(dlgOpenPreset.FileName);
1204
 
 
1205
 
end;
1206
 
 
1207
 
// menu: about
1208
 
procedure TfrmMain.mitAboutClick(Sender: TObject);
1209
 
begin
1210
 
  frmAbout.Show;
1211
 
end;
1212
 
 
1213
 
// menu: show / hide additional mnuOptions
1214
 
procedure TfrmMain.mitShowOptionsClick(Sender: TObject);
1215
 
 begin
1216
 
   if not mitShowOptions.Checked then
1217
 
        begin
1218
 
        frmMain.Height := frmMain.Height + pnlAdditionalOptions.Height;
1219
 
        pnlAdditionalOptions.Visible := True;
1220
 
        //Constraints.MinHeight := Constraints.MinHeight + pnlAdditionalOptions.Height;
1221
 
 
1222
 
        mitShowOptions.Checked:=true;
1223
 
        end
1224
 
  else
1225
 
        begin
1226
 
        //Constraints.MinHeight := Constraints.MinHeight - pnlAdditionalOptions.Height;
1227
 
        pnlAdditionalOptions.visible := false;
1228
 
        frmMain.Height := frmMain.Height - pnlAdditionalOptions.Height;
1229
 
 
1230
 
        mitShowOptions.Checked:=false;
1231
 
 
1232
 
        vidbitrate.Clear;
1233
 
        vidframerate.clear;
1234
 
        edtAspectRatio.Clear;
1235
 
        audbitrate.Clear;
1236
 
        audsamplingrate.Clear;
1237
 
        vidsizex.Clear;
1238
 
        vidsizey.clear;
1239
 
        mitDisplayCmdline.Checked:=false;
1240
 
        commandlineparams.Clear;
1241
 
        end;
1242
 
 
1243
 
  //  Application.ProcessMessages; // Should repaint the form like invalidate
1244
 
  Invalidate; //Why not use Invalidate itself?
1245
 
end;
1246
 
 
1247
 
// menu: shutdown on finish
1248
 
procedure TfrmMain.mitShutdownOnFinishClick(Sender: TObject);
1249
 
begin
1250
 
   if mitShutdownOnFinish.Checked then
1251
 
    begin
1252
 
    mitShutdownOnFinish.checked:=false;
1253
 
    end
1254
 
  else
1255
 
    begin
1256
 
    mitPauseOnFinish.checked:=false;
1257
 
    pausescript:='false';
1258
 
    mitShutdownOnFinish.Checked:=true;
1259
 
    end;
1260
 
end;
1261
 
 
1262
 
// menu: pause on finish
1263
 
procedure TfrmMain.mitPauseOnFinishClick(Sender: TObject);
1264
 
begin
1265
 
  if mitPauseOnFinish.Checked then
1266
 
    begin
1267
 
    mitPauseOnFinish.checked:=false;
1268
 
    pausescript:='false'
1269
 
    end
1270
 
  else
1271
 
    begin
1272
 
    mitPauseOnFinish.checked:=true;
1273
 
    pausescript:='true';
1274
 
    mitShutdownOnFinish.Checked:=false;
1275
 
    end;
1276
 
end;
1277
 
 
1278
 
// menu: display commandline
1279
 
procedure TfrmMain.mitDisplayCmdlineClick(Sender: TObject);
1280
 
begin
1281
 
     mitDisplayCmdline.Checked:= not mitDisplayCmdline.Checked;
1282
 
end;
1283
 
 
1284
 
// btnPlay the selected file
1285
 
procedure TfrmMain.btnPlayClick(Sender: TObject);
1286
 
var
1287
 
i : integer;
1288
 
filenametoplay: string;
1289
 
PlayProcess: TProcess;
1290
 
begin
1291
 
 
1292
 
 playprocess:= TProcess.Create(nil);
1293
 
 
1294
 
 if not fileexists(ffplay) then
1295
 
   begin
1296
 
    showmessage(rsCouldNotFindFFplay);
1297
 
    exit;
1298
 
   end;
1299
 
 
1300
 
 if filelist.Items.Count = 1 then
1301
 
    filelist.Selected[0]:=true;
1302
 
 
1303
 
 i:=0;
1304
 
 while i< filelist.Items.Count do
1305
 
    if filelist.Selected[i] then
1306
 
      begin
1307
 
      filenametoplay:=filelist.Items[i];
1308
 
      break;
1309
 
      end
1310
 
    else i+=1;
1311
 
 
1312
 
 if filenametoplay <>'' then
1313
 
    begin
1314
 
    PlayProcess.CommandLine:=ffplay + ' "' + filenametoplay+'"' ;
1315
 
    playProcess.Execute;
1316
 
    end;
1317
 
 
1318
 
 playprocess.free;
1319
 
end;
1320
 
 
1321
 
// Start Conversions
1322
 
procedure TfrmMain.btnConvertClick(Sender: TObject);
1323
 
var
1324
 
i,j : integer;
1325
 
cb,ct,cl,cr:integer;
1326
 
pn, extension, params, commandline, command, filename,batfile, passlogfile, basename:string;
1327
 
qterm, ffmpegfilename,ffplayfilename, usethreads, numthreads, deinterlace, nullfile, titlestring, priority:string;
1328
 
script: tstringlist;
1329
 
thetime: tdatetime;
1330
 
scriptprocess:tprocess;
1331
 
scriptpriority:tprocesspriority;
1332
 
ignorepreview:boolean;
1333
 
resmod : integer;
1334
 
begin                                     // get setup
1335
 
   scriptprocess:= TProcess.Create(nil);
1336
 
 
1337
 
   priority := getconfigvalue('general/priority');
1338
 
   if priority= unit4.rspriorityhigh then scriptpriority:=pphigh
1339
 
     else if priority= unit4.rsprioritynormal then scriptpriority:=ppnormal
1340
 
     else if priority= unit4.rspriorityidle then scriptpriority:=ppidle
1341
 
     else scriptpriority:=ppnormal;
1342
 
   scriptprocess.Priority:= scriptpriority;
1343
 
 
1344
 
 
1345
 
   script:= TStringList.Create;
1346
 
   {$ifdef win32}if usechcp = 'true' then script.Add('chcp ' + inttostr(ansicodepage));{$endif}
1347
 
   {$ifdef unix}script.Add('#!/bin/sh');{$endif}
1348
 
 
1349
 
   {$ifdef win32}ffmpegfilename:='"' + ffmpeg + '"';{$endif}
1350
 
   {$ifdef unix}ffmpegfilename:=ffmpeg;{$endif}
1351
 
   {$ifdef win32}ffplayfilename:='"' + ffplay + '"';{$endif}
1352
 
   {$ifdef unix}ffplayfilename:=ffplay;{$endif}
1353
 
   {$ifdef win32}nullfile:='"NUL.avi"';{$endif}
1354
 
   {$ifdef unix}nullfile:='/dev/null';{$endif}
1355
 
 
1356
 
   
1357
 
   if multithreading='true' then
1358
 
      begin
1359
 
        numthreads := trim(getconfigvalue('general/numberofthreads'));
1360
 
        if numthreads = '' then numthreads := '2';
1361
 
        usethreads := ' -threads ' + numthreads + ' ';
1362
 
      end
1363
 
   else usethreads:='';
1364
 
   
1365
 
   if cbxDeinterlace.Checked then deinterlace := ' -deinterlace '
1366
 
    else deinterlace:='';
1367
 
   
1368
 
   if not fileexists(ffmpeg) then
1369
 
      begin
1370
 
       showmessage(rsCouldnotFindFFplay);
1371
 
       exit;
1372
 
      end;
1373
 
 
1374
 
   pn:=getcurrentpresetname(presetbox.Text);
1375
 
   if pn='' then
1376
 
      begin
1377
 
       showmessage(rsPleaseSelectAPreset);
1378
 
       exit;
1379
 
      end;
1380
 
   if filelist.Items.Count=0 then
1381
 
      begin
1382
 
       showmessage(rsPleaseAdd1File);
1383
 
       exit;
1384
 
      end;
1385
 
   params:=getpresetparams(pn);
1386
 
   extension:=getpresetextension(pn);
1387
 
   frmScript.memo1.lines.Clear;
1388
 
 
1389
 
                                         // trim everything up
1390
 
   commandlineparams.text := trim(commandlineparams.Text);
1391
 
   vidbitrate.Text := trim(vidbitrate.Text);
1392
 
   vidframerate.text := trim(vidframerate.Text);
1393
 
   VidsizeX.text := trim(VidsizeX.Text);
1394
 
   VidsizeY.text := trim(VidsizeY.Text);
1395
 
   edtAspectRatio.Text := trim(edtAspectRatio.text);
1396
 
   audbitrate.Text := trim(audbitrate.Text);
1397
 
   audsamplingrate.Text := trim(audsamplingrate.Text);
1398
 
   audchannels.Text:=trim(audchannels.Text);
1399
 
   edtCropBottom.Text:=trim(edtCropbottom.text);
1400
 
   edtCropTop.Text:=trim(edtCropTop.text);
1401
 
   edtCropleft.Text:=trim(edtCropleft.text);
1402
 
   edtCropright.Text:=trim(edtCropright.text);
1403
 
   edtVolume.Text:=trim(edtVolume.Text);
1404
 
   edtAudioSync.Text:=trim(edtAudioSync.Text);
1405
 
 
1406
 
 
1407
 
                                      // replace preset params if mnuOptions specified
1408
 
   commandline := params;
1409
 
   if vidbitrate.Text <> '' then
1410
 
           commandline:=replaceparam(commandline,'-b','-b ' + vidbitrate.text+'k');
1411
 
   if vidframerate.Text <> '' then
1412
 
           commandline:=replaceparam(commandline,'-r','-r ' + vidframerate.Text);
1413
 
 
1414
 
// Inserting Crop Routine here as per Issue 77 on code.google.com
1415
 
// Changed by Ian V1.3
1416
 
 
1417
 
// cropping
1418
 
   if edtCropBottom.Text <> '' then
1419
 
      begin
1420
 
       cb:=strtoint(edtcropbottom.text);
1421
 
       if cb mod 2 = 1 then cb := cb-1;
1422
 
       edtcropbottom.text := inttostr(cb);
1423
 
       if edtcropbottom.text <> '0' then commandline := commandline + ' -cropbottom ' + edtCropBottom.Text + ' ';
1424
 
      end;
1425
 
 
1426
 
   if edtCropTop.Text <> '' then
1427
 
     begin
1428
 
       ct:=strtoint(edtcroptop.text);
1429
 
       if ct mod 2 = 1 then ct := ct-1;
1430
 
       edtcroptop.text := inttostr(ct);
1431
 
       if edtcroptop.text <> '0' then commandline += ' -croptop ' + edtCropTop.Text + ' ';
1432
 
     end;
1433
 
 
1434
 
   if edtCropLeft.Text <> '' then
1435
 
     begin
1436
 
       cl:=strtoint(edtcropleft.text);
1437
 
       if cl mod 2 = 1 then cl := cl-1;
1438
 
       edtcropleft.text := inttostr(cl);
1439
 
       if edtcropleft.text <> '0' then commandline += ' -cropleft ' + edtCropLeft.Text + ' ';
1440
 
     end;
1441
 
 
1442
 
   if edtCropRight.Text <> '' then
1443
 
     begin
1444
 
       cr:=strtoint(edtcropright.text);
1445
 
       if cr mod 2 = 1 then cr := cr-1;
1446
 
       edtcropright.text := inttostr(cr);
1447
 
       if edtcropright.text <> '0' then commandline += ' -cropright ' + edtCropRight.Text + ' ';
1448
 
     end;
1449
 
 
1450
 
 
1451
 
 
1452
 
   if (VidsizeX.Text <>'') AND (VidsizeY.Text <>'') then
1453
 
   begin
1454
 
        // 1.2
1455
 
        //commandline:=replaceparam(commandline,'-s','-s ' + VidsizeX.Text + 'x' + VidsizeY.Text);
1456
 
        //1.3
1457
 
        commandline:=replaceparam(commandline,'-s','');
1458
 
        commandline += ' -s ' + VidsizeX.Text + 'x' + VidsizeY.Text + ' ';
1459
 
 
1460
 
   end;
1461
 
 
1462
 
   if edtAspectRatio.Text <> '' then
1463
 
           commandline:=replaceparam(commandline,'-aspect','-aspect ' + edtAspectRatio.Text);
1464
 
   if audbitrate.Text <> '' then
1465
 
           commandline:=replaceparam(commandline,'-ab','-ab ' + audbitrate.Text+'k');
1466
 
   if audsamplingrate.Text <> '' then
1467
 
           commandline:=replaceparam(commandline,'-ar','-ar ' + audsamplingrate.Text);
1468
 
   if audchannels.Text <> '' then
1469
 
           commandline:=replaceparam(commandline,'-ac','-ac ' + audchannels.Text);
1470
 
 
1471
 
   // changes for winff 1.3
1472
 
   //
1473
 
   ignorepreview := false;
1474
 
   if edtVolume.Text <> '' then
1475
 
           commandline:=replaceparam(commandline,'-vol','-vol ' + edtVolume.Text);
1476
 
   if edtAudioSync.Text <> '' then
1477
 
           commandline:=replaceparam(commandline,'-async','-async ' + edtAudioSync.Text);
1478
 
 
1479
 
 
1480
 
 
1481
 
 
1482
 
   if edtSeekHH.Value + edtSeekMM.Value + edtSeekSS.Value > 0 then
1483
 
   begin
1484
 
     ignorepreview := true;
1485
 
     if (edtSeekMM.Value < 10) and (length(edtSeekMM.Text)<2) then edtSeekMM.Text := '0' + edtSeekMM.Text;
1486
 
     if (edtSeekSS.Value < 10) and (length(edtSeekSS.Text)<2) then edtSeekSS.Text := '0' + edtSeekSS.Text;
1487
 
 
1488
 
     commandline:=replaceparam(commandline,'-ss','-ss ' + edtSeekHH.Text + ':' + edtSeekMM.Text + ':' + edtSeekSS.Text);
1489
 
   end;
1490
 
 
1491
 
   if edtTTRHH.Value + edtTTRMM.Value + edtTTRSS.Value > 0 then
1492
 
   begin
1493
 
     ignorepreview := true;
1494
 
     if (edtTTRMM.Value < 10) and (length(edtTTRMM.Text)<2)  then edtTTRMM.Text := '0' + edtTTRMM.Text;
1495
 
     if (edtTTRSS.Value < 10) and (length(edtTTRSS.Text)<2)  then edtTTRSS.Text := '0' + edtTTRSS.Text;
1496
 
 
1497
 
     commandline:=replaceparam(commandline,'-t','-t ' + edtTTRHH.Text + ':' + edtTTRMM.Text + ':' + edtTTRSS.Text);
1498
 
   end;
1499
 
 
1500
 
 
1501
 
   if commandlineparams.Text <> '' then
1502
 
           commandline += ' ' + commandlineparams.text;
1503
 
 
1504
 
   // preview
1505
 
   // if -ss and -t are already set, ignore the following parameter.
1506
 
   if (preview = true) and (ignorepreview = false) then
1507
 
   begin
1508
 
     commandline += ' -ss 00:01:00 -t 00:00:30';
1509
 
   end;
1510
 
 
1511
 
 
1512
 
                                           // build batch file
1513
 
   thetime :=now;
1514
 
   batfile := 'ff' + FormatDateTime('yymmddhhnnss',thetime) +
1515
 
           {$ifdef win32}'.bat'{$endif}
1516
 
           {$ifdef unix}'.sh'{$endif} ;
1517
 
 
1518
 
   for i:=0 to filelist.Items.Count - 1 do
1519
 
     begin
1520
 
       filename := filelist.items[i];
1521
 
       basename := extractfilename(filename);
1522
 
       // resolve issues with embedded quote marks in filename to be converted.  issue 38
1523
 
       {$ifdef unix}
1524
 
       filename := StringReplace(filename,'"','\"',[rfReplaceAll]);
1525
 
       {$endif}
1526
 
 
1527
 
       for j:= length(basename) downto 1  do
1528
 
         begin
1529
 
           if basename[j] = #46 then
1530
 
              begin
1531
 
                basename := leftstr(basename,j-1);
1532
 
                {$ifdef unix}
1533
 
                basename := StringReplace(basename,'"','\"',[rfReplaceAll]);
1534
 
                {$endif}
1535
 
                break;
1536
 
              end;
1537
 
         end;
1538
 
 
1539
 
       command := '';
1540
 
       {$ifdef win32}titlestring:='title ' + rsConverting + ' ' + extractfilename(filename) +
1541
 
            ' ('+inttostr(i+1)+'/'+ inttostr(filelist.items.count)+')';{$endif}
1542
 
       {$ifdef unix}titlestring:='echo -n "\033]0; ' + rsConverting +' ' + basename +
1543
 
            ' ('+inttostr(i+1)+'/'+ inttostr(filelist.items.count)+')'+'\007"';{$endif}
1544
 
       script.Add(titlestring);
1545
 
       
1546
 
       passlogfile := destfolder.Text + DirectorySeparator + basename + '.log';
1547
 
 
1548
 
       if cbx2Pass.Checked = false then
1549
 
          begin
1550
 
           command := ffmpegfilename + usethreads + ' -i "' + filename + '" ' + deinterlace + commandline + ' "' +
1551
 
                  destfolder.Text + DirectorySeparator + basename +'.' + extension+ '"';
1552
 
           script.Add(command);
1553
 
          end
1554
 
       else if cbx2Pass.Checked = true then
1555
 
          begin
1556
 
           command := ffmpegfilename + usethreads + ' -i "' + filename + '" ' + deinterlace + commandline + ' -an'
1557
 
                 + ' -passlogfile "' + passlogfile + '"' + ' -pass 1 ' +  ' -y ' + nullfile ;
1558
 
           script.Add(command);
1559
 
           command := ffmpegfilename + usethreads + ' -y -i "' + filename + '" ' + deinterlace + commandline +  ' -passlogfile "'
1560
 
                 + passlogfile + '"' + ' -pass 2 ' + ' "' + destfolder.Text + DirectorySeparator + basename +'.'
1561
 
                 + extension+ '"';
1562
 
           script.add(command);
1563
 
          end;
1564
 
       if preview then
1565
 
         begin
1566
 
         script.add(ffplayfilename + ' "' + destfolder.Text + DirectorySeparator + basename +'.'+ extension+ '"');
1567
 
         break;
1568
 
         end;
1569
 
     end;
1570
 
                                       // finish off command
1571
 
 
1572
 
                                         // pausescript
1573
 
   if (pausescript='true') and (preview=false) then
1574
 
       begin
1575
 
       {$ifdef win32}
1576
 
       script.Add('pause');
1577
 
       {$endif}
1578
 
       {$ifdef unix}
1579
 
       script.Add('read -p "' + rsPressEnter + '" dumbyvar');
1580
 
       {$endif}
1581
 
       end;
1582
 
                                               //shutdown when finnshed
1583
 
   if mitShutdownOnFinish.Checked and (pausescript='false') then
1584
 
      {$ifdef win32}script.Add('shutdown.exe -s');{$endif}
1585
 
      {$ifdef unix}script.Add('shutdown now');{$endif}
1586
 
 
1587
 
                                           // remove preview file if exists
1588
 
   if preview then
1589
 
      begin
1590
 
        {$ifdef win32}script.add('del ' + '"' + destfolder.Text + DirectorySeparator + basename +'.'+ extension+ '"');{$endif}
1591
 
        {$ifdef unix}script.add('rm ' + '"' + destfolder.Text + DirectorySeparator + basename +'.'+ extension+ '"');{$endif}
1592
 
        preview:=false;
1593
 
      end;
1594
 
                                           // remove batch file on completion
1595
 
   {$ifdef win32}script.Add('del ' + '"' + presetspath + batfile + '"');{$endif}
1596
 
   {$ifdef unix}script.Add('rm ' + '"' +  presetspath + batfile+ '"');{$endif}
1597
 
 
1598
 
 
1599
 
   if not mitDisplayCmdline.Checked then
1600
 
    begin
1601
 
     script.SaveToFile(presetspath+batfile);
1602
 
     {$ifdef unix}
1603
 
     fpchmod(presetspath + batfile,&777);
1604
 
     {$endif}
1605
 
 
1606
 
     {$ifdef win32}
1607
 
     qterm := '"' + terminal + '"';
1608
 
     {$endif}
1609
 
 
1610
 
     {$ifdef unix}qterm := terminal;{$endif}
1611
 
                                                        // do it
1612
 
     {$ifdef win32}scriptprocess.commandline:= qterm + ' ' + termoptions + ' "' + presetspath + batfile + '"';{$endif}
1613
 
     {$ifdef unix}scriptprocess.commandline:= qterm + ' ' +  termoptions + ' ' + presetspath + batfile + ' &'; {$endif}
1614
 
 
1615
 
     scriptprocess.execute;
1616
 
    end
1617
 
   else
1618
 
   begin
1619
 
      // if continue pressed, attempt to execute user modified script;
1620
 
      frmScript.Memo1.Lines:=script;
1621
 
      frmScript.scriptfilename:= presetspath + batfile;
1622
 
      resmod := frmScript.ShowModal;
1623
 
      if resmod = 1 then     // Continue Clicked;
1624
 
      begin
1625
 
 
1626
 
 
1627
 
       {$ifdef unix}
1628
 
       fpchmod(presetspath + batfile,&777);
1629
 
       {$endif}
1630
 
 
1631
 
       {$ifdef win32}
1632
 
       qterm := '"' + terminal + '"';
1633
 
       {$endif}
1634
 
 
1635
 
       {$ifdef unix}qterm := terminal;{$endif}
1636
 
                                                        // do it
1637
 
       {$ifdef win32}scriptprocess.commandline:= qterm + ' ' + termoptions + ' "' + presetspath + batfile + '"';{$endif}
1638
 
       {$ifdef unix}scriptprocess.commandline:= qterm + ' ' +  termoptions + ' ' + presetspath + batfile + ' &'; {$endif}
1639
 
 
1640
 
       scriptprocess.execute;
1641
 
 
1642
 
      end;
1643
 
   end;
1644
 
 
1645
 
    script.Free;
1646
 
    // try                            // to set dest directory in preset
1647
 
    //   setpresetdestdir(pn,destfolder.text);
1648
 
    // finally
1649
 
    // end;
1650
 
end;
1651
 
 
1652
 
   // replace a paramter from a commandline
1653
 
function TfrmMain.replaceparam(commandline:string; param:string; replacement:string):string;
1654
 
var
1655
 
i,startpos,endpos: integer;
1656
 
 
1657
 
begin
1658
 
 startpos:=pos(param +' ', commandline);
1659
 
 endpos:=length(commandline)+1;
1660
 
 if startpos <> 0 then
1661
 
   begin
1662
 
     for I:=startpos+1 to length(commandline)-1 do
1663
 
         if commandline[i]='-' then
1664
 
            begin
1665
 
            endpos:=i-1;
1666
 
            break;
1667
 
            end;
1668
 
     delete(commandline,startpos,endpos-startpos);
1669
 
     commandline:=leftstr(commandline,startpos)+replacement+' '+rightstr(commandline,length(commandline)-startpos);
1670
 
   end
1671
 
 else
1672
 
     commandline+= ' ' + replacement;
1673
 
     result:=commandline;
1674
 
end;
1675
 
 
1676
 
procedure TfrmMain.VidbitrateChange(Sender: TObject);
1677
 
begin
1678
 
 
1679
 
end;
1680
 
 
1681
 
// import a preset from a file
1682
 
procedure TfrmMain.importpresetfromfile(presetfilename: string);
1683
 
var
1684
 
 importfile: txmldocument;
1685
 
 importedpreset: tdomelement;
1686
 
 i,j,reply:integer;
1687
 
 replaceall: boolean = false;
1688
 
 removepreset: boolean = false;
1689
 
 nodeexists:boolean = false;
1690
 
 newnode,labelnode,paramsnode,extensionnode,categorynode,
1691
 
  textl,textp,texte,textc, node: tdomnode;
1692
 
 nodename,nodelabel,nodeext,testchars:string;
1693
 
begin
1694
 
 if not fileexists(presetfilename) then
1695
 
    begin
1696
 
      showmessage(rsCouldNotFindFile);
1697
 
      exit;
1698
 
    end;
1699
 
 
1700
 
 try
1701
 
  importfile := TXMLdocument.Create;
1702
 
 except
1703
 
 end;
1704
 
 
1705
 
 try
1706
 
   ReadXMLFile(importfile, presetFileName);
1707
 
   importedpreset:=importfile.DocumentElement;
1708
 
 except
1709
 
  showmessage(rsInvalidPreset);
1710
 
  exit;
1711
 
 end;
1712
 
 
1713
 
 if importedpreset.ChildNodes.Count = 0 then exit;
1714
 
 
1715
 
 for j:= 0 to importedpreset.ChildNodes.Count -1 do
1716
 
 begin
1717
 
 
1718
 
   node:= importedpreset.ChildNodes.Item[j];
1719
 
 
1720
 
   nodename:= node.NodeName;
1721
 
 
1722
 
   removepreset:=false;
1723
 
   nodeexists:=false;
1724
 
   for i:= 0 to presets.ChildNodes.Count -1 do
1725
 
     if presets.ChildNodes.Item[i].NodeName = nodename then nodeexists := true;
1726
 
 
1727
 
   if nodeexists then
1728
 
     begin
1729
 
       if replaceall=false then reply :=  MessageDlg ('Replace Preset', Format(rsPresetAlreadyExist, ['"', nodename, '"']),
1730
 
                                            mtConfirmation, [mbYes, mbNo, mbAll, mbCancel],0);
1731
 
       if reply=mrCancel then exit;
1732
 
       if reply=mrNo then continue;
1733
 
       if reply=mrAll then replaceall := true;
1734
 
       if (reply=mrYes) or (reply = mrAll) or (replaceall = true) then removepreset:=true;
1735
 
       if removepreset then presets.RemoveChild(presets.FindNode(nodename));
1736
 
     end;
1737
 
 
1738
 
   try
1739
 
     nodelabel := node.FindNode('label').FindNode('#text').NodeValue;
1740
 
   except
1741
 
     begin
1742
 
       showmessage(rsPresethasnolabel);
1743
 
       exit;
1744
 
     end;
1745
 
   end;
1746
 
 
1747
 
   try
1748
 
     testchars := node.FindNode('params').FindNode('#text').NodeValue;
1749
 
   except
1750
 
   end;
1751
 
   for i:= 0 to length(testchars)-1 do
1752
 
     begin
1753
 
       if (testchars[i] = #124) or (testchars[i] = #60) or (testchars[i] = #62) or
1754
 
          (testchars[i] = #59) or (testchars[i] = #38) then
1755
 
         begin
1756
 
          showmessage(rsThePresetHasIllegalChars);
1757
 
          exit;
1758
 
         end;
1759
 
     end;
1760
 
 
1761
 
   for i:= 0 to presets.ChildNodes.Count -1 do
1762
 
     if presets.ChildNodes.Item[i].findnode('label').FindNode('#text').NodeValue = nodelabel then
1763
 
        begin
1764
 
         showmessage(Format(rsPresetWithLabelExists, ['"', nodelabel, '"']));
1765
 
         exit;
1766
 
        end;
1767
 
 
1768
 
 
1769
 
   try
1770
 
     nodeext := node.FindNode('extension').FindNode('#text').NodeValue;
1771
 
   except
1772
 
     begin
1773
 
       showmessage(rsPresetHasNoExt);
1774
 
       exit;
1775
 
     end;
1776
 
   end;
1777
 
 
1778
 
   newnode:=presetsfile.CreateElement(nodename);
1779
 
   presets.AppendChild(newnode);
1780
 
   labelnode:=presetsfile.CreateElement('label');
1781
 
   newnode.AppendChild(labelnode);
1782
 
   paramsnode:=presetsfile.CreateElement('params');
1783
 
   newnode.AppendChild(paramsnode);
1784
 
   extensionnode:=presetsfile.CreateElement('extension');
1785
 
   newnode.AppendChild(extensionnode);
1786
 
   categorynode:=presetsfile.CreateElement('category');
1787
 
   newnode.AppendChild(categorynode);
1788
 
 
1789
 
   textl:=presetsfile.CreateTextNode(nodelabel);
1790
 
   labelnode.AppendChild(textl);
1791
 
 
1792
 
 
1793
 
   try
1794
 
     textp:=presetsfile.CreateTextNode(node.FindNode('params').FindNode('#text').NodeValue);
1795
 
   except
1796
 
     textp:=presetsfile.CreateTextNode('');
1797
 
   end;
1798
 
   paramsnode.AppendChild(textp);
1799
 
 
1800
 
   texte:=presetsfile.CreateTextNode(nodeext);
1801
 
   extensionnode.AppendChild(texte);
1802
 
 
1803
 
   try
1804
 
     textc:=presetsfile.CreateTextNode(node.FindNode('category').FindNode('#text').NodeValue);
1805
 
   except
1806
 
     textc:=presetsfile.CreateTextNode('');
1807
 
   end;
1808
 
   categorynode.AppendChild(textc);
1809
 
 
1810
 
 end; //for j = 1 to childnodes-1
1811
 
 
1812
 
writexmlfile(presetsfile, presetspath + 'presets.xml');  // save the imported preset
1813
 
 
1814
 
populatepresetbox('');
1815
 
end;
1816
 
 
1817
 
initialization
1818
 
  {$I unit1.lrs}
1819
 
  {$ifdef win32}PODirectory := extraspath + '\languages\'{$endif};
1820
 
  {$ifdef unix}PODirectory := '/usr/share/winff/languages/'{$endif};
1821
 
  GetLanguageIDs(Lang, FallbackLang); // in unit gettext
1822
 
  POFile := PODirectory + 'winff.' + Lang + '.po';
1823
 
  if not FileExists(POFile) then
1824
 
     POFile := PODirectory + 'winff.' + FallbackLang + '.po';
1825
 
 
1826
 
  if FileExists(POFile) then
1827
 
  begin
1828
 
    try
1829
 
      LRSTranslator := TPoTranslator.Create(POFile);
1830
 
    except
1831
 
    end;
1832
 
  end
1833
 
  else
1834
 
    POFile := '';
1835
 
 
1836
 
end.
1837