Subversion Repositories autosfx

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 daniel-mar 1
unit SFXBehavior;
2
 
3
interface
4
 
5
uses
6
  SysUtils;
7
 
8
type
9
  TConflictBehavior = (cbAvoid, cbOverwrite, cbNewer, cbAsk);
10
 
11
  TCommentPresentation = (cpNone, cpBeforeExtracting, cpAfterExtracting);
12
 
13
  TExtractionTarget = (etExtractHere, etDesktop, etAsk);
14
 
15
  TZIPBehavior = record
16
    ConflictBehavior: TConflictBehavior;
17
    CommentPresentation: TCommentPresentation;
18
    ExtractionTarget: TExtractionTarget;
19
  end;
20
 
21
function ReadBehavior(c: string): TZIPBehavior;
22
function StripBehavior(c: string): string;
23
function BehaviorStrings(bh: TZipBehavior): string;
24
function RelocateBehaviorStringsToEnd(c: string): string;
25
 
26
implementation
27
 
28
const
29
  C_SIGNATURE   = 'ViaThinkSoft AutoSFX Archive Configuration';
30
 
31
  C_ASFX_CB_OVR = 'AutoSFX Conflict Behavior: Overwrite all';
32
  C_ASFX_CB_NEW = 'AutoSFX Conflict Behavior: Overwrite older';
33
  C_ASFX_CB_ASK = 'AutoSFX Conflict Behavior: Ask';
34
  C_ASFX_CB_AVO = 'AutoSFX Conflict Behavior: Avoid';
35
 
36
  C_ASFX_CP_BEF = 'AutoSFX Comment Presentation: Before extracting';
37
  C_ASFX_CP_AFT = 'AutoSFX Comment Presentation: After extracting';
38
  C_ASFX_CP_NON = 'AutoSFX Comment Presentation: None';
39
 
40
  C_ASFX_ET_HER = 'AutoSFX Extraction Target: Extract here';
41
  C_ASFX_ET_DES = 'AutoSFX Extraction Target: Extract to Desktop';
42
  C_ASFX_ET_ASK = 'AutoSFX Extraction Target: Choose directory';
43
 
2 daniel-mar 44
  EINRUECK      = '> '; // Optional to all C_ASFX
1 daniel-mar 45
 
46
const
47
  CB_DEFAULT = cbAvoid;
48
  CP_DEFAULT = cpNone;
49
  ET_DEFAULT = etExtractHere;
50
 
51
function ReadBehavior(c: string): TZIPBehavior;
52
 
53
  function Vorkommen(s: string): boolean;
54
  begin
55
    s := AnsiLowerCase(s);
56
    result := AnsiPos(s, c) > 0;
57
  end;
58
 
59
begin
60
  result.ConflictBehavior := CB_DEFAULT;
61
  result.CommentPresentation := CP_DEFAULT;
62
  result.ExtractionTarget := ET_DEFAULT;
63
 
64
  c := AnsiLowerCase(c);
65
 
66
  if Vorkommen(C_ASFX_CB_OVR) then
67
  begin
68
    result.ConflictBehavior := cbOverwrite;
69
  end
70
  else if Vorkommen(C_ASFX_CB_NEW) then
71
  begin
72
    result.ConflictBehavior := cbNewer;
73
  end
74
  else if Vorkommen(C_ASFX_CB_ASK) then
75
  begin
76
    result.ConflictBehavior := cbAsk;
77
  end
78
  else if Vorkommen(C_ASFX_CB_AVO) then
79
  begin
80
    result.ConflictBehavior := cbAvoid;
81
  end;
82
 
83
  if Vorkommen(C_ASFX_CP_BEF) then
84
  begin
85
    result.CommentPresentation := cpBeforeExtracting;
86
  end
87
  else if Vorkommen(C_ASFX_CP_AFT) then
88
  begin
89
    result.CommentPresentation := cpAfterExtracting;
90
  end
91
  else if Vorkommen(C_ASFX_CP_NON) then
92
  begin
93
    result.CommentPresentation := cpNone;
94
  end;
95
 
96
  if Vorkommen(C_ASFX_ET_HER) then
97
  begin
98
    result.ExtractionTarget := etExtractHere;
99
  end
100
  else if Vorkommen(C_ASFX_ET_DES) then
101
  begin
102
    result.ExtractionTarget := etDesktop;
103
  end
104
  else if Vorkommen(C_ASFX_ET_ASK) then
105
  begin
106
    result.ExtractionTarget := etAsk;
107
  end;
108
end;
109
 
110
function StripBehavior(c: string): string;
111
 
2 daniel-mar 112
  procedure StripIt(s: string; allowEinrueck: boolean);
1 daniel-mar 113
  begin
2 daniel-mar 114
    if allowEinrueck then
115
    begin
116
      c := StringReplace(c, EINRUECK + s+#13#10, '', [rfReplaceAll, rfIgnoreCase]);
117
      c := StringReplace(c, EINRUECK + s+#13,    '', [rfReplaceAll, rfIgnoreCase]);
118
      c := StringReplace(c, EINRUECK + s+#10,    '', [rfReplaceAll, rfIgnoreCase]);
119
      c := StringReplace(c, EINRUECK + s,        '', [rfReplaceAll, rfIgnoreCase]);
120
    end;
1 daniel-mar 121
 
122
    c := StringReplace(c, s+#13#10, '', [rfReplaceAll, rfIgnoreCase]);
123
    c := StringReplace(c, s+#13,    '', [rfReplaceAll, rfIgnoreCase]);
124
    c := StringReplace(c, s+#10,    '', [rfReplaceAll, rfIgnoreCase]);
125
    c := StringReplace(c, s,        '', [rfReplaceAll, rfIgnoreCase]);
126
  end;
127
 
128
begin
2 daniel-mar 129
  StripIt(C_SIGNATURE, false);
1 daniel-mar 130
 
2 daniel-mar 131
  StripIt(C_ASFX_CB_AVO, true);
132
  StripIt(C_ASFX_CB_OVR, true);
133
  StripIt(C_ASFX_CB_NEW, true);
134
  StripIt(C_ASFX_CB_ASK, true);
1 daniel-mar 135
 
2 daniel-mar 136
  StripIt(C_ASFX_CP_NON, true);
137
  StripIt(C_ASFX_CP_BEF, true);
138
  StripIt(C_ASFX_CP_AFT, true);
1 daniel-mar 139
 
2 daniel-mar 140
  StripIt(C_ASFX_ET_HER, true);
141
  StripIt(C_ASFX_ET_DES, true);
142
  StripIt(C_ASFX_ET_ASK, true);
1 daniel-mar 143
 
144
  result := c;
145
end;
146
 
147
function BehaviorStrings(bh: TZipBehavior): string;
148
begin
149
  result := C_SIGNATURE + #13#10 + EINRUECK;
150
 
151
  case bh.ConflictBehavior of
152
    cbAvoid:     result := result + C_ASFX_CB_AVO;
153
    cbOverwrite: result := result + C_ASFX_CB_OVR;
154
    cbNewer:     result := result + C_ASFX_CB_NEW;
155
    cbAsk:       result := result + C_ASFX_CB_ASK;
156
  end;
157
 
158
  result := result + #13#10 + EINRUECK;
159
 
160
  case bh.CommentPresentation of
161
    cpNone:             result := result + C_ASFX_CP_NON;
162
    cpBeforeExtracting: result := result + C_ASFX_CP_BEF;
163
    cpAfterExtracting:  result := result + C_ASFX_CP_AFT;
164
  end;
165
 
166
  result := result + #13#10 + EINRUECK;
167
 
168
  case bh.ExtractionTarget of
169
    etExtractHere: result := result + C_ASFX_ET_HER;
170
    etDesktop:     result := result + C_ASFX_ET_DES;
171
    etAsk:         result := result + C_ASFX_ET_ASK;
172
  end;
173
 
174
  result := result + #13#10;
175
end;
176
 
177
function RelocateBehaviorStringsToEnd(c: string): string;
178
var
179
  bh: TZIPBehavior;
180
begin
181
  bh := ReadBehavior(c);
182
  c := StripBehavior(c);
183
  c := TrimRight(c);
184
  c := c + #13#10 + #13#10;
185
  c := c + BehaviorStrings(bh);
186
  result := c;
187
end;
188
 
189
end.