Removed settings file

Save Icons to info.xml
Fixed Bug
This commit is contained in:
CreepyCrafter24 2019-10-21 14:39:33 +02:00
parent 25153e6998
commit 4e654eebf6
7 changed files with 97 additions and 116 deletions

View File

@ -12,4 +12,5 @@
- __APPFILES - __APPFILES
- info.xml - info.xml
- Version - Version
- Repo - Repos
- Local Repo

View File

@ -1,6 +1,6 @@
More Icons for Apps More Icons for Apps
More apps: Laptop Sim (when done) More apps: Laptop Sim (when done)
Use local info when building GUI (Except name/description)
Decent app Installer (Do not open CMD) Decent app Installer (Do not open CMD)
Save Images on disk to allow offline usage Save Images on disk to allow offline usage
Test Updates Test Updates
Remove Settings.settings (move to main XML)

View File

@ -11,6 +11,8 @@ using System.IO.Compression;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Linq; using System.Linq;
using Microsoft.VisualBasic; using Microsoft.VisualBasic;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace UpTool2 namespace UpTool2
{ {
@ -194,25 +196,22 @@ namespace UpTool2
{ {
apps.Clear(); apps.Clear();
string xml = dir + @"\info.xml"; string xml = dir + @"\info.xml";
using (WebClient client = new WebClient()) XDocument.Load(xml).Element("meta").Element("LocalRepo").Elements().ToList().ForEach(app =>
{ {
XDocument.Load(xml).Element("meta").Element("Repo").Elements().ToList().ForEach(app => apps.Add(Guid.Parse(app.Element("ID").Value), new App(
{ app.Element("Name").Value,
apps.Add(Guid.Parse(app.Element("ID").Value), new App( app.Element("Description").Value,
app.Element("Name").Value, int.Parse(app.Element("Version").Value),
app.Element("Description").Value, app.Element("File").Value,
int.Parse(app.Element("Version").Value), false,
app.Element("File").Value, app.Element("Hash").Value,
false, Guid.Parse(app.Element("ID").Value),
app.Element("Hash").Value, ColorTranslator.FromHtml(app.Element("Color").Value),
Guid.Parse(app.Element("ID").Value), app.Element("Icon") == null ? Resources.C_64.ToBitmap() : (Bitmap)new ImageConverter().ConvertFrom(Convert.FromBase64String(app.Element("Icon").Value)),
ColorTranslator.FromHtml(app.Element("Color").Value), app.Element("MainFile") != null,
app.Element("Icon") == null ? Resources.C_64.ToBitmap() : Image.FromStream(client.OpenRead(app.Element("Icon").Value)), app.Element("MainFile") != null ? "" : app.Element("MainFile").Value
app.Element("MainFile") != null, ));
app.Element("MainFile") != null ? "" : app.Element("MainFile").Value });
));
});
}
Directory.GetDirectories(dir + @"\Apps\").Where(s => !apps.ContainsKey(Guid.Parse(Path.GetFileName(s)))).ToList().ForEach(s => Directory.GetDirectories(dir + @"\Apps\").Where(s => !apps.ContainsKey(Guid.Parse(Path.GetFileName(s)))).ToList().ForEach(s =>
{ {
Guid tmp = Guid.Parse(Path.GetFileName(s)); Guid tmp = Guid.Parse(Path.GetFileName(s));
@ -223,57 +222,100 @@ namespace UpTool2
void fetchRepos() void fetchRepos()
{ {
List<XElement> apps = new List<XElement>(); string xml = dir + @"\info.xml";
XElement meta = XDocument.Load(xml).Element("meta");
List<XElement> tmp_apps_list = new List<XElement>();
if (meta.Element("Repos") == null)
meta.Add(new XElement("Repos"));
if (meta.Element("Repos").Elements("Repo").Count() == 0)
meta.Element("Repos").Add(new XElement("Repo", "https://github.com/CreepyCrafter24/UpTool2/releases/download/Repo/Repo.xml"));
string[] repArr = meta.Element("Repos").Elements("Repo").Select(s => s.Value).ToArray();
using (WebClient client = new WebClient()) using (WebClient client = new WebClient())
{ {
for (int i = 0; i < Settings.Default.Repos.Count; i++) for (int i = 0; i < repArr.Length; i++)
{ {
#if !DEBUG #if !DEBUG
try try
{ {
#endif #endif
XDocument repo = XDocument.Load(Settings.Default.Repos[i]); XDocument repo = XDocument.Load(repArr[i]);
foreach (XElement app in repo.Element("repo").Elements("app")) foreach (XElement app in repo.Element("repo").Elements("app"))
{ {
//"Sanity check" if (tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value).Count() == 0 ||
int.Parse(app.Element("Version").Value); tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value)
Guid.Parse(app.Element("ID").Value); .Where(a => int.Parse(a.Element("Version").Value) >= int.Parse(app.Element("Version").Value)).Count() == 0)
ColorTranslator.FromHtml(app.Element("Color").Value); {
//Create XElement //"Sanity check"
apps.Add(new XElement("App", int.Parse(app.Element("Version").Value);
new XElement("Name", app.Element("Name").Value), Guid.Parse(app.Element("ID").Value);
new XElement("Description", app.Element("Description").Value), ColorTranslator.FromHtml(app.Element("Color").Value);
new XElement("Version", app.Element("Version").Value), //Create XElement
new XElement("ID", app.Element("ID").Value), tmp_apps_list.Add(new XElement("App",
new XElement("File", app.Element("File").Value), new XElement("Name", app.Element("Name").Value),
new XElement("Hash", app.Element("Hash").Value) new XElement("Description", app.Element("Description").Value),
)); new XElement("Version", app.Element("Version").Value),
if (app.Element("MainFile") != null) new XElement("ID", app.Element("ID").Value),
apps.Last().Add(new XElement("MainFile", app.Element("MainFile").Value)); new XElement("File", app.Element("File").Value),
if (app.Element("Icon") != null) new XElement("Hash", app.Element("Hash").Value)
apps.Last().Add(new XElement("Icon", app.Element("Icon").Value)); ));
if (app.Element("Color") == null) if (app.Element("MainFile") != null)
apps.Last().Add(new XElement("Color", "#FFFFFF")); tmp_apps_list.Last().Add(new XElement("MainFile", app.Element("MainFile").Value));
else if (app.Element("Icon") != null)
apps.Last().Add(new XElement("Color", app.Element("Color").Value)); {
#if !DEBUG
try
{
#endif
//Scale Image and save as Base64
Image src = Image.FromStream(client.OpenRead(app.Element("Icon").Value));
Bitmap dest = new Bitmap(70, 70);
dest.SetResolution(src.HorizontalResolution, src.VerticalResolution);
using (Graphics g = Graphics.FromImage(dest))
{
g.CompositingMode = CompositingMode.SourceCopy;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
using (var wrapMode = new ImageAttributes())
{
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
g.DrawImage(src, new Rectangle(0, 0, 70, 70), 0, 0, src.Width, src.Height, GraphicsUnit.Pixel, wrapMode);
}
}
using (var ms = new MemoryStream())
{
dest.Save(ms, ImageFormat.Png);
tmp_apps_list.Last().Add(new XElement("Icon", Convert.ToBase64String(ms.ToArray())));
}
#if !DEBUG
}
catch { }
#endif
}
if (app.Element("Color") == null)
tmp_apps_list.Last().Add(new XElement("Color", "#FFFFFF"));
else
tmp_apps_list.Last().Add(new XElement("Color", app.Element("Color").Value));
if (tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value).Count() > 1)
tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value).Reverse().Skip(1).ToList().ForEach(a => tmp_apps_list.Remove(a));
}
} }
#if !DEBUG #if !DEBUG
} }
catch (Exception e) catch (Exception e)
{ {
MessageBox.Show(e.ToString(), "Failed to load repo: " + Settings.Default.Repos[i]); MessageBox.Show(e.ToString(), "Failed to load repo: " + repArr[i]);
} }
#endif #endif
} }
} }
apps.Sort((x, y) => x.Element("Name").Value.CompareTo(y.Element("Name").Value)); tmp_apps_list.Sort((x, y) => x.Element("Name").Value.CompareTo(y.Element("Name").Value));
string xml = dir + @"\info.xml"; if (meta.Element("LocalRepo") == null)
XElement meta = XDocument.Load(xml).Element("meta"); meta.Add(new XElement("LocalRepo"));
if (meta.Element("Repo") == null) XElement repos = meta.Element("LocalRepo");
meta.Add(new XElement("Repo"));
XElement repos = meta.Element("Repo");
repos.RemoveNodes(); repos.RemoveNodes();
apps.ForEach(app => repos.Add(app)); tmp_apps_list.ForEach(app => repos.Add(app));
meta.Save(xml); meta.Save(xml);
} }
#endregion #endregion

View File

@ -80,7 +80,7 @@ namespace UpTool2
Directory.CreateDirectory(dir + @"\Apps"); Directory.CreateDirectory(dir + @"\Apps");
string xml = dir + @"\info.xml"; string xml = dir + @"\info.xml";
if (!File.Exists(xml)) if (!File.Exists(xml))
new XElement("meta", new XElement("Version", 0), new XElement("Repo")).Save(xml); new XElement("meta", new XElement("Version", 0), new XElement("Repos", new XElement("Repo", "https://github.com/CreepyCrafter24/UpTool2/releases/download/Repo/Repo.xml")), new XElement("LocalRepo")).Save(xml);
XElement meta = XDocument.Load("https://github.com/CreepyCrafter24/UpTool2/releases/download/Repo/Meta.xml").Element("meta"); XElement meta = XDocument.Load("https://github.com/CreepyCrafter24/UpTool2/releases/download/Repo/Meta.xml").Element("meta");
int version = int.Parse(meta.Element("Version").Value); int version = int.Parse(meta.Element("Version").Value);
if (int.Parse(XDocument.Load(xml).Element("meta").Element("Version").Value) < version) if (int.Parse(XDocument.Load(xml).Element("meta").Element("Version").Value) < version)

View File

@ -1,41 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace UpTool2.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(@"<?xml version=""1.0"" encoding=""utf-16""?>
<ArrayOfString xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<string>https://github.com/CreepyCrafter24/UpTool2/releases/download/Repo/Repo.xml</string>
</ArrayOfString>")]
public global::System.Collections.Specialized.StringCollection Repos {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["Repos"]));
}
set {
this["Repos"] = value;
}
}
}
}

View File

@ -1,12 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="UpTool2.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="Repos" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;string&gt;https://github.com/CreepyCrafter24/UpTool2/releases/download/Repo/Repo.xml&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -91,15 +91,6 @@
<EmbeddedResource Include="SettingsForm.resx"> <EmbeddedResource Include="SettingsForm.resx">
<DependentUpon>SettingsForm.cs</DependentUpon> <DependentUpon>SettingsForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />