|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
3 |
| -using System.IO; |
4 |
| -using System.Linq; |
5 |
| -using System.Text; |
6 |
| -using System.Threading.Tasks; |
7 |
| -using Logic.Business.Level5ScriptManagement.Contract; |
| 1 | +using Logic.Business.Level5ScriptManagement.Contract; |
8 | 2 | using Logic.Business.Level5ScriptManagement.InternalContract;
|
9 | 3 | using Logic.Domain.CodeAnalysis.Contract.Level5;
|
10 | 4 | using Logic.Domain.CodeAnalysis.Contract.Level5.DataClasses;
|
@@ -168,15 +162,16 @@ private void CreateScript(string filePath)
|
168 | 162 | // Convert to script data
|
169 | 163 | CodeUnitSyntax codeUnit = _scriptParser.ParseCodeUnit(readableScript);
|
170 | 164 |
|
171 |
| - ScriptType type = DetermineScriptType(_config.QueryType); |
172 |
| - ScriptFile script = _treeConverter.CreateScriptFile(codeUnit, type); |
| 165 | + ScriptFile script = _treeConverter.CreateScriptFile(codeUnit); |
| 166 | + script.Length = DeterminePointerLength(_config.Length); |
173 | 167 |
|
174 | 168 | // Write script data
|
| 169 | + ScriptType type = DetermineScriptType(_config.QueryType); |
175 | 170 | IScriptWriter scriptWriter = _writerFactory.Create(type);
|
176 | 171 |
|
177 | 172 | using Stream newFileStream = File.Create(filePath + ".xq");
|
178 | 173 |
|
179 |
| - scriptWriter.Write(script, newFileStream); |
| 174 | + scriptWriter.Write(script, newFileStream, !_config.WithoutCompression); |
180 | 175 | }
|
181 | 176 |
|
182 | 177 | private void DecompressScripts()
|
@@ -209,15 +204,15 @@ private void DecompressScripts()
|
209 | 204 | private void DecompressScript(string filePath)
|
210 | 205 | {
|
211 | 206 | // Decompress script data
|
212 |
| - using Stream fileStream = File.OpenRead(_config.FilePath); |
| 207 | + using Stream fileStream = File.OpenRead(filePath); |
213 | 208 |
|
214 | 209 | ScriptType type = _typeReader.Peek(fileStream);
|
215 | 210 | IScriptDecompressor decompressor = _decompressorFactory.Create(type);
|
216 | 211 |
|
217 | 212 | ScriptContainer container = decompressor.Decompress(fileStream);
|
218 | 213 |
|
219 | 214 | // Write script data
|
220 |
| - using Stream newFileStream = File.Create(_config.FilePath + ".dec"); |
| 215 | + using Stream newFileStream = File.Create(filePath + ".dec"); |
221 | 216 |
|
222 | 217 | IScriptCompressor compressor = _compressorFactory.Create(type);
|
223 | 218 |
|
@@ -264,20 +259,43 @@ private ScriptType DetermineScriptType(string type)
|
264 | 259 | }
|
265 | 260 | }
|
266 | 261 |
|
| 262 | + private PointerLength DeterminePointerLength(string type) |
| 263 | + { |
| 264 | + switch (type) |
| 265 | + { |
| 266 | + case "int": |
| 267 | + return PointerLength.Int; |
| 268 | + |
| 269 | + case "long": |
| 270 | + return PointerLength.Long; |
| 271 | + |
| 272 | + default: |
| 273 | + throw new InvalidOperationException($"Unsupported pointer length {type}"); |
| 274 | + } |
| 275 | + } |
| 276 | + |
267 | 277 | private void PrintHelp()
|
268 | 278 | {
|
269 | 279 | Console.WriteLine("Following commands exist:");
|
270 | 280 | Console.WriteLine(" -h, --help\t\tShows this help message.");
|
271 | 281 | Console.WriteLine(" -o, --operation\tThe operation to take on the file");
|
272 |
| - Console.WriteLine(" Valid operations are: e for extraction, c for creation, d for decompression"); |
273 | 282 | Console.WriteLine(" -t, --type\t\tThe type of file given");
|
274 | 283 | Console.WriteLine(" Valid types are: xq32, xseq");
|
275 | 284 | Console.WriteLine(" The type is automatically detected when extracting; This argument will not have any effect on operation 'e'");
|
| 285 | + Console.WriteLine(" Valid operations are: e for extraction, c for creation, d for decompression"); |
276 | 286 | Console.WriteLine(" -f, --file\t\tThe file to process");
|
| 287 | + Console.WriteLine(" -n, --no-compression\t[Optional] If the file uses a compression layer"); |
| 288 | + Console.WriteLine(" This option is automatically detected when extracting; This argument will not have any effect on operation 'e'"); |
| 289 | + Console.WriteLine(" -l, --length\t\t[Optional]The pointer length given"); |
| 290 | + Console.WriteLine(" Valid lengths are: int, long"); |
| 291 | + Console.WriteLine(" Default value is 'int'"); |
| 292 | + Console.WriteLine(" The length is automatically detected when extracting; This argument will not have any effect on operation 'e'"); |
277 | 293 | Console.WriteLine();
|
278 | 294 | Console.WriteLine("Examples:");
|
279 | 295 | Console.WriteLine($"\tExtract any script to human readable text: {Environment.ProcessPath} -o e -f Path/To/File.xq");
|
280 | 296 | Console.WriteLine($"\tCreate a xq32 script from human readable text: {Environment.ProcessPath} -o c -t xq32 -f Path/To/File.txt");
|
| 297 | + Console.WriteLine($"\tCreate a xq32 script with long pointers from human readable text: {Environment.ProcessPath} -o c -t xq32 -l long -f Path/To/File.txt"); |
| 298 | + Console.WriteLine($"\tCreate a xq32 script without a compression layer from human readable text: {Environment.ProcessPath} -o c -t xq32 -n -f Path/To/File.txt"); |
281 | 299 | }
|
282 | 300 |
|
283 | 301 | private Exception GetInnermostException(Exception e)
|
|
0 commit comments