1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// ArchiveCommandLine.cpp
2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "StdAfx.h"
4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef _WIN32
6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef UNDER_CE
7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <io.h>
8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include <stdio.h>
11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Common/ListFileUtils.h"
13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Common/StringConvert.h"
14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Common/StringToInt.h"
15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Windows/FileDir.h"
17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Windows/FileName.h"
18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef _WIN32
19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Windows/FileMapping.h"
20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Windows/Synchronization.h"
21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "ArchiveCommandLine.h"
24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "EnumDirItems.h"
25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "SortUtils.h"
26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "Update.h"
27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "UpdateAction.h"
28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
29baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern bool g_CaseSensitive;
30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef UNDER_CE
32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define MY_IS_TERMINAL(x) false;
34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#else
36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#if _MSC_VER >= 1400
38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define MY_isatty_fileno(x) _isatty(_fileno(x))
39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#else
40baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define MY_isatty_fileno(x) isatty(fileno(x))
41baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0);
44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
47baa3858d3f5d128a5c8466b700098109edcad5f2repo syncusing namespace NCommandLineParser;
48baa3858d3f5d128a5c8466b700098109edcad5f2repo syncusing namespace NWindows;
49baa3858d3f5d128a5c8466b700098109edcad5f2repo syncusing namespace NFile;
50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
51baa3858d3f5d128a5c8466b700098109edcad5f2repo syncint g_CodePage = -1;
52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
53baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace NKey {
54baa3858d3f5d128a5c8466b700098109edcad5f2repo syncenum Enum
55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kHelp1 = 0,
57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kHelp2,
58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kHelp3,
59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kDisableHeaders,
60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kDisablePercents,
61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kArchiveType,
62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kYes,
63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  #ifndef _NO_CRYPTO
64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kPassword,
65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  #endif
66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kProperty,
67baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kOutputDir,
68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kWorkingDir,
69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kInclude,
70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kExclude,
71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kArInclude,
72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kArExclude,
73baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kNoArName,
74baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kUpdate,
75baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kVolume,
76baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kRecursed,
77baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kSfx,
78baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kStdIn,
79baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kStdOut,
80baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kOverwrite,
81baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kEmail,
82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kShowDialog,
83baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kLargePages,
84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kListfileCharSet,
85baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kConsoleCharSet,
86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kTechMode,
87baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kShareForWrite,
88baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kCaseSensitive,
89baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  kCalcCrc
90baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
91baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
92baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
93baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
94baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
95baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const wchar_t kRecursedIDChar = 'R';
96baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const wchar_t *kRecursedPostCharSet = L"0-";
97baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
98baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace NRecursedPostCharIndex {
99baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  enum EEnum
100baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
101baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    kWildCardRecursionOnly = 0,
102baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    kNoRecursion = 1
103baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  };
104baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
105baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
106baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char kImmediateNameID = '!';
107baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char kMapNameID = '#';
108baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char kFileListID = '@';
109baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
110baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be
111baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be
112baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
113baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const wchar_t *kOverwritePostCharSet = L"asut";
114baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
115baa3858d3f5d128a5c8466b700098109edcad5f2repo syncNExtract::NOverwriteMode::EEnum k_OverwriteModes[] =
116baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
117baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  NExtract::NOverwriteMode::kWithoutPrompt,
118baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  NExtract::NOverwriteMode::kSkipExisting,
119baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  NExtract::NOverwriteMode::kAutoRename,
120baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  NExtract::NOverwriteMode::kAutoRenameExisting
121baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
122baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
123baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const CSwitchForm kSwitchForms[] =
124baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
125baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"?",  NSwitchType::kSimple, false },
126baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"H",  NSwitchType::kSimple, false },
127baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"-HELP",  NSwitchType::kSimple, false },
128baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"BA", NSwitchType::kSimple, false },
129baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"BD", NSwitchType::kSimple, false },
130baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"T",  NSwitchType::kUnLimitedPostString, false, 1 },
131baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"Y",  NSwitchType::kSimple, false },
132baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    #ifndef _NO_CRYPTO
133baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"P",  NSwitchType::kUnLimitedPostString, false, 0 },
134baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    #endif
135baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"M",  NSwitchType::kUnLimitedPostString, true, 1 },
136baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"O",  NSwitchType::kUnLimitedPostString, false, 1 },
137baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"W",  NSwitchType::kUnLimitedPostString, false, 0 },
138baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"I",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},
139baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"X",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},
140baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"AI", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},
141baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"AX", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},
142baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"AN", NSwitchType::kSimple, false },
143baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"U",  NSwitchType::kUnLimitedPostString, true, 1},
144baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"V",  NSwitchType::kUnLimitedPostString, true, 1},
145baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"R",  NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },
146baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SFX", NSwitchType::kUnLimitedPostString, false, 0 },
147baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SI", NSwitchType::kUnLimitedPostString, false, 0 },
148baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SO", NSwitchType::kSimple, false, 0 },
149baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"AO", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet},
150baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SEML", NSwitchType::kUnLimitedPostString, false, 0},
151baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"AD",  NSwitchType::kSimple, false },
152baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SLP", NSwitchType::kUnLimitedPostString, false, 0},
153baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SCS", NSwitchType::kUnLimitedPostString, false, 0},
154baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SCC", NSwitchType::kUnLimitedPostString, false, 0},
155baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SLT", NSwitchType::kSimple, false },
156baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SSW", NSwitchType::kSimple, false },
157baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SSC", NSwitchType::kPostChar, false, 0, 0, L"-" },
158baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    { L"SCRC", NSwitchType::kSimple, false }
159baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  };
160baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
161baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const CCommandForm g_CommandForms[] =
162baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
163baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"A", false },
164baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"U", false },
165baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"D", false },
166baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"T", false },
167baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"E", false },
168baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"X", false },
169baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"L", false },
170baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"B", false },
171baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"I", false }
172baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
173baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
174baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const int kNumCommandForms = sizeof(g_CommandForms) /  sizeof(g_CommandForms[0]);
175baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
176baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const wchar_t *kUniversalWildcard = L"*";
177baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const int kMinNonSwitchWords = 1;
178baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const int kCommandIndex = 0;
179baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
180baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// ---------------------------
181baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// exception messages
182baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
183baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char *kUserErrorMessage  = "Incorrect command line";
184baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char *kCannotFindListFile = "Cannot find listfile";
185baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char *kIncorrectListFile = "Incorrect item in listfile.\nCheck charset encoding and -scs switch.";
186baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char *kIncorrectWildCardInListFile = "Incorrect wildcard in listfile";
187baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char *kIncorrectWildCardInCommandLine  = "Incorrect wildcard in command line";
188baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char *kTerminalOutError = "I won't write compressed data to a terminal";
189baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char *kSameTerminalError = "I won't write data and program's messages to same terminal";
190baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char *kEmptyFilePath = "Empty file path";
191baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
192baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void ThrowException(const char *errorMessage)
193baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
194baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  throw CArchiveCommandLineException(errorMessage);
195baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
196baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
197baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void ThrowUserErrorException()
198baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
199baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  ThrowException(kUserErrorMessage);
200baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
201baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
202baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// ---------------------------
203baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
204baa3858d3f5d128a5c8466b700098109edcad5f2repo syncbool CArchiveCommand::IsFromExtractGroup() const
205baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
206baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  switch(CommandType)
207baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
208baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NCommandType::kTest:
209baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NCommandType::kExtract:
210baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NCommandType::kFullExtract:
211baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return true;
212baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    default:
213baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return false;
214baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
215baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
216baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
217baa3858d3f5d128a5c8466b700098109edcad5f2repo syncNExtract::NPathMode::EEnum CArchiveCommand::GetPathMode() const
218baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
219baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  switch(CommandType)
220baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
221baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NCommandType::kTest:
222baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NCommandType::kFullExtract:
223baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return NExtract::NPathMode::kFullPathnames;
224baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    default:
225baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return NExtract::NPathMode::kNoPathnames;
226baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
227baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
228baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
229baa3858d3f5d128a5c8466b700098109edcad5f2repo syncbool CArchiveCommand::IsFromUpdateGroup() const
230baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
231baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return (CommandType == NCommandType::kAdd ||
232baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CommandType == NCommandType::kUpdate ||
233baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CommandType == NCommandType::kDelete);
234baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
235baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
236baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic NRecursedType::EEnum GetRecursedTypeFromIndex(int index)
237baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
238baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  switch (index)
239baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
240baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NRecursedPostCharIndex::kWildCardRecursionOnly:
241baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return NRecursedType::kWildCardOnlyRecursed;
242baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NRecursedPostCharIndex::kNoRecursion:
243baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return NRecursedType::kNonRecursed;
244baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    default:
245baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return NRecursedType::kRecursed;
246baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
247baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
248baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
249baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)
250baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
251baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UString commandStringUpper = commandString;
252baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  commandStringUpper.MakeUpper();
253baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UString postString;
254baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper,
255baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      postString) ;
256baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (commandIndex < 0)
257baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return false;
258baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  command.CommandType = (NCommandType::EEnum)commandIndex;
259baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return true;
260baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
261baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
262baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// ------------------------------------------------------------------
263baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// filenames functions
264baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
265baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void AddNameToCensor(NWildcard::CCensor &wildcardCensor,
266baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UString &name, bool include, NRecursedType::EEnum type)
267baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
268baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool recursed = false;
269baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
270baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  switch (type)
271baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
272baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NRecursedType::kWildCardOnlyRecursed:
273baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      recursed = DoesNameContainWildCard(name);
274baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      break;
275baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NRecursedType::kRecursed:
276baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      recursed = true;
277baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      break;
278baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
279baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  wildcardCensor.AddItem(include, name, recursed);
280baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
281baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
282baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,
283baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)
284baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
285baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UStringVector names;
286baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (!NFind::DoesFileExist(fileName))
287baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    throw kCannotFindListFile;
288baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (!ReadNamesFromListFile(fileName, names, codePage))
289baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    throw kIncorrectListFile;
290baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (int i = 0; i < names.Size(); i++)
291baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    AddNameToCensor(wildcardCensor, names[i], include, type);
292baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
293baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
294baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void AddToCensorFromNonSwitchesStrings(
295baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int startIndex,
296baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NWildcard::CCensor &wildcardCensor,
297baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UStringVector &nonSwitchStrings, NRecursedType::EEnum type,
298baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    bool thereAreSwitchIncludes, UINT codePage)
299baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
300baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes))
301baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    AddNameToCensor(wildcardCensor, kUniversalWildcard, true, type);
302baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (int i = startIndex; i < nonSwitchStrings.Size(); i++)
303baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
304baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UString &s = nonSwitchStrings[i];
305baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (s.IsEmpty())
306baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      throw kEmptyFilePath;
307baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (s[0] == kFileListID)
308baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);
309baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else
310baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      AddNameToCensor(wildcardCensor, s, true, type);
311baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
312baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
313baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
314baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef _WIN32
315baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor,
316baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UString &switchParam, bool include,
317baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NRecursedType::EEnum commonRecursedType)
318baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
319baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int splitPos = switchParam.Find(L':');
320baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (splitPos < 0)
321baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ThrowUserErrorException();
322baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UString mappingName = switchParam.Left(splitPos);
323baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
324baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UString switchParam2 = switchParam.Mid(splitPos + 1);
325baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  splitPos = switchParam2.Find(L':');
326baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (splitPos < 0)
327baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ThrowUserErrorException();
328baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
329baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UString mappingSize = switchParam2.Left(splitPos);
330baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UString eventName = switchParam2.Mid(splitPos + 1);
331baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
332baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 dataSize64 = ConvertStringToUInt64(mappingSize, NULL);
333baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt32 dataSize = (UInt32)dataSize64;
334baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
335baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CFileMapping fileMapping;
336baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (fileMapping.Open(FILE_MAP_READ, GetSystemString(mappingName)) != 0)
337baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ThrowException("Can not open mapping");
338baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    LPVOID data = fileMapping.Map(FILE_MAP_READ, 0, dataSize);
339baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (data == NULL)
340baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ThrowException("MapViewOfFile error");
341baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    try
342baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
343baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      const wchar_t *curData = (const wchar_t *)data;
344baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (*curData != 0)
345baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        ThrowException("Incorrect mapping data");
346baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      UInt32 numChars = dataSize / sizeof(wchar_t);
347baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      UString name;
348baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      for (UInt32 i = 1; i < numChars; i++)
349baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
350baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        wchar_t c = curData[i];
351baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (c == L'\0')
352baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        {
353baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          AddNameToCensor(wildcardCensor, name, include, commonRecursedType);
354baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          name.Empty();
355baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        }
356baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        else
357baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          name += c;
358baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
359baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (!name.IsEmpty())
360baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        ThrowException("data error");
361baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
362baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    catch(...)
363baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
364baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      UnmapViewOfFile(data);
365baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      throw;
366baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
367baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UnmapViewOfFile(data);
368baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
369baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
370baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
371baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NSynchronization::CManualResetEvent event;
372baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK)
373baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      event.Set();
374baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
375baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
376baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
377baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
378baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,
379baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UStringVector &strings, bool include,
380baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NRecursedType::EEnum commonRecursedType, UINT codePage)
381baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
382baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (int i = 0; i < strings.Size(); i++)
383baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
384baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UString &name = strings[i];
385baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NRecursedType::EEnum recursedType;
386baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int pos = 0;
387baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (name.Length() < kSomeCludePostStringMinSize)
388baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ThrowUserErrorException();
389baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (::MyCharUpper(name[pos]) == kRecursedIDChar)
390baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
391baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      pos++;
392baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      int index = UString(kRecursedPostCharSet).Find(name[pos]);
393baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      recursedType = GetRecursedTypeFromIndex(index);
394baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (index >= 0)
395baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        pos++;
396baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
397baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else
398baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      recursedType = commonRecursedType;
399baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)
400baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ThrowUserErrorException();
401baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UString tail = name.Mid(pos + 1);
402baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (name[pos] == kImmediateNameID)
403baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      AddNameToCensor(wildcardCensor, tail, include, recursedType);
404baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else if (name[pos] == kFileListID)
405baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);
406baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    #ifdef _WIN32
407baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else if (name[pos] == kMapNameID)
408baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ParseMapWithPaths(wildcardCensor, tail, include, recursedType);
409baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    #endif
410baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else
411baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ThrowUserErrorException();
412baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
413baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
414baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
415baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef _WIN32
416baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
417baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// This code converts all short file names to long file names.
418baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
419baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void ConvertToLongName(const UString &prefix, UString &name)
420baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
421baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (name.IsEmpty() || DoesNameContainWildCard(name))
422baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return;
423baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  NFind::CFileInfoW fi;
424baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (fi.Find(prefix + name))
425baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    name = fi.Name;
426baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
427baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
428baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)
429baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
430baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (int i = 0; i < items.Size(); i++)
431baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
432baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NWildcard::CItem &item = items[i];
433baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (item.Recursive || item.PathParts.Size() != 1)
434baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      continue;
435baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ConvertToLongName(prefix, item.PathParts.Front());
436baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
437baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
438baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
439baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)
440baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
441baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  ConvertToLongNames(prefix, node.IncludeItems);
442baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  ConvertToLongNames(prefix, node.ExcludeItems);
443baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int i;
444baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (i = 0; i < node.SubNodes.Size(); i++)
445baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ConvertToLongName(prefix, node.SubNodes[i].Name);
446baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  // mix folders with same name
447baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (i = 0; i < node.SubNodes.Size(); i++)
448baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
449baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];
450baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int j = i + 1; j < node.SubNodes.Size();)
451baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
452baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];
453baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (nextNode1.Name.CompareNoCase(nextNode2.Name) == 0)
454baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
455baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        nextNode1.IncludeItems += nextNode2.IncludeItems;
456baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        nextNode1.ExcludeItems += nextNode2.ExcludeItems;
457baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        node.SubNodes.Delete(j);
458baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
459baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else
460baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        j++;
461baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
462baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
463baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (i = 0; i < node.SubNodes.Size(); i++)
464baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
465baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NWildcard::CCensorNode &nextNode = node.SubNodes[i];
466baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode);
467baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
468baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
469baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
470baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void ConvertToLongNames(NWildcard::CCensor &censor)
471baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
472baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (int i = 0; i < censor.Pairs.Size(); i++)
473baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
474baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NWildcard::CPair &pair = censor.Pairs[i];
475baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ConvertToLongNames(pair.Prefix, pair.Head);
476baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
477baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
478baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
479baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
480baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
481baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)
482baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
483baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  switch(i)
484baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
485baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;
486baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;
487baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;
488baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;
489baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
490baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  throw 98111603;
491baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
492baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
493baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst UString kUpdatePairStateIDSet = L"PQRXYZW";
494baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};
495baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
496baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst UString kUpdatePairActionIDSet = L"0123"; //Ignore, Copy, Compress, Create Anti
497baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
498baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst wchar_t *kUpdateIgnoreItselfPostStringID = L"-";
499baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst wchar_t kUpdateNewArchivePostCharID = '!';
500baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
501baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
502baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic bool ParseUpdateCommandString2(const UString &command,
503baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NUpdateArchive::CActionSet &actionSet, UString &postString)
504baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
505baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (int i = 0; i < command.Length();)
506baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
507baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    wchar_t c = MyCharUpper(command[i]);
508baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int statePos = kUpdatePairStateIDSet.Find(c);
509baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (statePos < 0)
510baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
511baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      postString = command.Mid(i);
512baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return true;
513baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
514baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    i++;
515baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (i >= command.Length())
516baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return false;
517baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));
518baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (actionPos < 0)
519baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return false;
520baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);
521baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)
522baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return false;
523baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    i++;
524baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
525baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  postString.Empty();
526baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return true;
527baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
528baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
529baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void ParseUpdateCommandString(CUpdateOptions &options,
530baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UStringVector &updatePostStrings,
531baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const NUpdateArchive::CActionSet &defaultActionSet)
532baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
533baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (int i = 0; i < updatePostStrings.Size(); i++)
534baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
535baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UString &updateString = updatePostStrings[i];
536baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)
537baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
538baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (options.UpdateArchiveItself)
539baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
540baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        options.UpdateArchiveItself = false;
541baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        options.Commands.Delete(0);
542baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
543baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
544baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else
545baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
546baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      NUpdateArchive::CActionSet actionSet = defaultActionSet;
547baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
548baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      UString postString;
549baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (!ParseUpdateCommandString2(updateString, actionSet, postString))
550baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        ThrowUserErrorException();
551baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (postString.IsEmpty())
552baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
553baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (options.UpdateArchiveItself)
554baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          options.Commands[0].ActionSet = actionSet;
555baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
556baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else
557baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
558baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)
559baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          ThrowUserErrorException();
560baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        CUpdateArchiveCommand uc;
561baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        UString archivePath = postString.Mid(1);
562baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (archivePath.IsEmpty())
563baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          ThrowUserErrorException();
564baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        uc.UserArchivePath = archivePath;
565baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        uc.ActionSet = actionSet;
566baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        options.Commands.Add(uc);
567baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
568baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
569baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
570baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
571baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
572baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char kByteSymbol = 'B';
573baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char kKiloSymbol = 'K';
574baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char kMegaSymbol = 'M';
575baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const char kGigaSymbol = 'G';
576baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
577baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic bool ParseComplexSize(const UString &src, UInt64 &result)
578baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
579baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UString s = src;
580baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  s.MakeUpper();
581baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
582baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const wchar_t *start = s;
583baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const wchar_t *end;
584baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 number = ConvertStringToUInt64(start, &end);
585baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int numDigits = (int)(end - start);
586baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (numDigits == 0 || s.Length() > numDigits + 1)
587baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return false;
588baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (s.Length() == numDigits)
589baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
590baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    result = number;
591baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return true;
592baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
593baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int numBits;
594baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  switch (s[numDigits])
595baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
596baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case kByteSymbol:
597baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      result = number;
598baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return true;
599baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case kKiloSymbol:
600baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      numBits = 10;
601baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      break;
602baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case kMegaSymbol:
603baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      numBits = 20;
604baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      break;
605baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case kGigaSymbol:
606baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      numBits = 30;
607baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      break;
608baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    default:
609baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return false;
610baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
611baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (number >= ((UInt64)1 << (64 - numBits)))
612baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return false;
613baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  result = number << numBits;
614baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return true;
615baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
616baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
617baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void SetAddCommandOptions(
618baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NCommandType::EEnum commandType,
619baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const CParser &parser,
620baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CUpdateOptions &options)
621baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
622baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  NUpdateArchive::CActionSet defaultActionSet;
623baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  switch(commandType)
624baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
625baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NCommandType::kAdd:
626baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      defaultActionSet = NUpdateArchive::kAddActionSet;
627baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      break;
628baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    case NCommandType::kDelete:
629baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      defaultActionSet = NUpdateArchive::kDeleteActionSet;
630baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      break;
631baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    default:
632baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      defaultActionSet = NUpdateArchive::kUpdateActionSet;
633baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
634baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
635baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.UpdateArchiveItself = true;
636baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
637baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.Commands.Clear();
638baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CUpdateArchiveCommand updateMainCommand;
639baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  updateMainCommand.ActionSet = defaultActionSet;
640baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.Commands.Add(updateMainCommand);
641baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (parser[NKey::kUpdate].ThereIs)
642baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings,
643baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        defaultActionSet);
644baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (parser[NKey::kWorkingDir].ThereIs)
645baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
646baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];
647baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (postString.IsEmpty())
648baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      NDirectory::MyGetTempPath(options.WorkingDir);
649baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else
650baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      options.WorkingDir = postString;
651baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
652baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.SfxMode = parser[NKey::kSfx].ThereIs;
653baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (options.SfxMode)
654baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    options.SfxModule = parser[NKey::kSfx].PostStrings[0];
655baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
656baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (parser[NKey::kVolume].ThereIs)
657baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
658baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UStringVector &sv = parser[NKey::kVolume].PostStrings;
659baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int i = 0; i < sv.Size(); i++)
660baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
661baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      UInt64 size;
662baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (!ParseComplexSize(sv[i], size))
663baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        ThrowException("Incorrect volume size");
664baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      options.VolumesSizes.Add(size);
665baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
666baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
667baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
668baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
669baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &properties)
670baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
671baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (parser[NKey::kProperty].ThereIs)
672baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
673baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    // options.MethodMode.Properties.Clear();
674baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)
675baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
676baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      CProperty property;
677baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      const UString &postString = parser[NKey::kProperty].PostStrings[i];
678baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      int index = postString.Find(L'=');
679baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (index < 0)
680baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        property.Name = postString;
681baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else
682baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
683baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        property.Name = postString.Left(index);
684baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        property.Value = postString.Mid(index + 1);
685baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
686baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      properties.Add(property);
687baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
688baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
689baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
690baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
691baa3858d3f5d128a5c8466b700098109edcad5f2repo syncCArchiveCommandLineParser::CArchiveCommandLineParser():
692baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {}
693baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
694baa3858d3f5d128a5c8466b700098109edcad5f2repo syncvoid CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings,
695baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CArchiveCommandLineOptions &options)
696baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
697baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  try
698baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
699baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    parser.ParseStrings(kSwitchForms, commandStrings);
700baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
701baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  catch(...)
702baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
703baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ThrowUserErrorException();
704baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
705baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
706baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.IsInTerminal = MY_IS_TERMINAL(stdin);
707baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.IsStdOutTerminal = MY_IS_TERMINAL(stdout);
708baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.IsStdErrTerminal = MY_IS_TERMINAL(stderr);
709baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.StdInMode = parser[NKey::kStdIn].ThereIs;
710baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.StdOutMode = parser[NKey::kStdOut].ThereIs;
711baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;
712baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs  || parser[NKey::kHelp3].ThereIs;
713baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
714baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  #ifdef _WIN32
715baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.LargePages = false;
716baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (parser[NKey::kLargePages].ThereIs)
717baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
718baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const UString &postString = parser[NKey::kLargePages].PostStrings.Front();
719baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (postString.IsEmpty())
720baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      options.LargePages = true;
721baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
722baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  #endif
723baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
724baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
725baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CCodePagePair
726baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
727baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const wchar_t *Name;
728baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UINT CodePage;
729baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
730baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
731baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic CCodePagePair g_CodePagePairs[] =
732baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
733baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"UTF-8", CP_UTF8 },
734baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"WIN", CP_ACP },
735baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  { L"DOS", CP_OEMCP }
736baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
737baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
738baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic int FindCharset(const NCommandLineParser::CParser &parser, int keyIndex, int defaultVal)
739baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
740baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (!parser[keyIndex].ThereIs)
741baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return defaultVal;
742baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
743baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UString name = parser[keyIndex].PostStrings.Back();
744baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  name.MakeUpper();
745baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int i;
746baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (i = 0; i < sizeof(g_CodePagePairs) / sizeof(g_CodePagePairs[0]); i++)
747baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
748baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    const CCodePagePair &pair = g_CodePagePairs[i];
749baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (name.Compare(pair.Name) == 0)
750baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return pair.CodePage;
751baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
752baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (i == sizeof(g_CodePagePairs) / sizeof(g_CodePagePairs[0]))
753baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ThrowUserErrorException();
754baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return -1;
755baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
756baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
757baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)
758baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
759baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const wchar_t *end;
760baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 number = ConvertStringToUInt64(s, &end);
761baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (*end != 0)
762baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return false;
763baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (number > (UInt32)0xFFFFFFFF)
764baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return false;
765baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  v = (UInt32)number;
766baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  return true;
767baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
768baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
769baa3858d3f5d128a5c8466b700098109edcad5f2repo syncvoid EnumerateDirItemsAndSort(NWildcard::CCensor &wildcardCensor,
770baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UStringVector &sortedPaths,
771baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UStringVector &sortedFullPaths)
772baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
773baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UStringVector paths;
774baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
775baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CDirItems dirItems;
776baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
777baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      UStringVector errorPaths;
778baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      CRecordVector<DWORD> errorCodes;
779baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      HRESULT res = EnumerateItems(wildcardCensor, dirItems, NULL, errorPaths, errorCodes);
780baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (res != S_OK || errorPaths.Size() > 0)
781baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        throw "cannot find archive";
782baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
783baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int i = 0; i < dirItems.Items.Size(); i++)
784baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
785baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      const CDirItem &dirItem = dirItems.Items[i];
786baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (!dirItem.IsDir())
787baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        paths.Add(dirItems.GetPhyPath(i));
788baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
789baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
790baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
791baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (paths.Size() == 0)
792baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    throw "there is no such archive";
793baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
794baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UStringVector fullPaths;
795baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
796baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int i;
797baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (i = 0; i < paths.Size(); i++)
798baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
799baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UString fullPath;
800baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NFile::NDirectory::MyGetFullPathName(paths[i], fullPath);
801baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    fullPaths.Add(fullPath);
802baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
803baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CIntVector indices;
804baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  SortFileNames(fullPaths, indices);
805baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  sortedPaths.Reserve(indices.Size());
806baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  sortedFullPaths.Reserve(indices.Size());
807baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  for (i = 0; i < indices.Size(); i++)
808baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
809baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    int index = indices[i];
810baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    sortedPaths.Add(paths[index]);
811baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    sortedFullPaths.Add(fullPaths[index]);
812baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
813baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
814baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
815baa3858d3f5d128a5c8466b700098109edcad5f2repo syncvoid CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)
816baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
817baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
818baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int numNonSwitchStrings = nonSwitchStrings.Size();
819baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (numNonSwitchStrings < kMinNonSwitchWords)
820baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ThrowUserErrorException();
821baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
822baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command))
823baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ThrowUserErrorException();
824baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
825baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.TechMode = parser[NKey::kTechMode].ThereIs;
826baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.CalcCrc = parser[NKey::kCalcCrc].ThereIs;
827baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
828baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (parser[NKey::kCaseSensitive].ThereIs)
829baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0);
830baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
831baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  NRecursedType::EEnum recursedType;
832baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (parser[NKey::kRecursed].ThereIs)
833baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);
834baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  else
835baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    recursedType = NRecursedType::kNonRecursed;
836baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
837baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  g_CodePage = FindCharset(parser, NKey::kConsoleCharSet, -1);
838baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UINT codePage = FindCharset(parser, NKey::kListfileCharSet, CP_UTF8);
839baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
840baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool thereAreSwitchIncludes = false;
841baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (parser[NKey::kInclude].ThereIs)
842baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
843baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    thereAreSwitchIncludes = true;
844baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    AddSwitchWildCardsToCensor(options.WildcardCensor,
845baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        parser[NKey::kInclude].PostStrings, true, recursedType, codePage);
846baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
847baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (parser[NKey::kExclude].ThereIs)
848baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    AddSwitchWildCardsToCensor(options.WildcardCensor,
849baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        parser[NKey::kExclude].PostStrings, false, recursedType, codePage);
850baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
851baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int curCommandIndex = kCommandIndex + 1;
852baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs &&
853baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      options.Command.CommandType != NCommandType::kBenchmark &&
854baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      options.Command.CommandType != NCommandType::kInfo;
855baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
856baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();
857baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool isExtractOrList = isExtractGroupCommand || options.Command.CommandType == NCommandType::kList;
858baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
859baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (isExtractOrList && options.StdInMode)
860baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    thereIsArchiveName = false;
861baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
862baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (thereIsArchiveName)
863baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
864baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (curCommandIndex >= numNonSwitchStrings)
865baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ThrowUserErrorException();
866baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    options.ArchiveName = nonSwitchStrings[curCommandIndex++];
867baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (options.ArchiveName.IsEmpty())
868baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ThrowUserErrorException();
869baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
870baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
871baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  AddToCensorFromNonSwitchesStrings(
872baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      curCommandIndex, options.WildcardCensor,
873baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage);
874baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
875baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.YesToAll = parser[NKey::kYes].ThereIs;
876baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
877baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
878baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  #ifndef _NO_CRYPTO
879baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.PasswordEnabled = parser[NKey::kPassword].ThereIs;
880baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (options.PasswordEnabled)
881baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    options.Password = parser[NKey::kPassword].PostStrings[0];
882baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  #endif
883baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
884baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.ShowDialog = parser[NKey::kShowDialog].ThereIs;
885baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
886baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (parser[NKey::kArchiveType].ThereIs)
887baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    options.ArcType = parser[NKey::kArchiveType].PostStrings[0];
888baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
889baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  if (isExtractOrList)
890baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
891baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (!options.WildcardCensor.AllAreRelative())
892baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      ThrowException("Cannot use absolute pathnames for this command");
893baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
894baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    NWildcard::CCensor archiveWildcardCensor;
895baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
896baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (parser[NKey::kArInclude].ThereIs)
897baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      AddSwitchWildCardsToCensor(archiveWildcardCensor,
898baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);
899baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (parser[NKey::kArExclude].ThereIs)
900baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      AddSwitchWildCardsToCensor(archiveWildcardCensor,
901baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);
902baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
903baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (thereIsArchiveName)
904baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      AddNameToCensor(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);
905baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
906baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    #ifdef _WIN32
907baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ConvertToLongNames(archiveWildcardCensor);
908baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    #endif
909baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
910baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    archiveWildcardCensor.ExtendExclude();
911baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
912baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (options.StdInMode)
913baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
914baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      UString arcName = parser[NKey::kStdIn].PostStrings.Front();
915baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      options.ArchivePathsSorted.Add(arcName);
916baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      options.ArchivePathsFullSorted.Add(arcName);
917baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
918baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    else
919baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
920baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      EnumerateDirItemsAndSort(archiveWildcardCensor,
921baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        options.ArchivePathsSorted,
922baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        options.ArchivePathsFullSorted);
923baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
924baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
925baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (isExtractGroupCommand)
926baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
927baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      SetMethodOptions(parser, options.ExtractProperties);
928baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)
929baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        throw kSameTerminalError;
930baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (parser[NKey::kOutputDir].ThereIs)
931baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
932baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];
933baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        NFile::NName::NormalizeDirPathPrefix(options.OutputDir);
934baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
935baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
936baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;
937baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (parser[NKey::kOverwrite].ThereIs)
938baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        options.OverwriteMode = k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];
939baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else if (options.YesToAll)
940baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;
941baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
942baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
943baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  else if (options.Command.IsFromUpdateGroup())
944baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
945baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CUpdateOptions &updateOptions = options.UpdateOptions;
946baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
947baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    SetAddCommandOptions(options.Command.CommandType, parser, updateOptions);
948baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
949baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    SetMethodOptions(parser, updateOptions.MethodMode.Properties);
950baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
951baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (parser[NKey::kShareForWrite].ThereIs)
952baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      updateOptions.OpenShareForWrite = true;
953baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
954baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs;
955baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
956baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (options.EnablePercents)
957baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
958baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if ((options.StdOutMode && !options.IsStdErrTerminal) ||
959baa3858d3f5d128a5c8466b700098109edcad5f2repo sync         (!options.StdOutMode && !options.IsStdOutTerminal))
960baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        options.EnablePercents = false;
961baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
962baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
963baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;
964baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (updateOptions.EMailMode)
965baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
966baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front();
967baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (updateOptions.EMailAddress.Length() > 0)
968baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (updateOptions.EMailAddress[0] == L'.')
969baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        {
970baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          updateOptions.EMailRemoveAfter = true;
971baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          updateOptions.EMailAddress.Delete(0);
972baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        }
973baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
974baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
975baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    updateOptions.StdOutMode = options.StdOutMode;
976baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    updateOptions.StdInMode = options.StdInMode;
977baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
978baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (updateOptions.StdOutMode && updateOptions.EMailMode)
979baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      throw "stdout mode and email mode cannot be combined";
980baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (updateOptions.StdOutMode && options.IsStdOutTerminal)
981baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      throw kTerminalOutError;
982baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (updateOptions.StdInMode)
983baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();
984baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
985baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    #ifdef _WIN32
986baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ConvertToLongNames(options.WildcardCensor);
987baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    #endif
988baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
989baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  else if (options.Command.CommandType == NCommandType::kBenchmark)
990baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
991baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    options.NumThreads = (UInt32)-1;
992baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    options.DictionarySize = (UInt32)-1;
993baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    options.NumIterations = 1;
994baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    if (curCommandIndex < numNonSwitchStrings)
995baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
996baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))
997baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        ThrowUserErrorException();
998baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
999baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)
1000baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
1001baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      UString postString = parser[NKey::kProperty].PostStrings[i];
1002baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      postString.MakeUpper();
1003baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (postString.Length() < 2)
1004baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        ThrowUserErrorException();
1005baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (postString[0] == 'D')
1006baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
1007baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        int pos = 1;
1008baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (postString[pos] == '=')
1009baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          pos++;
1010baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        UInt32 logSize;
1011baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))
1012baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          ThrowUserErrorException();
1013baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (logSize > 31)
1014baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          ThrowUserErrorException();
1015baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        options.DictionarySize = 1 << logSize;
1016baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
1017baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else if (postString[0] == 'M' && postString[1] == 'T' )
1018baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
1019baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        int pos = 2;
1020baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (postString[pos] == '=')
1021baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          pos++;
1022baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (postString[pos] != 0)
1023baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))
1024baa3858d3f5d128a5c8466b700098109edcad5f2repo sync            ThrowUserErrorException();
1025baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
1026baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else if (postString[0] == 'M' && postString[1] == '=' )
1027baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {
1028baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        int pos = 2;
1029baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        if (postString[pos] != 0)
1030baa3858d3f5d128a5c8466b700098109edcad5f2repo sync          options.Method = postString.Mid(2);
1031baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      }
1032baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      else
1033baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        ThrowUserErrorException();
1034baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
1035baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
1036baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  else if (options.Command.CommandType == NCommandType::kInfo)
1037baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
1038baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
1039baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  else
1040baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    ThrowUserErrorException();
1041baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  options.WildcardCensor.ExtendExclude();
1042baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}
1043