cdar

diff unit_Editor_CreateAR.pas @ 0:ef71164288c1

begin of using hg for cdar
author "Meillo r e t u r n s <meillo@marmaro.de>"
date Sun, 03 Dec 2006 21:54:43 +0100
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/unit_Editor_CreateAR.pas	Sun Dec 03 21:54:43 2006 +0100
     1.3 @@ -0,0 +1,319 @@
     1.4 +unit unit_Editor_CreateAR;
     1.5 +
     1.6 +interface//####################################################################################
     1.7 +
     1.8 +uses
     1.9 +  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    1.10 +  Dialogs, StdCtrls, Grids, ValEdit, ShellApi;
    1.11 +
    1.12 +type
    1.13 +  Tform_editor_CreateAR = class(TForm)
    1.14 +    btn_Finish: TButton;
    1.15 +    btn_Back: TButton;
    1.16 +    FinalSettings: TValueListEditor;
    1.17 +    procedure FormCreate(Sender: TObject);
    1.18 +    procedure FormShow(Sender: TObject);
    1.19 +    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    1.20 +    procedure btn_BackClick(Sender: TObject);
    1.21 +    procedure btn_FinishClick(Sender: TObject);
    1.22 +  private
    1.23 +    { Private declarations }
    1.24 +  public
    1.25 +    { Public declarations }
    1.26 +  end;
    1.27 +
    1.28 +var
    1.29 +  form_editor_CreateAR: Tform_editor_CreateAR;
    1.30 +
    1.31 +implementation//###############################################################################
    1.32 +uses unit_Editor, unit_Editor_tutorial, unit_Start;
    1.33 +{$R *.dfm}//###################################################################################
    1.34 +{$I-}
    1.35 +
    1.36 +//------------------------------------------------------------------------------ form create
    1.37 +procedure Tform_editor_CreateAR.FormCreate(Sender: TObject);
    1.38 +begin
    1.39 +  //
    1.40 +    form_Editor_CreateAR.Caption := 'Create your CD-Autorunner';
    1.41 +    btn_Finish.Caption := 'Finish';
    1.42 +    btn_Back.Caption := 'Back';
    1.43 +    FinalSettings.TitleCaptions.Strings[0] := ' Settings';
    1.44 +    FinalSettings.TitleCaptions.Strings[1] := ' Value';
    1.45 +    FinalSettings.Keys[1] := 'Background-Picture';
    1.46 +    FinalSettings.Keys[2] := 'Enter-Picture';
    1.47 +    FinalSettings.Keys[3] := 'Autorun-Icon';
    1.48 +    FinalSettings.Keys[4] := 'CD-Root-Dir';
    1.49 +    FinalSettings.Keys[6] := 'Enter X-Position';
    1.50 +    FinalSettings.Keys[7] := 'Enter Y-Position';
    1.51 +    FinalSettings.Keys[8] := 'Welcome-Kind';
    1.52 +    FinalSettings.Keys[9] := 'Delay';
    1.53 +    FinalSettings.Keys[10] := 'Starts File/Dir';
    1.54 +end;//--------------------------------------------------------------------------
    1.55 +//------------------------------------------------------------------------------ form show
    1.56 +procedure Tform_editor_CreateAR.FormShow(Sender: TObject);
    1.57 +begin
    1.58 +  // disable drag'n'drop of 'img_button'
    1.59 +    form_editor.draggingstatus := 3;
    1.60 +  // disable menu
    1.61 +    form_editor.mnu_Tutorial.enabled := false;
    1.62 +    form_editor.mnu_WelcomeScreen.Enabled := false;
    1.63 +    form_editor.mnu_Autorun.Enabled := false;
    1.64 +    form_editor.mnu_CreateAR.enabled := false;
    1.65 +    form_editor.mnu_Sprache.enabled := false;
    1.66 +
    1.67 +  // show final settings
    1.68 +    finalsettings.Values['Background-Picture'] := form_Editor.PfadHG_alt;
    1.69 +    finalsettings.Values['Enter-Picture'] := form_Editor.PfadEnter_alt;
    1.70 +    finalsettings.values['Autorun-Icon'] := form_Editor.PfadIcon_alt;
    1.71 +    finalsettings.Values['CD-Root-Dir'] := form_Editor.CDRoot_alt;
    1.72 +
    1.73 +    finalsettings.Values['Enter X-Position'] := inttostr(form_Editor.xEnter_alt);
    1.74 +    finalsettings.Values['Enter Y-Position'] := inttostr(form_Editor.yEnter_alt);
    1.75 +    finalsettings.Values['Welcome-Kind'] := form_Editor.WelcomeKind_alt;
    1.76 +    finalsettings.Values['Delay'] := form_Editor.delay;
    1.77 +    finalsettings.Values['Starts File/Dir'] := form_Editor.StartsFD_alt;
    1.78 +
    1.79 +  // disable everything not needed
    1.80 +    if form_Editor.WelcomeKind_alt = 'none' then
    1.81 +      begin
    1.82 +        finalsettings.Values['Background-Picture'] := '< not used / nicht genutzt >';
    1.83 +        finalsettings.Values['Enter-Picture'] := '< not used / nicht genutzt >';
    1.84 +        finalsettings.Values['Enter X-Position'] := '< not used / nicht genutzt >';
    1.85 +        finalsettings.Values['Enter Y-Position'] := '< not used / nicht genutzt >';
    1.86 +        finalsettings.Values['Delay'] := '< not used / nicht genutzt >';
    1.87 +      end
    1.88 +    else
    1.89 +      begin
    1.90 +        if form_Editor.WelcomeKind_alt = 'time' then
    1.91 +          begin
    1.92 +            finalsettings.Values['Enter-Picture'] := '< not used / nicht genutzt >';
    1.93 +            finalsettings.Values['Enter X-Position'] := '< not used / nicht genutzt >';
    1.94 +            finalsettings.Values['Enter Y-Position'] := '< not used / nicht genutzt >';
    1.95 +            if form_Editor.PfadHG_alt = '' then
    1.96 +              begin
    1.97 +                finalsettings.Values['Background-Picture'] := '#### missing / fehlt ####';
    1.98 +                btn_finish.Enabled := false;
    1.99 +              end;
   1.100 +          end
   1.101 +        else  // klick
   1.102 +          begin
   1.103 +            finalsettings.Values['Delay'] := '< not used / nicht genutzt >';
   1.104 +            if form_Editor.PfadHG_alt = '' then
   1.105 +              begin
   1.106 +                // if the 'enter'-picture is full size, then dont use the 'background'-picture
   1.107 +                if (form_editor.img_button.Width = form_editor.img_Background.Width) and
   1.108 +                   (form_editor.img_button.Height = form_editor.img_Background.Height) then
   1.109 +                  begin
   1.110 +                    finalsettings.Values['Background-Picture'] := '< not used / nicht genutzt >';
   1.111 +                  end
   1.112 +                else
   1.113 +                  begin
   1.114 +                    finalsettings.Values['Background-Picture'] := '#### missing / fehlt ####';
   1.115 +                    btn_finish.Enabled := false;
   1.116 +                  end;
   1.117 +              end;
   1.118 +            if form_Editor.PfadEnter_alt = '' then
   1.119 +              begin
   1.120 +                finalsettings.Values['Enter-Picture'] := '#### missing / fehlt ####';
   1.121 +                btn_finish.Enabled := false;
   1.122 +              end;
   1.123 +          end;
   1.124 +      end;
   1.125 +
   1.126 +  //
   1.127 +    if form_Editor.pfadIcon_alt = '' then
   1.128 +      begin
   1.129 +        finalsettings.values['Autorun-Icon'] := '(The banana / Die Banane)';
   1.130 +      end;
   1.131 +
   1.132 +  //
   1.133 +    if form_Editor.StartsFD_alt = '' then
   1.134 +      begin
   1.135 +        finalsettings.Values['Starts File/Dir'] := '(CD-Root-Dir / CD-Wurzelverzeichnis)';
   1.136 +      end;
   1.137 +  //
   1.138 +    if form_Editor.StartsFD_alt = '-' then
   1.139 +      begin
   1.140 +        if form_Editor.WelcomeKind_alt = 'none' then
   1.141 +          begin
   1.142 +            finalsettings.Values['Starts File/Dir'] := '#### CDAR does not do anything! / CDAR macht gar nichts! ####';
   1.143 +            btn_finish.Enabled := false;
   1.144 +          end
   1.145 +        else
   1.146 +          begin
   1.147 +            finalsettings.Values['Starts File/Dir'] := '(Just shows Welcome-Screen / Zeigt nur ein Willkommensbild)';
   1.148 +          end;
   1.149 +      end;
   1.150 +
   1.151 +        // use German if set so
   1.152 +    if form_editor.englisch = false then
   1.153 +      begin
   1.154 +        form_Editor_CreateAR.Caption := 'Autorunner erstellen';
   1.155 +        btn_Finish.Caption := 'Fertigstellen';
   1.156 +        btn_Back.caption := 'Zurück';
   1.157 +        FinalSettings.TitleCaptions.Strings[0] := ' Einstellung';
   1.158 +        FinalSettings.TitleCaptions.Strings[1] := ' Wert';
   1.159 +        FinalSettings.Keys[1] := 'Hintergrundbild';
   1.160 +        FinalSettings.Keys[2] := 'Enterbild';
   1.161 +        FinalSettings.Keys[3] := 'Autorun-Icon';
   1.162 +        FinalSettings.Keys[4] := 'CD-Grundverzeichnis';
   1.163 +        FinalSettings.Keys[6] := 'Enter X-Position';
   1.164 +        FinalSettings.Keys[7] := 'Enter Y-Position';
   1.165 +        FinalSettings.Keys[8] := 'Willkommensart';
   1.166 +        FinalSettings.Keys[9] := 'Zeitverzögerung';
   1.167 +        FinalSettings.Keys[10] := 'Startet Datei/Verz.';
   1.168 +      end;
   1.169 +end;//--------------------------------------------------------------------------
   1.170 +//------------------------------------------------------------------------------ Form Close
   1.171 +procedure Tform_editor_CreateAR.FormClose(Sender: TObject;
   1.172 +  var Action: TCloseAction);
   1.173 +begin
   1.174 +  // enable drag'n'drop of 'img_button' again
   1.175 +    form_editor.draggingstatus := 0;
   1.176 +  // enable menu again
   1.177 +    form_editor.mnu_Tutorial.enabled := true;
   1.178 +    form_editor.mnu_WelcomeScreen.Enabled := true;
   1.179 +    form_editor.mnu_Autorun.Enabled := true;
   1.180 +    form_editor.mnu_CreateAR.enabled := true;
   1.181 +    form_editor.mnu_Sprache.enabled := true;
   1.182 +end;//--------------------------------------------------------------------------
   1.183 +
   1.184 +//#############################################################################################
   1.185 +
   1.186 +//------------------------------------------------------------------------------ Click Back
   1.187 +procedure Tform_editor_CreateAR.btn_BackClick(Sender: TObject);
   1.188 +begin
   1.189 +  // close CreateAR
   1.190 +    form_editor_createar.Close;
   1.191 +end;//--------------------------------------------------------------------------
   1.192 +//------------------------------------------------------------------------------ Click Finish
   1.193 +procedure Tform_editor_CreateAR.btn_FinishClick(Sender: TObject);
   1.194 +  var f : textfile;
   1.195 +      i : integer;
   1.196 +      CDRoot1 : string;
   1.197 +      CDRoot2 : string;
   1.198 +begin
   1.199 +  // create 'CDRoot' directory if not exists
   1.200 +  cdRoot1 := form_Editor.CDRoot_alt;
   1.201 +
   1.202 +  if DirectoryExists(CDRoot1) = false then
   1.203 +    begin
   1.204 +      for i := 5 to length(CDRoot1) do
   1.205 +        begin
   1.206 +          if copy(CDRoot1, i, 1) = '\' then
   1.207 +            begin
   1.208 +              CDRoot2 := copy(CDRoot1, 1, i);
   1.209 +              if DirectoryExists(CDRoot2) = false then
   1.210 +                begin
   1.211 +                  mkdir(cdroot2);
   1.212 +                end;
   1.213 +            end;
   1.214 +        end;
   1.215 +    end;
   1.216 +
   1.217 +
   1.218 +  // create Autorun.inf
   1.219 +    try
   1.220 +      AssignFile(f, form_Editor.CDRoot_alt + 'Autorun.inf');
   1.221 +          ReWrite(f);
   1.222 +          Writeln(f, '[Autorun]');
   1.223 +          Writeln(f, 'Open= "_CDAR\cdar.exe welcome"');
   1.224 +          if finalsettings.Cells[1,3] = '(The banana / Die Banane)' then
   1.225 +            begin
   1.226 +              Writeln(f, 'Icon= "_CDAR\cdar.exe"');
   1.227 +            end
   1.228 +          else
   1.229 +            begin
   1.230 +              Writeln(f, 'Icon= "_CDAR\Autorun.ico"');
   1.231 +            end;
   1.232 +      CloseFile(f);
   1.233 +    except
   1.234 +      showmessage('"Autorun.inf" konnte nicht erstellt werden'+ #10
   1.235 +        +'Vermutlich ist der Pfad zum CD-Wurzelverzeichnis ungültig'+ #10
   1.236 +        + #10
   1.237 +        +'"Autorun.inf" could not be created'+ #10
   1.238 +        +'probably the path to the CD root directory is corrupt');
   1.239 +    end;
   1.240 +
   1.241 +  // create directory '_CDAR' if not exists
   1.242 +    if DirectoryExists(CDRoot1 + '_CDAR') = false then
   1.243 +      begin
   1.244 +        mkdir(form_Editor.CDRoot_alt + '_CDAR\');
   1.245 +      end;
   1.246 +
   1.247 +  // create 'cdar.ini'
   1.248 +    try
   1.249 +      AssignFile(f, form_Editor.CDRoot_alt + '_CDAR\cdar.ini');
   1.250 +      ReWrite(f);
   1.251 +        Writeln(f, form_Editor.WelcomeKind_alt);
   1.252 +        Writeln(f, form_Editor.Delay);
   1.253 +        Writeln(f, inttostr(form_Editor.xEnter_alt));
   1.254 +        Writeln(f, inttostr(form_Editor.yEnter_alt));
   1.255 +        Writeln(f, '..\' + form_Editor.StartsFD_alt);
   1.256 +      CloseFile(f);
   1.257 +    except
   1.258 +      showmessage('"cdar.ini"  konnte nicht erstellt werden'+ #10
   1.259 +        +'Vermutlich ist der Pfad zum CD-Wurzelverzeichnis ungültig'+ #10
   1.260 +        + #10
   1.261 +        +'"cdar.ini" could not be created'+ #10
   1.262 +        +'probably the path to the CD root directory is corrupt');
   1.263 +    end;
   1.264 +
   1.265 +  // create 'cdar.bat'
   1.266 +    try
   1.267 +      AssignFile(f, 'C:\cdar.bat');
   1.268 +      ReWrite(f);
   1.269 +        Writeln(f, 'Rem This File was built by CD-Autorunner');
   1.270 +        Writeln(f, 'Rem It is not needed anymore you can delete it');
   1.271 +        Writeln(f, 'Rem');
   1.272 +        Writeln(f, 'Rem Diese Datei wurde von CD-Autorunner erzeugt');
   1.273 +        Writeln(f, 'Rem Sie wird nicht mehr gebraucht und kann geloescht werden');
   1.274 +        Writeln(f, 'Rem ###############################################');
   1.275 +        Writeln(f, 'Rem');
   1.276 +        Writeln(f, 'Rem');
   1.277 +      // copy 'Autorun.ico' if necessary
   1.278 +        if finalsettings.Cells[1,3] <> '(The banana / Die Banane)' then
   1.279 +          begin
   1.280 +                Writeln(f, 'Copy %1 %2');
   1.281 +          end;
   1.282 +      // copy 'background'-picture if necessary
   1.283 +        if finalsettings.Cells[1,1] <> '< not used / nicht genutzt >' then
   1.284 +          begin
   1.285 +            Writeln(f, 'Copy %3 %4');
   1.286 +          end;
   1.287 +      // copy 'enter'-picture if necessary
   1.288 +        if finalsettings.Cells[1,2] <> '< not used / nicht genutzt >' then
   1.289 +          begin
   1.290 +            Writeln(f, 'Copy %5 %6');
   1.291 +          end;
   1.292 +      // copy 'cdar.exe'
   1.293 +        Writeln(f, 'Copy %7 %8');
   1.294 +      // self destruction
   1.295 +        Writeln(f, 'del "C:\cdar.bat"');
   1.296 +      // exit script
   1.297 +        Writeln(f, 'exit');
   1.298 +      // close file
   1.299 +      CloseFile(f);
   1.300 +    except
   1.301 +      showmessage('"cdar.bat" konnte nicht erstellt werden'+ #10#10
   1.302 +        +'"cdar.bat" could not be created');
   1.303 +    end;
   1.304 +
   1.305 +    try
   1.306 +      ShellExecute(application.Handle, 'open', pchar('C:\cdar.bat'),
   1.307 +        pchar('"'
   1.308 +          + form_Editor.PfadIcon_alt + '" "' + form_Editor.CDRoot_alt + '_CDAR\Autorun.ico" "'
   1.309 +          + form_Editor.PfadHG_alt + '" "' + form_Editor.CDRoot_alt + '_CDAR\Welcome.jpg" "'
   1.310 +          + form_Editor.PfadEnter_alt + '" "' + form_Editor.CDRoot_alt + '_CDAR\Enter.jpg" "'
   1.311 +          + paramstr(0) + '" "' + form_Editor.CDRoot_alt + '_CDAR\cdar.exe"'
   1.312 +        ), nil, sw_shownormal);
   1.313 +    except
   1.314 +      showmessage('"cdar.bat" konnte nicht ausgeführt werden'+ #10#10
   1.315 +        +'was not able to run "cdar.bat"');
   1.316 +    end;
   1.317 +
   1.318 +  // return to 'form_Editor'
   1.319 +    form_editor_createar.Close;
   1.320 +end;//--------------------------------------------------------------------------
   1.321 +
   1.322 +end.//#########################################################################################