Ignore:
Timestamp:
Feb 27, 2010, 10:32:23 AM (14 years ago)
Author:
george
Message:
  • Přidáno: Načítání parametrů volání z příkazové řádky.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/dbc_export/DBCExport.pas

    r335 r336  
    1919    DBC: TDBC;
    2020    Database: TSqlDatabase;
     21    DBCFileName: string;
     22    NewDBCFileName: string;
    2123    constructor Create(TheOwner: TComponent); override;
    2224    destructor Destroy; override;
     
    3234begin
    3335  // Quick check parameters
    34   ErrorMsg := CheckOptions('h', 'help');
    35   if ErrorMsg <> '' then begin
    36     ShowException(Exception.Create(ErrorMsg));
    37     Halt;
    38   end;
     36  //ErrorMsg := CheckOptions('h', 'help');
     37  //if ErrorMsg <> '' then begin
     38  //  ShowException(Exception.Create(ErrorMsg));
     39  //  Halt;
     40  //end;
    3941
    4042  // Parse parameters
     
    4345    Halt;
    4446  end;
     47  if HasOption('f', 'file') then begin
     48    DBCFileName := GetOptionValue('f', 'file');
     49    NewDBCFileName := Copy(DBCFileName, 1, Length(DBCFileName) -
     50      Length(ExtractFileExt(DBCFileName))) + '-2.dbc';
     51  end else begin
     52    WriteLn('Source DBC file not specified.');
     53    Halt;
     54  end;
     55  if HasOption('n', 'newfile') then begin
     56    NewDBCFileName := GetOptionValue('n', 'newfile');
     57  end;
     58
     59  if HasOption('s', 'schema') then begin
     60    Database.Database := GetOptionValue('s', 'schema');
     61  end else Database.Database := 'wowpreklad';
     62  if HasOption('u', 'user') then begin
     63    Database.UserName := GetOptionValue('u', 'user');
     64  end else Database.UserName := 'root';
     65  if HasOption('p', 'password') then begin
     66    Database.Password := GetOptionValue('p', 'password');
     67  end else Database.Password := '';
     68  if HasOption('t', 'host') then begin
     69    Database.Hostname := GetOptionValue('t', 'host');
     70  end else Database.Hostname := 'localhost';
     71
     72
    4573  ShowDBC;
    4674
     
    5381  inherited Create(TheOwner);
    5482  StopOnException := True;
     83  Database := TSqlDatabase.Create;;
    5584end;
    5685
    5786destructor TDBCExport.Destroy;
    5887begin
     88  Database.Destroy;
    5989  inherited Destroy;
    6090end;
     
    6292procedure TDBCExport.WriteHelp;
    6393begin
    64   { add your help code here }
    65   WriteLn('Usage: ', ExeName, ' -h');
     94  WriteLn('Usage: ', ExtractFileName(ExeName), ' [options]');
     95  WriteLn('  -h --help      Show this help');
     96  WriteLn('  -u --user      Database user name');
     97  WriteLn('  -p --password  Database password name');
     98  WriteLn('  -s --schema    Database schema name');
     99  WriteLn('  -t --host      Database host name');
     100  WriteLn('  -f --file      Source DBC file name');
     101  WriteLn('  -n --newfile   New created DBC file name');
    66102end;
    67103
     
    73109  DBC := TDBC.Create;
    74110  with DBC do begin
    75     LoadFromFile('Spell.dbc');
    76     //LoadColumnStrings(1);
    77     //LoadColumnStrings(127);
    78     (*for Y := 0 to Length(Cells) - 1 do begin
    79       Text := '';
    80       for X := 0 to Length(Cells[Y]) - 1 do
    81        if VarIsStr(Cells[Y, X]) then Text := Text + Cells[Y, X] + ', '
    82         else Text := Text + IntToStr(Cells[Y, X]) + ', ';
    83       WriteLn(Text);
    84     end;
    85     *)
    86     WriteLn('Save');
    87     SaveToFile('Spell2.dbc');
     111    if FileExists(DBCFileName) then begin
     112      LoadFromFile(DBCFileName);
     113      //LoadColumnStrings(1);
     114      //LoadColumnStrings(127);
     115      (*for Y := 0 to Length(Cells) - 1 do begin
     116        Text := '';
     117        for X := 0 to Length(Cells[Y]) - 1 do
     118         if VarIsStr(Cells[Y, X]) then Text := Text + Cells[Y, X] + ', '
     119          else Text := Text + IntToStr(Cells[Y, X]) + ', ';
     120        WriteLn(Text);
     121      end;
     122      *)
     123      WriteLn('Save');
     124      SaveToFile(NewDBCFileName);
     125    end else WriteLn('File ' + DBCFileName + ' not exists.');
    88126    Free;
    89127  end;
Note: See TracChangeset for help on using the changeset viewer.