Skip to content

Commit

Permalink
config pack version checking, editor/engine verchk
Browse files Browse the repository at this point in the history
  • Loading branch information
suicvne committed Aug 10, 2015
1 parent c3f4f8e commit 218603c
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 11 deletions.
296 changes: 289 additions & 7 deletions Manager.mono/PGE-Manager/MainWindow.cs
Expand Up @@ -10,6 +10,8 @@
using System.Diagnostics;
using System.Text.RegularExpressions;
using STA.Settings;
using System.Threading;
using System.Linq;

public partial class MainWindow: Gtk.Window
{
Expand All @@ -32,8 +34,27 @@ public MainWindow () : base (Gtk.WindowType.Toplevel)
RunningPortable = DetectRunningPortable();
this.Title = "PGE Manager - Portable: " + RunningPortable;
DoPGEVersioning();

Thread t = new System.Threading.Thread(CheckUpdatesCombined);
t.Start();
}

private void CheckUpdatesCombined()
{
bool EditorUpdateAvail, EngineUpdateAvail;
EditorUpdateAvail = CheckForEditorUpdates();
EngineUpdateAvail = CheckForEngineUpdates();

string message = "The following components have updates:\n";
message += (EditorUpdateAvail) ? "-Editor\n" : "";
message += (EngineUpdateAvail) ? "-Engine\n" : "";
message += "\nPlease update them!";
MessageDialog md = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, message);
if (EditorUpdateAvail | EngineUpdateAvail)
md.Run();
md.Destroy();
}

private bool DetectRunningPortable()
{
PGEEditorPath = Environment.CurrentDirectory + System.IO.Path.DirectorySeparatorChar;
Expand Down Expand Up @@ -85,6 +106,12 @@ private void DoPGEVersioning()
launcheditorwidget1.SetEngineVersion(EngineVersion);
}

private Version GetVersionFromWohlString(string text)
{
Regex pattern = new Regex("\\d+(\\.\\d+)+");
Match m = pattern.Match(text);
return new Version(m.Value);
}

private Version ExtractVersionFromWohlString(string pathToExe)
{
Expand Down Expand Up @@ -118,7 +145,6 @@ private void GetLatestNews()

Console.WriteLine("News is okay!");
}

}

private void InitializeNewsTreeView()
Expand All @@ -140,25 +166,136 @@ private void InitializeNewsTreeView()
}
}

private bool CheckForEditorUpdates()
{
try
{
using(WebClient wc = new WebClient())
{
string versTextFile = wc.DownloadString("http://download.gna.org/pgewohlstand/dev/win32/online-install/editor.txt");
if(versTextFile == null || versTextFile.Trim() == "")
return false;
Version LatestVersion = GetVersionFromWohlString(versTextFile);
if(LatestVersion > EditorVersion)
return true;
}
}
catch(Exception ex)
{
Console.WriteLine("ERROR: {0}", ex.Message);
}
return false;
}

private bool CheckForEngineUpdates()
{
try
{
using(WebClient wc = new WebClient())
{
string versTextFile = wc.DownloadString("http://download.gna.org/pgewohlstand/dev/win32/online-install/engine.txt");
if(versTextFile == null || versTextFile.Trim() == "")
return false;
Version LatestVersion = GetVersionFromWohlString(versTextFile);
if(LatestVersion > EngineVersion)
return true;
}
}
catch(Exception ex)
{
Console.WriteLine("ERROR: {0}", ex.Message);
}
return false;
}

private void InitializeConfigTreeView()
{
Gtk.ListStore configPackModel = new ListStore(typeof(string), typeof(string), typeof(bool));
List<ConfigPack> PacksThatNeedUpdating = new List<ConfigPack>();
Gtk.ListStore configPackModel = new ListStore(typeof(string), typeof(string), typeof(string));
configListTreeview.AppendColumn("Pack Name", new CellRendererText(), "text", 0);
configListTreeview.AppendColumn("Upload Date", new CellRendererText(), "text", 1);
configListTreeview.AppendColumn("Installed", new CellRendererText(), "text", 2);
foreach (var cfg in ConfigList)
{
bool exists = false;
string pathToCheck = Program.ProgramSettings.PGEDirectory + System.IO.Path.DirectorySeparatorChar + cfg.URL.Trim('/');
if(Directory.Exists(pathToCheck))
string pathToCheck = Program.ProgramSettings.PGEDirectory + System.IO.Path.DirectorySeparatorChar + "configs" + System.IO.Path.DirectorySeparatorChar + cfg.URL.Trim('/');
long cfgPackVersion = 0;
if (cfg.URL.ToLower() == "smbx13/")
{
if (Directory.Exists(Program.ProgramSettings.PGEDirectory + System.IO.Path.DirectorySeparatorChar + "configs" + System.IO.Path.DirectorySeparatorChar + "SMBX"))
exists = true;
cfgPackVersion = GetPackVersion(cfg);
}
else if (cfg.URL == "SMBX_Redrawn/")
{
if (Directory.Exists(Program.ProgramSettings.PGEDirectory + System.IO.Path.DirectorySeparatorChar + "configs" + System.IO.Path.DirectorySeparatorChar + "SMBX_Redrawn"))
exists = true;
cfgPackVersion = GetPackVersion(cfg);
}
else if (cfg.URL == "A2MBXT/")
{
if (Directory.Exists(Program.ProgramSettings.PGEDirectory + System.IO.Path.DirectorySeparatorChar + "configs" + System.IO.Path.DirectorySeparatorChar + "Raocow (A2MBXT)"))
exists = true;
cfgPackVersion = GetPackVersion(cfg);
}
else if(Directory.Exists(pathToCheck))
{
exists = true;
cfgPackVersion = GetPackVersion(cfg);
}
configPackModel.AppendValues(
cfg.FriendlyName,
ConfigPack.UnixTimeStampToDateTime((double)cfg.upd).ToString(), exists);
if(exists)
if (cfg.upd > cfgPackVersion)
PacksThatNeedUpdating.Add(cfg);
if(exists)
configPackModel.AppendValues(
cfg.FriendlyName,
ConfigPack.UnixTimeStampToDateTime((double)cfg.upd).ToString(), exists + " (" + ConfigPack.UnixTimeStampToDateTime((double)cfgPackVersion) + ")");
else
configPackModel.AppendValues(
cfg.FriendlyName,
ConfigPack.UnixTimeStampToDateTime((double)cfg.upd).ToString(), exists.ToString());
}
configListTreeview.Model = configPackModel;
if (PacksThatNeedUpdating.Count > 0)
NotifyUserOfUpdates(PacksThatNeedUpdating);
}

private void NotifyUserOfUpdates(List<ConfigPack> list)
{
string message = "The following config packs are out of date:\n";
foreach (var cfg in list)
message += string.Format("-{0}\n", cfg.FriendlyName);
message += "\nPlease update them!";
MessageDialog md = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, message);
md.Run();
md.Destroy();
}

private void UpdateConfigPacks(List<ConfigPack> list)
{
string tempDir = Program.ProgramSettings.ConfigDirectory + System.IO.Path.DirectorySeparatorChar + "PGE Manager" + System.IO.Path.DirectorySeparatorChar + "temp";
if (!Directory.Exists(tempDir))
Directory.CreateDirectory(tempDir);

foreach (var configPack in list)
{
ConfigPackInformation cpi = ReadPackInformation(configPack);
//TODO: download pack
//TODO: extract pack
//TODO: write current pack verison to settings
//TODO: coffee
}

}

private long GetPackVersion(ConfigPack cfg)
{
foreach (var installed in Program.ProgramSettings.InstalledConfigs)
{
if (cfg.URL.Trim('/') == installed.Key)
return installed.Value;
}
return 0L;
}

protected void OnDeleteEvent (object sender, DeleteEventArgs a)
Expand Down Expand Up @@ -216,11 +353,156 @@ private void ReadConfigsIndex()

}
}

#region Hackjob: The Game
private static ConfigPackInformation ReadPackInformation(ConfigPack selected)
{
WebClient wc = new WebClient();
string fullXmlText = wc.DownloadString(Program.ProgramSettings.ConfigsRepoURL + selected.URL + "pge_cpack.xml");
XmlDocument doc = new XmlDocument();
doc.LoadXml(fullXmlText);

ConfigPackInformation cpi = new ConfigPackInformation();


foreach (XmlNode node in doc.DocumentElement.ChildNodes)
{
if(cpi.PackName == null)
cpi.PackName = node.ParentNode.Attributes["name"].Value;
switch (node.Name)
{
case("head"):
cpi = IterateThroughHead(node, cpi);
break;
case("files"):
if (node.HasChildNodes)
{
foreach (XmlNode fileNode in node.ChildNodes)
{
if (fileNode.Name == "file")
{
FilesStruct temp = new FilesStruct();
//temp.Platform = (fileNode.Attributes["platform"].Value);
temp.Folder = (fileNode.Attributes["folder"].Value == null) ? "" : fileNode.Attributes["folder"].Value;
temp.URL = fileNode.InnerText;

if (temp.URL != null && temp.Folder != null)
cpi.FilesParts.Add(temp);
}
}
}
break;
}
}
if (cpi.SplashURL != null && cpi.SplashURL != "")
cpi.SplashURL = Program.ProgramSettings.ConfigsRepoURL + selected.URL + cpi.SplashURL;
if (cpi.IconURL != null && cpi.IconURL != "")
cpi.IconURL = Program.ProgramSettings.ConfigsRepoURL + selected.URL + cpi.IconURL;
return cpi;
}

private static ConfigPackInformation IterateThroughHead(XmlNode node, ConfigPackInformation cpi)
{
if (node.HasChildNodes)
{
foreach (XmlNode child in node.ChildNodes)
{
switch (child.Name)
{
case("config"):
cpi.PackName = child.Attributes["name"].Value;
break;
case ("description"):
cpi.Description = child.InnerText;
break;
case("icon"):
cpi.IconURL = child.Attributes["img"].Value;
break;
case("splash"):
cpi.SplashURL = child.Attributes["img"].Value;;
break;
case("smbx64"):
if (child.Attributes["true"] != null)
cpi.IsSMBX64 = (child.Attributes["true"].Value == "1") ? true : false;
break;
case("license"):
cpi.License = child.InnerText;
break;
case("credits"):
if (child.HasChildNodes)
{
foreach (XmlNode partNode in child.ChildNodes)
{
if (partNode.Name == "part")
{
string key = "";
List<AuthorStruct> values = new List<AuthorStruct>();

//XmlNode partNode = node.ChildNodes;
key = (partNode.Attributes["name"].Value == null) ? "" : partNode.Attributes["name"].Value;
if (partNode.HasChildNodes)
{
foreach (XmlNode childAuthor in partNode.ChildNodes)
{
if (childAuthor.Name == "author")
{
AuthorStruct temp = new AuthorStruct();
temp.Author = childAuthor.InnerText;
temp.Comment = (childAuthor.Attributes["comment"] == null) ? "" : childAuthor.Attributes["comment"].Value;
temp.Website = (childAuthor.Attributes["url"] == null) ? "" : childAuthor.Attributes["url"].Value;
temp.Email = (childAuthor.Attributes["email"] == null) ? "" : childAuthor.Attributes["email"].Value;
values.Add(temp);
}
}
}
if (values.Count > 0 && key != "")
{
KeyValuePair<string, AuthorStruct[]> k = new KeyValuePair<string, AuthorStruct[]>(key, values.ToArray());
cpi.CreditsParts.Add(k);
}
}
}
}
break;
}
}
}
return cpi;
}
#endregion



protected void OnExitActionActivated (object sender, EventArgs e)
{
Program.SaveSettings();
Application.Quit ();

Environment.Exit(0);
}

[GLib.ConnectBeforeAttribute]
protected void OnConfigListTreeviewButtonPressEvent (object o, ButtonPressEventArgs args)
{
if (args.Event.Button == 3)
{
Menu m = new Menu();
MenuItem ViewInfo = new MenuItem("View Config Pack Information");
ViewInfo.ButtonPressEvent += (sender, argss) =>
{
TreeSelection selection = (o as TreeView).Selection;
TreeModel model;
TreeIter iter;
if(selection.GetSelected(out model, out iter))
{
var match = ConfigList.FirstOrDefault(x => x.FriendlyName.Equals(model.GetValue(iter, 0).ToString()));
ViewPackInfoWindow vpi = new ViewPackInfoWindow(ReadPackInformation(match));
vpi.Show();
}
};
m.Add(ViewInfo);
m.ShowAll();
m.Popup();
}
}
}
7 changes: 5 additions & 2 deletions Manager.mono/PGE-Manager/PGE-Manager.csproj
Expand Up @@ -43,8 +43,9 @@
<Reference Include="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="Ionic.Zip">
<HintPath>..\packages\DotNetZip.1.9.6\lib\net20\Ionic.Zip.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="gtk-gui\gui.stetic">
Expand All @@ -68,6 +69,8 @@
<Compile Include="Internal\WohlNews.cs" />
<Compile Include="PrettySetupWindow.cs" />
<Compile Include="gtk-gui\PGEManager.PrettySetupWindow.cs" />
<Compile Include="ViewPackInfoWindow.cs" />
<Compile Include="gtk-gui\PGEManager.ViewPackInfoWindow.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Manager.mono/PGE-Manager/Settings.cs
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;

namespace PGEManager
{
Expand All @@ -19,6 +20,7 @@ public class Settings
public string ConfigDirectory {get;set;}
public string ConfigsRepoURL { get; set; }
public string ConfigsIndexURL {get{return ConfigsRepoURL + "configs.index";}}
public List<KeyValuePair<string, long>> InstalledConfigs = new List<KeyValuePair<string, long>>();

public bool ForcePortable {get;set;}

Expand Down

0 comments on commit 218603c

Please sign in to comment.