-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3730274
commit 358dbaf
Showing
29 changed files
with
1,760 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Visual Studio build folders # | ||
bin/ | ||
obj/ | ||
|
||
# MonoDevelop files | ||
*.pidb | ||
|
||
# Mac files | ||
._* | ||
.DS_Store | ||
._* | ||
|
||
# Installer output # | ||
Installer/Output | ||
|
||
# PortableApps-related files | ||
*.paf.exe | ||
MASGAU.Portable/App/MASGAU/* | ||
MASGAU.Portable/Data/* | ||
MASGAU.Main.WPF/Data/ | ||
|
||
# MASGAU binaries # | ||
MASGAU.*.exe | ||
MASGAU.*.dll | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store* | ||
ehthumbs.db | ||
Icon? | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml; | ||
using System.IO; | ||
using XmlData; | ||
namespace GameSaveInfo { | ||
public abstract class AFile: AXmlDataEntry { | ||
public string Name { get; protected set; } | ||
public string Path { get; protected set; } | ||
public string OnlyFor { get; protected set; } | ||
public DateTime ModifiedAfter { get; protected set; } | ||
|
||
protected AFile(string name, string path, XmlDocument doc): base(doc) { | ||
Name = name; | ||
Path = path; | ||
} | ||
|
||
protected AFile(XmlElement element): base(element) { | ||
|
||
} | ||
|
||
protected override void LoadData(XmlElement element) { | ||
foreach (XmlAttribute attr in element.Attributes) { | ||
switch (attr.Name) { | ||
case "path": | ||
Path = attr.Value; | ||
break; | ||
case "filename": | ||
Name = attr.Value; | ||
break; | ||
case "modified_after": | ||
ModifiedAfter = DateTime.Parse(attr.Value); | ||
break; | ||
case "only_for": | ||
OnlyFor = attr.Value; | ||
break; | ||
default: | ||
throw new NotSupportedException(attr.Name); | ||
} | ||
} | ||
LoadMoreData(element); | ||
} | ||
protected abstract void LoadMoreData(XmlElement element); | ||
protected abstract XmlElement WriteMoreData(XmlElement element); | ||
|
||
protected override XmlElement WriteData(XmlElement element) { | ||
addAtribute(element, "path", Path); | ||
addAtribute(element, "filename", Name); | ||
|
||
if (ModifiedAfter != new DateTime()) | ||
throw new Exception("Don't know ho to write modified after!"); | ||
|
||
addAtribute(element, "only_for", Path); | ||
return WriteMoreData(element); | ||
} | ||
|
||
|
||
public virtual List<string> FindMatching(string location) { | ||
List<DirectoryInfo> directories = new List<DirectoryInfo>(); | ||
List<string> return_me = new List<string>(); | ||
|
||
if (Name == null) { | ||
if (Path == null) { | ||
if (Directory.Exists(location)) { | ||
return_me.AddRange(findTheseFilesHelper(location, gatherFiles(location))); | ||
} | ||
} else { | ||
directories.AddRange(getPaths(location, Path)); | ||
foreach (DirectoryInfo directory in directories) { | ||
return_me.AddRange(findTheseFilesHelper(location, gatherFiles(directory.FullName))); | ||
} | ||
} | ||
} else if (Path == null) { | ||
if (Directory.Exists(location)) { | ||
List<string> files = new List<string>(); | ||
foreach (FileInfo read_me in new DirectoryInfo(location).GetFiles(Name)) { | ||
files.Add(read_me.FullName); | ||
} | ||
return_me.AddRange(findTheseFilesHelper(location, files)); | ||
} | ||
} else { | ||
directories.AddRange(getPaths(location, Path)); | ||
foreach (DirectoryInfo directory in directories) { | ||
List<string> files = new List<string>(); | ||
foreach (FileInfo read_me in directory.GetFiles(Name)) { | ||
files.Add(read_me.FullName); | ||
} | ||
return_me.AddRange(findTheseFilesHelper(location, files)); | ||
} | ||
} | ||
return return_me; | ||
} | ||
|
||
private List<string> findTheseFilesHelper(string location, List<string> files) { | ||
List<string> return_me = new List<string>(); | ||
foreach (string file_name in files) { | ||
FileInfo file = new FileInfo(file_name); | ||
if (!file.Exists) | ||
continue; | ||
|
||
if (file.LastWriteTime <= ModifiedAfter) | ||
continue; | ||
|
||
string add_me = file.FullName; | ||
|
||
|
||
if (file.DirectoryName.Length != add_me.Length) | ||
add_me = add_me.Substring(location.Trim(System.IO.Path.DirectorySeparatorChar).Length + 1); | ||
else | ||
throw new Exception("what?"); | ||
|
||
return_me.Add(add_me); | ||
} | ||
return return_me; | ||
} | ||
|
||
|
||
private static List<string> gatherFiles(string root) { | ||
List<string> return_me = new List<string>(); | ||
try { | ||
foreach (FileInfo file in new DirectoryInfo(root).GetFiles()) { | ||
return_me.Add(file.FullName); | ||
} | ||
foreach (DirectoryInfo sub_folder in new DirectoryInfo(root).GetDirectories()) { | ||
return_me.AddRange(gatherFiles(sub_folder.FullName)); | ||
} | ||
} catch (Exception e) { | ||
throw e; | ||
} | ||
return return_me; | ||
} | ||
|
||
|
||
private static List<DirectoryInfo> getPaths(string root, string path) { | ||
List<DirectoryInfo> return_me = new List<DirectoryInfo>(); | ||
DirectoryInfo root_directory = new DirectoryInfo(root); | ||
|
||
string[] split = path.Split(System.IO.Path.DirectorySeparatorChar); | ||
string forward_me = ""; | ||
|
||
for (int i = 1; i < split.Length; i++) { | ||
forward_me = System.IO.Path.Combine(forward_me, split[i]); | ||
} | ||
try { | ||
DirectoryInfo[] directories = root_directory.GetDirectories(split[0]); | ||
if (split.Length == 1) { | ||
foreach (DirectoryInfo add_me in directories) { | ||
return_me.Add(add_me); | ||
} | ||
} else { | ||
foreach (DirectoryInfo add_me in directories) { | ||
return_me.AddRange(getPaths(add_me.FullName, forward_me)); | ||
} | ||
} | ||
} catch (Exception e) { | ||
throw e; | ||
} | ||
return return_me; | ||
} | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml; | ||
namespace GameSaveInfo { | ||
public class ExceptFile: AFile { | ||
public string Type { get; protected set; } | ||
|
||
public override string ElementName { | ||
get { return "except"; } | ||
} | ||
|
||
public ExceptFile(string name, string path, string type, XmlDocument doc): base(name,path, doc) { | ||
this.Type = type; | ||
} | ||
|
||
public ExceptFile(XmlElement element, string type) | ||
: base(element) { | ||
this.Type = type; | ||
} | ||
|
||
protected override void LoadMoreData(XmlElement element) { | ||
|
||
} | ||
|
||
protected override XmlElement WriteMoreData(XmlElement element) { | ||
return element; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml; | ||
using XmlData; | ||
namespace GameSaveInfo { | ||
public class FileType: AXmlDataEntry { | ||
public List<SaveFile> Saves = new List<SaveFile>(); | ||
public string Type { get; protected set; } | ||
|
||
public override string ElementName { | ||
get { return "files"; } | ||
} | ||
|
||
|
||
public FileType(string name, XmlDocument doc): base(doc) { | ||
this.Type = name; | ||
} | ||
|
||
public FileType(XmlElement element): base(element) { | ||
} | ||
|
||
protected override void LoadData(XmlElement element) { | ||
foreach (XmlAttribute attr in element.Attributes) { | ||
switch (attr.Name) { | ||
case "type": | ||
this.Type = attr.Value; | ||
break; | ||
default: | ||
throw new NotSupportedException(attr.Name); | ||
} | ||
} | ||
foreach (XmlElement child in element.ChildNodes) { | ||
switch (child.Name) { | ||
case "save": | ||
SaveFile save = new SaveFile(child, Type); | ||
Saves.Add(save); | ||
break; | ||
default: | ||
throw new NotSupportedException(child.Name); | ||
} | ||
} | ||
} | ||
|
||
|
||
protected override XmlElement WriteData(XmlElement element) { | ||
addAtribute(element, "type", this.Type); | ||
foreach (SaveFile save in Saves) { | ||
element.AppendChild(save.XML); | ||
} | ||
return element; | ||
} | ||
|
||
public void Add(SaveFile file) { | ||
this.Saves.Add(file); | ||
this.XML.AppendChild(file.XML); | ||
} | ||
|
||
public virtual List<string> FindMatching(string location) { | ||
List<string> files = new List<string>(); | ||
foreach (SaveFile save in Saves) { | ||
files.AddRange(save.FindMatching(location)); | ||
} | ||
return files; | ||
} | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml; | ||
namespace GameSaveInfo { | ||
public class Identifier: AFile { | ||
public Identifier(XmlElement element) : base(element) { } | ||
|
||
public override string ElementName { | ||
get { return "identifier"; } | ||
} | ||
|
||
protected override void LoadMoreData(XmlElement element) { | ||
|
||
} | ||
|
||
protected override XmlElement WriteMoreData(XmlElement element) { | ||
return element; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml; | ||
namespace GameSaveInfo { | ||
public class SaveFile: ExceptFile { | ||
public List<ExceptFile> Excepts = new List<ExceptFile>(); | ||
|
||
public SaveFile(string name, string path, string type, XmlDocument doc) | ||
: base(name, path, type, doc) { | ||
} | ||
|
||
public SaveFile(XmlElement element, string type) | ||
: base(element, type) { | ||
} | ||
|
||
protected override void LoadMoreData(XmlElement element) { | ||
foreach (XmlElement child in element.ChildNodes) { | ||
switch (child.Name) { | ||
case "except": | ||
ExceptFile except = new ExceptFile(child, Type); | ||
Excepts.Add(except); | ||
break; | ||
default: | ||
throw new NotSupportedException(child.Name); | ||
} | ||
} | ||
} | ||
|
||
protected override XmlElement WriteMoreData(XmlElement element) { | ||
foreach (ExceptFile ex in Excepts) { | ||
element.AppendChild(ex.XML); | ||
} | ||
return element; | ||
} | ||
} | ||
} |
Oops, something went wrong.