-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProgram.cs
More file actions
114 lines (107 loc) · 4.79 KB
/
Program.cs
File metadata and controls
114 lines (107 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using DemoCleaner3.ExtClasses;
using System;
using System.IO;
using System.Windows.Forms;
using System.Text;
using System.Collections.Generic;
namespace DemoCleaner3
{
static class Program
{
/// <summary>
/// The main entry point for the app.
/// </summary>
[STAThread]
static void Main(String[] argg)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
FileInfo demoFile = null;
string argument = null;
FileInfo extraFile = null;
if (argg.Length == 1) {
demoFile = new FileInfo(argg[0]);
} else if (argg.Length == 2) {
argument = argg[0];
demoFile = new FileInfo(argg[1]);
} else if (argg.Length == 3) {
argument = argg[0];
demoFile = new FileInfo(argg[1]);
extraFile = new FileInfo(argg[2]);
}
if (demoFile != null && demoFile.Exists && demoFile.Extension.ToLowerInvariant().StartsWith(".dm_")) {
Demo demo = null;
switch (argument) {
default:
DemoInfoForm demoInfoForm = new DemoInfoForm();
demoInfoForm.demoFile = demoFile;
Application.Run(demoInfoForm);
break;
case "--xml":
try {
var infoString = getDemoInfoString(demoFile);
Console.WriteLine(infoString);
} catch (Exception ex) {
Console.WriteLine("Can not parse demo");
Console.WriteLine(ex.ToString());
}
break;
case "--xml-file":
if (extraFile == null) {
string extension = ".xml";
var name = demoFile.Name.Substring(0, demoFile.Name.Length - demoFile.Extension.Length) + extension;
var m_exePath = Path.GetDirectoryName(Application.ExecutablePath);
extraFile = new FileInfo(Path.Combine(m_exePath, name));
}
var fileStream = new FileStream(extraFile.FullName, FileMode.CreateNew);
var streamWriter = new StreamWriter(fileStream, Encoding.UTF8);
try {
var infoString = getDemoInfoString(demoFile);
streamWriter.Write(infoString);
} catch (Exception ex) {
streamWriter.Write("Can not parse demo: " + ex.Message);
}
streamWriter.Close();
fileStream.Close();
break;
case "--rec":
try {
demo = Demo.GetDemoFromFileRaw(demoFile);
} catch (Exception ex) {
Console.WriteLine("Can not parse demo");
Console.WriteLine(ex.ToString());
}
if (demo != null) {
var saver = new RecFileSaver(demo);
if (saver.canSave) {
try {
if (extraFile != null) {
saver.Save(extraFile.FullName);
} else {
saver.Save();
}
System.Diagnostics.Debug.WriteLine("rec file saved");
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
Console.WriteLine("Can not create rec file for current demo");
}
break;
}
} else {
Application.Run(new Form1());
}
}
static string getDemoInfoString(FileInfo demoFile) {
Demo demo = Demo.GetDemoFromFileRaw(demoFile);
Dictionary<string, string> name = new Dictionary<string, string>();
name.Add("originalFileName", demoFile.Name);
name.Add("suggestedFileName", demo.demoNewName);
name.Add("suggestedFileNameSimple", demo.demoNewNameSimple);
var friendlyInfo = demo.rawInfo.getFriendlyInfo();
friendlyInfo.Add("fileName", name);
return XmlUtils.FriendlyInfoToXmlString(friendlyInfo);
}
}
}