Skip to content

Commit 358dbaf

Browse files
committed
Initial commit
1 parent 3730274 commit 358dbaf

29 files changed

+1760
-0
lines changed

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Visual Studio build folders #
2+
bin/
3+
obj/
4+
5+
# MonoDevelop files
6+
*.pidb
7+
8+
# Mac files
9+
._*
10+
.DS_Store
11+
._*
12+
13+
# Installer output #
14+
Installer/Output
15+
16+
# PortableApps-related files
17+
*.paf.exe
18+
MASGAU.Portable/App/MASGAU/*
19+
MASGAU.Portable/Data/*
20+
MASGAU.Main.WPF/Data/
21+
22+
# MASGAU binaries #
23+
MASGAU.*.exe
24+
MASGAU.*.dll
25+
26+
# OS generated files #
27+
######################
28+
.DS_Store*
29+
ehthumbs.db
30+
Icon?
31+
Thumbs.db

Files/AFile.cs

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Xml;
6+
using System.IO;
7+
using XmlData;
8+
namespace GameSaveInfo {
9+
public abstract class AFile: AXmlDataEntry {
10+
public string Name { get; protected set; }
11+
public string Path { get; protected set; }
12+
public string OnlyFor { get; protected set; }
13+
public DateTime ModifiedAfter { get; protected set; }
14+
15+
protected AFile(string name, string path, XmlDocument doc): base(doc) {
16+
Name = name;
17+
Path = path;
18+
}
19+
20+
protected AFile(XmlElement element): base(element) {
21+
22+
}
23+
24+
protected override void LoadData(XmlElement element) {
25+
foreach (XmlAttribute attr in element.Attributes) {
26+
switch (attr.Name) {
27+
case "path":
28+
Path = attr.Value;
29+
break;
30+
case "filename":
31+
Name = attr.Value;
32+
break;
33+
case "modified_after":
34+
ModifiedAfter = DateTime.Parse(attr.Value);
35+
break;
36+
case "only_for":
37+
OnlyFor = attr.Value;
38+
break;
39+
default:
40+
throw new NotSupportedException(attr.Name);
41+
}
42+
}
43+
LoadMoreData(element);
44+
}
45+
protected abstract void LoadMoreData(XmlElement element);
46+
protected abstract XmlElement WriteMoreData(XmlElement element);
47+
48+
protected override XmlElement WriteData(XmlElement element) {
49+
addAtribute(element, "path", Path);
50+
addAtribute(element, "filename", Name);
51+
52+
if (ModifiedAfter != new DateTime())
53+
throw new Exception("Don't know ho to write modified after!");
54+
55+
addAtribute(element, "only_for", Path);
56+
return WriteMoreData(element);
57+
}
58+
59+
60+
public virtual List<string> FindMatching(string location) {
61+
List<DirectoryInfo> directories = new List<DirectoryInfo>();
62+
List<string> return_me = new List<string>();
63+
64+
if (Name == null) {
65+
if (Path == null) {
66+
if (Directory.Exists(location)) {
67+
return_me.AddRange(findTheseFilesHelper(location, gatherFiles(location)));
68+
}
69+
} else {
70+
directories.AddRange(getPaths(location, Path));
71+
foreach (DirectoryInfo directory in directories) {
72+
return_me.AddRange(findTheseFilesHelper(location, gatherFiles(directory.FullName)));
73+
}
74+
}
75+
} else if (Path == null) {
76+
if (Directory.Exists(location)) {
77+
List<string> files = new List<string>();
78+
foreach (FileInfo read_me in new DirectoryInfo(location).GetFiles(Name)) {
79+
files.Add(read_me.FullName);
80+
}
81+
return_me.AddRange(findTheseFilesHelper(location, files));
82+
}
83+
} else {
84+
directories.AddRange(getPaths(location, Path));
85+
foreach (DirectoryInfo directory in directories) {
86+
List<string> files = new List<string>();
87+
foreach (FileInfo read_me in directory.GetFiles(Name)) {
88+
files.Add(read_me.FullName);
89+
}
90+
return_me.AddRange(findTheseFilesHelper(location, files));
91+
}
92+
}
93+
return return_me;
94+
}
95+
96+
private List<string> findTheseFilesHelper(string location, List<string> files) {
97+
List<string> return_me = new List<string>();
98+
foreach (string file_name in files) {
99+
FileInfo file = new FileInfo(file_name);
100+
if (!file.Exists)
101+
continue;
102+
103+
if (file.LastWriteTime <= ModifiedAfter)
104+
continue;
105+
106+
string add_me = file.FullName;
107+
108+
109+
if (file.DirectoryName.Length != add_me.Length)
110+
add_me = add_me.Substring(location.Trim(System.IO.Path.DirectorySeparatorChar).Length + 1);
111+
else
112+
throw new Exception("what?");
113+
114+
return_me.Add(add_me);
115+
}
116+
return return_me;
117+
}
118+
119+
120+
private static List<string> gatherFiles(string root) {
121+
List<string> return_me = new List<string>();
122+
try {
123+
foreach (FileInfo file in new DirectoryInfo(root).GetFiles()) {
124+
return_me.Add(file.FullName);
125+
}
126+
foreach (DirectoryInfo sub_folder in new DirectoryInfo(root).GetDirectories()) {
127+
return_me.AddRange(gatherFiles(sub_folder.FullName));
128+
}
129+
} catch (Exception e) {
130+
throw e;
131+
}
132+
return return_me;
133+
}
134+
135+
136+
private static List<DirectoryInfo> getPaths(string root, string path) {
137+
List<DirectoryInfo> return_me = new List<DirectoryInfo>();
138+
DirectoryInfo root_directory = new DirectoryInfo(root);
139+
140+
string[] split = path.Split(System.IO.Path.DirectorySeparatorChar);
141+
string forward_me = "";
142+
143+
for (int i = 1; i < split.Length; i++) {
144+
forward_me = System.IO.Path.Combine(forward_me, split[i]);
145+
}
146+
try {
147+
DirectoryInfo[] directories = root_directory.GetDirectories(split[0]);
148+
if (split.Length == 1) {
149+
foreach (DirectoryInfo add_me in directories) {
150+
return_me.Add(add_me);
151+
}
152+
} else {
153+
foreach (DirectoryInfo add_me in directories) {
154+
return_me.AddRange(getPaths(add_me.FullName, forward_me));
155+
}
156+
}
157+
} catch (Exception e) {
158+
throw e;
159+
}
160+
return return_me;
161+
}
162+
163+
164+
165+
}
166+
}

Files/ExceptFile.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Xml;
6+
namespace GameSaveInfo {
7+
public class ExceptFile: AFile {
8+
public string Type { get; protected set; }
9+
10+
public override string ElementName {
11+
get { return "except"; }
12+
}
13+
14+
public ExceptFile(string name, string path, string type, XmlDocument doc): base(name,path, doc) {
15+
this.Type = type;
16+
}
17+
18+
public ExceptFile(XmlElement element, string type)
19+
: base(element) {
20+
this.Type = type;
21+
}
22+
23+
protected override void LoadMoreData(XmlElement element) {
24+
25+
}
26+
27+
protected override XmlElement WriteMoreData(XmlElement element) {
28+
return element;
29+
}
30+
}
31+
}

Files/FileType.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Xml;
6+
using XmlData;
7+
namespace GameSaveInfo {
8+
public class FileType: AXmlDataEntry {
9+
public List<SaveFile> Saves = new List<SaveFile>();
10+
public string Type { get; protected set; }
11+
12+
public override string ElementName {
13+
get { return "files"; }
14+
}
15+
16+
17+
public FileType(string name, XmlDocument doc): base(doc) {
18+
this.Type = name;
19+
}
20+
21+
public FileType(XmlElement element): base(element) {
22+
}
23+
24+
protected override void LoadData(XmlElement element) {
25+
foreach (XmlAttribute attr in element.Attributes) {
26+
switch (attr.Name) {
27+
case "type":
28+
this.Type = attr.Value;
29+
break;
30+
default:
31+
throw new NotSupportedException(attr.Name);
32+
}
33+
}
34+
foreach (XmlElement child in element.ChildNodes) {
35+
switch (child.Name) {
36+
case "save":
37+
SaveFile save = new SaveFile(child, Type);
38+
Saves.Add(save);
39+
break;
40+
default:
41+
throw new NotSupportedException(child.Name);
42+
}
43+
}
44+
}
45+
46+
47+
protected override XmlElement WriteData(XmlElement element) {
48+
addAtribute(element, "type", this.Type);
49+
foreach (SaveFile save in Saves) {
50+
element.AppendChild(save.XML);
51+
}
52+
return element;
53+
}
54+
55+
public void Add(SaveFile file) {
56+
this.Saves.Add(file);
57+
this.XML.AppendChild(file.XML);
58+
}
59+
60+
public virtual List<string> FindMatching(string location) {
61+
List<string> files = new List<string>();
62+
foreach (SaveFile save in Saves) {
63+
files.AddRange(save.FindMatching(location));
64+
}
65+
return files;
66+
}
67+
68+
69+
70+
}
71+
}

Files/Identifier.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Xml;
6+
namespace GameSaveInfo {
7+
public class Identifier: AFile {
8+
public Identifier(XmlElement element) : base(element) { }
9+
10+
public override string ElementName {
11+
get { return "identifier"; }
12+
}
13+
14+
protected override void LoadMoreData(XmlElement element) {
15+
16+
}
17+
18+
protected override XmlElement WriteMoreData(XmlElement element) {
19+
return element;
20+
}
21+
}
22+
}

Files/SaveFile.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Xml;
6+
namespace GameSaveInfo {
7+
public class SaveFile: ExceptFile {
8+
public List<ExceptFile> Excepts = new List<ExceptFile>();
9+
10+
public SaveFile(string name, string path, string type, XmlDocument doc)
11+
: base(name, path, type, doc) {
12+
}
13+
14+
public SaveFile(XmlElement element, string type)
15+
: base(element, type) {
16+
}
17+
18+
protected override void LoadMoreData(XmlElement element) {
19+
foreach (XmlElement child in element.ChildNodes) {
20+
switch (child.Name) {
21+
case "except":
22+
ExceptFile except = new ExceptFile(child, Type);
23+
Excepts.Add(except);
24+
break;
25+
default:
26+
throw new NotSupportedException(child.Name);
27+
}
28+
}
29+
}
30+
31+
protected override XmlElement WriteMoreData(XmlElement element) {
32+
foreach (ExceptFile ex in Excepts) {
33+
element.AppendChild(ex.XML);
34+
}
35+
return element;
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)