annotate Class1.cs @ 0:85ff734c7605 default tip

Initial commit under GPLv3
author IBBoard <dev@ibboard.co.uk>
date Sat, 06 Oct 2018 20:29:36 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file is a part of the SGA Extractor command-line app and is copyright 2006-2018 IBBoard.
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System.IO;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Text.RegularExpressions;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using IBBoard.Relic.RelicTools;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 namespace SgaExtractor
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 /// <summary>
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 /// Summary description for Class1.
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 /// </summary>
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 class Class1
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 private const int DEFAULT_MODE = 2;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 private static readonly string nl = System.Environment.NewLine;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 private static string dest;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 private static SgaArchive archive;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 private static ArrayList paths;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 private static bool overwrite = false;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 private static bool recursive = false;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 private static string ext;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 private static short mode = DEFAULT_MODE;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 private static string logPath;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 private static StreamWriter sw;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 private static bool fullExtract = false;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 /// <summary>
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 /// The main entry point for the application.
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 /// </summary>
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 [STAThread]
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 static void Main(string[] args)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 if (args.Length<1 || args[0]=="/?")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 ShowHelp("");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 if (args.Length>1 && args[1].ToLower() == "usage")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 Output(nl+"Click ENTER to see example usage...");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 Console.ReadLine();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 ShowUsage();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 if (!Regex.IsMatch(args[0], "[a-zA-Z0-9]+.sga$"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 ShowHelp("Archive to extract must be specified as the first parameter");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 archive = new SgaArchive(args[0]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 catch (FileNotFoundException)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 ShowHelp("The archive specified was not found");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 int i = 1;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 if (args.Length>1)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 if (!args[i].StartsWith("-"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 //full-archive extraction with a destination
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 fullExtract = true;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 dest = args[i];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 else if (args[i]=="-paths")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 fullExtract = false;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 paths = new ArrayList();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 while (i<args.Length && !args[i].StartsWith("-"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 paths.Add(args[i]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 fullExtract = true;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 fullExtract = true;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 ArrayList arrFind = new ArrayList();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 ArrayList arrReplace = new ArrayList();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 while (i<args.Length)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 if (!fullExtract && args[i]=="-d" && i<(args.Length-1) && !args[i+1].StartsWith("-"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 if (dest!="" && dest!=null)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 ShowHelp("Please only specify one destination - either a single file or a folder");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 dest = args[i];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 int lastSlash = dest.LastIndexOf('\\');
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
121 if (lastSlash<dest.LastIndexOf('.'))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
122 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
123 //it looks like a file, so make sure they've not specified multiple files
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 if (paths == null || paths.Count!=1)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 ShowHelp("Multiple files were selected but a single destination file was specified");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 else if (!fullExtract && args[i]=="-find" && i<(args.Length-3))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
135 while (i<args.Length && !args[i].StartsWith("-"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 arrFind.Add(args[i]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141 else if (!fullExtract && args[i]=="-replace" && i<(args.Length-1))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144 while (i<args.Length && !args[i].StartsWith("-"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146 arrReplace.Add(args[i]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150 else if (!fullExtract && (args[i]=="-extension" || args[i]=="-ext") && i<(args.Length-1))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
152 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153 ext = args[i];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
155 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 else if (args[i]=="-mode" && i<args.Length-1)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
157 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
160 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
161 mode = short.Parse(args[i]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
162
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
163 if (mode<1||mode>3)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
164 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165 mode = DEFAULT_MODE;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 Output("Warning: invalid mode used. Reverting to default");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169 catch
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 mode = DEFAULT_MODE;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
172 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
174 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 else if (args[i]=="-log" && i<args.Length-1)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
176 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 logPath = args[i];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
179 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
181 else if (args[i]=="--force")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
182 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
183 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
184 overwrite = true;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
185 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
186 else if (!fullExtract && args[i]=="--recursive")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
188 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
189 recursive = true;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
190 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
191 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
192 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
193 ShowHelp("Invalid parameter: "+args[i]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
194 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
195 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
197
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
198 string [] find;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
199 string [] replace;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
200
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
201 if (arrReplace.Count!=arrFind.Count)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
203 ShowHelp("Find and Replace lists must be the same length");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
204 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
205 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
206 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
207 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
208 find = new string[arrFind.Count];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
209 replace = new string [arrReplace.Count];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
210
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
211 for (int j = 0; j<arrFind.Count; j++)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
212 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
213 find[j] = (string)arrFind[j];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
215
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
216 for (int j = 0; j<arrReplace.Count; j++)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
217 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
218 replace[j] = (string)arrReplace[j];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
219 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
220 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
221
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
222 if ((mode & 1) == 1)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
223 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
224 archive.OnExtractFileFail += new SgaArchive.ExtractionNotification(OutputExtractionStatus);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
225 archive.OnExtractFolderFail += new SgaArchive.ExtractionNotification(OutputExtractionStatus);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
226 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
227
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
228 if ((mode & 2) == 2)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
229 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
230 archive.OnExtractFileSuccess += new SgaArchive.ExtractionNotification(OutputExtractionStatus);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
231 archive.OnExtractFolderSuccess += new SgaArchive.ExtractionNotification(OutputExtractionStatus);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
232 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
233
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
234 if (logPath!=null && logPath!="")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
235 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
236 sw = new StreamWriter(logPath,true);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
237 sw.AutoFlush = true;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
238 sw.WriteLine(DateTime.Now.ToString()+" - "+Environment.CommandLine.ToString()+nl);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
240
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
241 if (paths==null || paths.Count==0)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
242 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
243 //full archive extraction
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
244 if (dest==null || dest == "")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
246 //to default location
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
247 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
248 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
249 Output("Extracting full archive "+archive.Name+" to default location");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250 archive.ExtractAll(overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 Output("Extraction Complete");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
253 catch (FileNotFoundException)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
254 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
255 ShowHelp("The archive specified was not found");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
256 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
257 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
258 catch(Exception ex)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
259 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
260 Output("Extraction failed: "+ex.Message);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
261 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
262 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
263 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
264 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
265 //to specified location
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
266 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
267 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
268 Output("Extracting full archive "+archive.Name+" to "+dest);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
269 archive.ExtractAll(dest, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
270 Output("Extraction Complete");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
271 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
272 catch (FileNotFoundException)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
273 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
274 ShowHelp("The archive specified was not found");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
275 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
276 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
277 catch(Exception ex)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
278 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
279 Output("Extraction failed: "+ex.Message);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
280 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
281 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
282 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
283 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
284 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
285 string path = "";
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
286
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
287 for (int j = 0; j<paths.Count; j++)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
288 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
289 path = (string)paths[j];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
290 int lastindex = path.LastIndexOf('\\');
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
291
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
292 if (lastindex>=path.LastIndexOf('.'))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
293 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
294 //the path to extract is a folder
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
295 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
296 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
297 if (ext!=null)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
298 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
299 Output("Attempting to extract files of type '"+ext+"' from folder: "+path);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
300
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
301 if (dest==null)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
302 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
303 archive.ExtractType(ext, path, find, replace, recursive, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
304 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
305 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
306 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
307 archive.ExtractType(ext, path, dest, find, replace, recursive, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
308 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
309 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
310 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
311 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
312 Output("Attempting to extract folder: "+path);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
313
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
314 if (dest==null && find.Length==0)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
315 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
316 archive.ExtractFolder(path, recursive, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
317 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
318 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
319 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
320 archive.ExtractFolder(path, dest, find, replace, recursive, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
321 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
322 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
323
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
324 Output("Extraction complete");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
325 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
326 catch(Exception ex)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
327 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
328 Output("Extraction failed: "+ex.Message);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
329 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
330 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
331 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
332 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
333 Output("Attempting to extract file: "+path);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
334 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
335 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
336 if (dest==null)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
337 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
338 archive.Extract(path, find, replace, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
339 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
340 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
341 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
342 archive.Extract(path, dest, find, replace, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
343 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
344 Output("Extraction complete");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
345 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
346 catch(Exception ex)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
347 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
348 Output("Extraction failed: "+ex.Message);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
349 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
350 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
351 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
352 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
353 /*
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
354 if (args.Length==1 && args[0]=="/?")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
355 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
356 ShowHelp("");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
357 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
358 else if (args.Length==1 && args[0].EndsWith(".sga"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
359 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
360 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
361 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
362 archive = new SgaArchive(args[0]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
363 Output("Extracting full archive "+args[0]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
364 archive.ExtractAll();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
365 Output("Extraction Complete");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
366 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
367 catch (RelicSga.Exceptions.FileNotFoundException)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
368 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
369 ShowHelp("The archive specified was not found");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
370 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
371 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
372 catch(RelicSga.Exceptions.Exception ex)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
373 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
374 Output("Extraction failed: "+ex.Message);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
375 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
376 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
377 else if (args.Length ==2 && args[0]=="/?" && args[1]=="usage")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
378 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
379 ShowHelp("");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
380 Output(nl+"Click ENTER to see example usage...");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
381 Console.ReadLine();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
382 ShowUsage();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
383 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
384 else if (args.Length==2 && args[0].EndsWith(".sga"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
385 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
386 if (args[1]=="--force")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
387 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
388 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
389 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
390 archive = new SgaArchive(args[0]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
391 Output("Extracting full archive "+args[0]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
392 archive.ExtractAll(true);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
393 Output("Extraction Complete");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
394 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
395 catch (RelicSga.Exceptions.FileNotFoundException)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
396 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
397 ShowHelp("The archive specified was not found");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
398 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
399 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
400 catch(RelicSga.Exceptions.Exception ex)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
401 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
402 Output("Extraction failed: "+ex.Message);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
403 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
404 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
405 else if (!args[1].StartsWith("-"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
406 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
407 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
408 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
409 archive = new SgaArchive(args[0]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
410 Output("Extracting full archive "+args[0]+" to "+args[1]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
411 archive.ExtractAll(args[1]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
412 Output("Extraction Complete");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
413 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
414 catch (RelicSga.Exceptions.FileNotFoundException)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
415 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
416 ShowHelp("The archive specified was not found");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
417 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
418 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
419 catch(RelicSga.Exceptions.Exception ex)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
420 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
421 Output("Extraction failed: "+ex.Message);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
422 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
423 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
424 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
425 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
426 ShowHelp("Invalid parameter combination");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
427 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
428 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
429 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
430 else if (args.Length<3)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
431 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
432 ShowHelp("");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
433 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
434 else if (args.Length==3 && args[0].EndsWith(".sga") && !args[1].StartsWith("-") && args[2]=="--force")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
435 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
436 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
437 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
438 archive = new SgaArchive(args[0]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
439 Output("Extracting full archive "+args[0]+" to "+args[1]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
440 archive.ExtractAll(args[1], true);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
441 Output("Extraction Complete");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
442 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
443 catch (RelicSga.Exceptions.FileNotFoundException)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
444 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
445 ShowHelp("The archive specified was not found");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
446 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
447 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
448 catch(RelicSga.Exceptions.Exception ex)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
449 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
450 Output("Extraction failed: "+ex.Message);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
451 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
452 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
453 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
454 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
455 if (!Regex.IsMatch(args[0], "^[a-zA-Z0-9]+.sga$"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
456 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
457 ShowHelp("Archive to extract must be specified as the first parameter");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
458 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
459 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
460 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
461 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
462 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
463 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
464 archive = new SgaArchive(args[0]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
465 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
466 catch (RelicSga.Exceptions.FileNotFoundException)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
467 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
468 ShowHelp("The archive specified was not found");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
469 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
470 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
471 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
472
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
473 if (args[1]!="-paths")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
474 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
475 ShowHelp("Must specifie a set of paths to extract");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
476 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
477 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
478
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
479 int i = 2;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
480 paths = new ArrayList();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
481
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
482 while (i<args.Length && !args[i].StartsWith("-"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
483 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
484 paths.Add(args[i]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
485 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
486 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
487
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
488
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
489 ArrayList arrFind = new ArrayList();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
490 ArrayList arrReplace = new ArrayList();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
491
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
492 if (i != args.Length)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
493 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
494 while (i<args.Length)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
495 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
496 if (args[i]=="-d" && i<(args.Length-1) && !args[i+1].StartsWith("-"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
497 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
498 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
499
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
500 dest = args[i];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
501 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
502 int lastindex = dest.LastIndexOf('\\');
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
503
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
504 if (lastindex<=dest.LastIndexOf('.'))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
505 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
506 //it looks like a file, so make sure they've not specified multiple files
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
507 if (paths.Count!=1)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
508 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
509 ShowHelp("Multiple files were selected but a single destination file was specified");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
510 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
511 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
512 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
513 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
514 else if (args[i]=="-find" && i<(args.Length-3))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
515 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
516 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
517 while (i<args.Length && !args[i].StartsWith("-"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
518 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
519 arrFind.Add(args[i]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
520 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
521 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
522 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
523 else if (args[i]=="-replace" && i<(args.Length-1))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
524 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
525 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
526 while (i<args.Length && !args[i].StartsWith("-"))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
527 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
528 arrReplace.Add(args[i]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
529 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
530 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
531 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
532 else if ((args[i]=="-extension" || args[i]=="-ext") && i<(args.Length-1))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
533 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
534 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
535 ext = args[i];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
536 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
537 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
538 else if (args[i]=="-mode" && i<args.Length-1)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
539 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
540 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
541 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
542 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
543 mode = short.Parse(args[i]);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
544 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
545 catch
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
546 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
547 mode = DEFAULT_MODE;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
548 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
549 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
550 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
551 else if (args[i]=="-log" && i<args.Length-1)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
552 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
553 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
554 logPath = args[i];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
555 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
556 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
557 else if (args[i]=="--force")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
558 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
559 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
560 overwrite = true;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
561 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
562 else if (args[i]=="--recursive")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
563 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
564 i++;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
565 recursive = true;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
566 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
567 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
568 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
569 ShowHelp("Invalid parameter combination");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
570 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
571 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
572 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
573 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
574
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
575 string path = "";
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
576
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
577 string [] find;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
578 string [] replace;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
579
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
580 if (arrReplace.Count!=arrFind.Count)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
581 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
582 ShowHelp("Find and Replace lists must be the same length");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
583 return;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
584 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
585 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
586 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
587 find = new string[arrFind.Count];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
588 replace = new string [arrReplace.Count];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
589
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
590 for (int j = 0; j<arrFind.Count; j++)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
591 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
592 find[j] = (string)arrFind[j];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
593 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
594
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
595 for (int j = 0; j<arrReplace.Count; j++)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
596 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
597 replace[j] = (string)arrReplace[j];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
598 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
599 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
600
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
601 if ((mode & 1) == 1)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
602 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
603 archive.OnExtractFileFail += new SgaArchive.ExtractionNotification(OutputExtractionStatus);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
604 archive.OnExtractFolderFail += new SgaArchive.ExtractionNotification(OutputExtractionStatus);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
605 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
606
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
607 if ((mode & 2) == 2)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
608 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
609 archive.OnExtractFileSuccess += new SgaArchive.ExtractionNotification(OutputExtractionStatus);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
610 archive.OnExtractFolderSuccess += new SgaArchive.ExtractionNotification(OutputExtractionStatus);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
611 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
612
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
613 if (logPath!=null && logPath!="")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
614 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
615 sw = new StreamWriter(logPath,false);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
616 sw.AutoFlush = true;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
617 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
618
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
619 for (int j = 0; j<paths.Count; j++)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
620 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
621 path = (string)paths[j];
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
622 int lastindex = path.LastIndexOf('\\');
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
623
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
624 if (lastindex>path.LastIndexOf('.'))
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
625 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
626 //it's a folder
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
627 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
628 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
629 if (ext!=null)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
630 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
631 Output("Attempting to extract files of type '"+ext+"' from folder: "+path);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
632
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
633 if (dest==null)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
634 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
635 archive.ExtractType(ext, path, find, replace, recursive, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
636 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
637 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
638 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
639 archive.ExtractType(ext, path, dest, find, replace, recursive, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
640 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
641 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
642 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
643 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
644 Output("Attempting to extract folder: "+path);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
645
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
646 if (dest==null && find.Length==0)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
647 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
648 archive.ExtractFolder(path, recursive, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
649 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
650 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
651 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
652 archive.ExtractFolder(path, dest, find, replace, recursive, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
653 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
654 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
655
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
656 Output("Extraction complete");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
657 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
658 catch(RelicSga.Exceptions.Exception ex)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
659 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
660 Output("Extraction failed: "+ex.Message);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
661 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
662 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
663 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
664 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
665 Output("Attempting to extract file: "+path);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
666 try
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
667 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
668 if (dest==null)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
669 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
670 archive.Extract(path, find, replace, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
671 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
672 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
673 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
674 archive.Extract(path, dest, find, replace, overwrite);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
675 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
676 Output("Extraction complete");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
677 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
678 catch(RelicSga.Exceptions.Exception ex)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
679 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
680 Output("Extraction failed: "+ex.Message);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
681 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
682 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
683 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
684 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
685 */
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
686 if (sw!=null)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
687 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
688 sw.WriteLine("");
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
689 sw.Close();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
690 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
691 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
692
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
693 private static void ShowHelp(string error)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
694 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
695 if (error!="")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
696 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
697
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
698 error = nl+"Error: "+error+nl;
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
699
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
700 if (sw!=null)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
701 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
702 //output just the error directly to the log if we errored in some important way and we're logging to a file
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
703 sw.WriteLine(error);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
704 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
705 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
706
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
707 Output("Extracts files from an SGA archive file, with optional hex-editing"+nl+error+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
708 "SGAEXTRACTOR archive -paths path [path [...]] [-d destination]"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
709 " [ -find find[ find ...] -replace repl[ repl] ] [-ext extension] "+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
710 " [-mode level] [-log logfile] [--force] [--recursive]"+nl+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
711 "SGAEXTRACTOR archive [destination] [-mode level] [-log logfile] [--force]"+nl+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
712 " archive\tSpecifies the SGA file to extract from"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
713 " path\t\tSpecifies the file or folder path within the archive"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
714 " \t\t to extract"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
715 " destination\tLocation the files will be extracted to. Defaults to the"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
716 " \t\t location of the archive"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
717 " find\t\tThe text string that will be found to be replace"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
718 " repl\t\tThe text string that will replace the found string"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
719 " extension\tIf a folder is specified in 'path' ext specifies the extension"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
720 " \t\tof file types to extract"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
721 " level\tThe level of feedback required: 0 = minimal feedback, "+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
722 " \t\t 1 = failures, 2 = successes, 3 = both (default = 2)"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
723 " log\t\tSpecifies the path of the log file to write to"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
724 " --force\tForces an overwrite of the file or files if they exist"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
725 " --recursive\tIf a folder is specified in 'path', extracts all sub folders",
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
726 false);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
727 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
728
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
729 private static void ShowUsage()
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
730 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
731 Output("Example Usage:"+nl+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
732 " Extract all of the Dawn of War texture archive to its default location:"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
733 " SGAEXTRACTOR \"c:\\Program Files\\THQ\\Dawn of War\\W40k\\W40KData-SharedTextures-Full.sga\""+nl+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
734 " Extract all of the Dawn of War texture archive to a new location:"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
735 " SGAEXTRACTOR \"c:\\Program Files\\THQ\\Dawn of War\\W40k\\W40KData-SharedTextures-Full.sga\" -d c:\\texture_temp"+nl+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
736 " Extract all of the Dawn of War RGDs to their default location, overwriting any that already exist:"+nl+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
737 " SGAEXTRACTOR \"c:\\Program Files\\THQ\\Dawn of War\\W40k\\W40kData.sga\" -ext .rgd --force"+nl+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
738 "MORE...", false);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
739 Console.ReadLine();
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
740 Output(" Extract Chaplain texture from WXP texture archive to its default location:"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
741 " SGAEXTRACTOR \"c:\\Program Files\\THQ\\Dawn of War\\WXP\\WXPData-SharedTextures-Full.sga\" -paths data\\art\\ebps\\races\\space_marines\\texture_share\\sm_chaplain.rsh"+nl+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
742 " Extract Chaplain RSH and WTP from WXP texture archive to their default locations:"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
743 " SGAEXTRACTOR \"c:\\Program Files\\THQ\\Dawn of War\\WXP\\WXPData-SharedTextures-Full.sga\" -paths data\\art\\ebps\\races\\space_marines\\texture_share\\sm_chaplain.rsh data\\art\\ebps\\races\\space_marines\\texture_share\\sm_chaplain_default.wtp"+nl+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
744 " Extract Chaplain texture from WXP texture archive, save it to a different filename and hex-edit it for a new race:"+nl+
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
745 " SGAEXTRACTOR \"c:\\Program Files\\THQ\\Dawn of War\\WXP\\WXPData-SharedTextures-Full.sga\" -paths data\\art\\ebps\\races\\space_marines\\texture_share\\sm_chaplain.rsh -d \"c:\\program files\\thq\\dawn of war\\temp\\halved_chaplain.rsh\" -find races/space_marines -replace races/halvedmarines",
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
746 false);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
747 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
748
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
749 private static void OutputExtractionStatus(string type, string name, string message)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
750 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
751 if (message=="")
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
752 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
753 Output(String.Format("Extraction of {0} \"{1}\" succeeded", type, name));
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
754 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
755 else
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
756 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
757 Output(String.Format("Extraction of {0} \"{1}\" failed: {2}", type, name, message));
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
758 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
759 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
760
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
761 private static void Output(string str)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
762 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
763 Output(str, true);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
764 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
765
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
766 private static void Output(string str, bool log)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
767 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
768 if (sw!=null && log)
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
769 {
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
770 sw.WriteLine(str);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
771 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
772
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
773 Console.WriteLine(str);
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
774 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
775 }
85ff734c7605 Initial commit under GPLv3
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
776 }