-
Notifications
You must be signed in to change notification settings - Fork 3
/
CommandThreadUnit.pas
173 lines (145 loc) · 4.16 KB
/
CommandThreadUnit.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
unit CommandThreadUnit;
interface
uses
Winapi.Windows, System.SysUtils, System.Classes,
Winapi.ActiveX, ThreadUnit, ConstUnit, IOUtils;
type
TPrThreadObject = class(TThreadExecObject)
private
FLogFile: TPathName;
FDestinationPath: TPathName;
FCommand: TCommand;
procedure SetDestinationPath(const Value: TPathName);
procedure SetCommand(const Value: TCommand);
protected
procedure Execute; override;
public
property LogFile: TPathName read FLogFile;
property DestinationPath: TPathName read FDestinationPath write SetDestinationPath;
property Command: TCommand read FCommand write SetCommand;
end;
TPgConversionThreadObject = class(TPrThreadObject)
private
FSourceFile: TFileName;
FDestinationFile: TFileName;
procedure SetSourceFile(const Value: TFileName);
procedure SetDestinationFile(const Value: TFileName);
procedure ConvertSourceFileToUniCode;
protected
procedure Execute; override;
public
property SourceFile: TFileName read FSourceFile write SetSourceFile;
property DestinationFile: TFileName read FDestinationFile write SetDestinationFile;
end;
TPgnativeThreadObject = class(TPrThreadObject)
private
FSourcePath: TFileName;
FSourceFile: TFileName;
procedure SetSourcePath(const Value: TFileName);
procedure SetSourceFile(const Value: TFileName);
protected
procedure Execute; override;
public
property SourcePath: TFileName read FSourcePath write SetSourcePath;
property SourceFile: TFileName read FSourceFile write SetSourceFile;
end;
implementation
uses SqlPPConsoleUnit, regUnit;
{ TCommandThreadObject }
procedure TPrThreadObject.Execute;
var
PPConsole: TSqlPPConsole;
begin
PPConsole := TSqlPPConsole.Create;
try
PPConsole.Run(Command, ExcludeTrailingPathDelimiter(DestinationPath));
{Áåñöåííûå ðåçóëüòàòû ïðîëèâêè}
if FileExists(PPConsole.ConsoleFile) then
begin
FLogFile := PPConsole.ConsoleFile;
end;
finally
PPConsole.Free;
end;
end;
procedure TPrThreadObject.SetCommand(const Value: TCommand);
begin
FCommand := Value;
end;
procedure TPrThreadObject.SetDestinationPath(const Value: TPathName);
begin
FDestinationPath := Value;
end;
{ TPgConversionThreadObject }
procedure TPgConversionThreadObject.ConvertSourceFileToUniCode;
var
Strings: TStrings;
S: string;
PS: PAnsiChar;
i,Len : Integer;
begin
Strings := TStringList.Create;
try
Strings.LoadFromFile(FSourceFile);
for i := 0 to Strings.Count-1 do
begin
S := Strings[i];
Len := Length(S);
if Len=0 then continue;
GetMem(PS, Len + 1);
try
StrPCopy(PS, AnsiString(S));
OemToAnsi(PS, PS);
Strings[i] := String(PS);
finally
FreeMem(PS);
end;
end;
Strings.WriteBOM := False;
Strings.SaveToFile(DestinationFile,TEncoding.UTF8);
finally
Strings.Free;
end;
end;
procedure TPgConversionThreadObject.Execute;
var
ConvertString: string;
begin
{$IFNDEF NPPCONNECTIONS}
ConvertSourceFileToUniCode;
ConvertString := TOptionsReg.GetPostgreSQLConvertString;
Command := Format(ConvertString,[FDestinationFile]);
inherited;
if IOUtils.TFile.Exists(FLogFile) then
IOUtils.TFile.Copy(FLogFile, FDestinationFile, True);
{$ENDIF}
end;
procedure TPgConversionThreadObject.SetDestinationFile(const Value: TFileName);
begin
FDestinationFile := Value;
end;
procedure TPgConversionThreadObject.SetSourceFile(const Value: TFileName);
begin
FSourceFile := Value;
end;
{ TPgnativeThreadObject }
procedure TPgnativeThreadObject.Execute;
begin
{$IFNDEF NPPCONNECTIONS}
{ Command := FPgForm.Cmd;
FSourceFile := FPgForm.FileName;
FSourcePath := FPgForm.Path;
inherited;
if IOUtils.TFile.Exists(FLogFile) then
IOUtils.TFile.Copy(FLogFile, FDestinationFile, True);}
{$ENDIF}
end;
procedure TPgnativeThreadObject.SetSourceFile(const Value: TFileName);
begin
FSourceFile := Value;
end;
procedure TPgnativeThreadObject.SetSourcePath(const Value: TFileName);
begin
FSourcePath := Value;
end;
end.