secret
Created

  • Download Gist
configuration.cs
C#
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 System.IO;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
 
namespace Imagine_Updater
{
/*
* Hi there! The Imagine! Updater wants to supply you with a free and easy way to keep your customers software up to date.
* This code is licensed under the Apache 2.0 license.
* If you use this for any bigger project like an indie game or something feel free to shoot me a mail to fe.a.ernst@gmail.com so I have something to brag about but no pressure!
*
* HowTo:
* 1. Find the directory of the program you want to have distributed by this software, copy the path to the textBox next to the Create XML-Button and press it!
* 2. Check the register.xml that was created on your desktop. It should show all the files and folder you want to have synced with your customers.
* Be sure none of your files use weird charakters because some are not supported by xml. I replaced ' ' with '+' so '+' is not supported either but ' ' is.
* 3. Upload that directory and the register.xml to a public part of your server. The two free hosters I tested used to have a "public_html"-folder that served that purpose.
* 4. Change the patchPath string below to match the path to the public part of your server. You may want to test different URL using the download function of this updater.
* For example try to enter an URL ending in "/register.xml" to find your freshly uploaded files.
* 5. Start the program and hope everything works. You will need administrative rights if you patch to some directories.
*
* 6. Feel free to change the other configuartions and the code itself to your liking.
*/
public class UpdaterSettings
{
#region Patch Settings // Developer settings.
// the url to your server repository. I suggest free servers for smaller projects. freeserverhostin.co.uk worked for me so far. Some hosters (000webhost.com) do not allow .exe!
public string RemotePatchURL = "http://eliotvu.com/files/auto/ue-explorer/";
 
// The name of the executable at the root of your savePath. This will be executed when pressing the playButton.
public string ExecutableName = "UE Explorer.exe";
 
// The main element in your register. It doesn't matter how you call it because it works anyways but you maybe want a fitting name.
public string xmlRootName = "UEExplorer";
#endregion
 
#region UI Settings // Visual modifiers.
// How the Updater is labeled.
public string WindowTitle = "UE Explorer updater";
 
// The text on the start program button.
public string LaunchButtonTitle = "Launch";
#endregion
 
#region User Settings // Settings that may differ from user to user.
// This will automatically switch to the patchnotes if available
public bool ShowPatchNotes = true;
 
// When true the updater will automatically patch to newest version if one is available.
public bool AutoUpdate = true;
 
// This will for one thing start the programm instantly when no new version is found on the patch-server. For another it will start the programm as soon as a patch-process is done.
public bool LaunchAfterUpdate = false;
 
// This will hide or show the download and xml-creation capabilities of this updater and one or two notifications.
public bool DevMode = true;
#endregion
 
// I decided to put my files in a bin folder next to the updater to keep things together. But based on this it could become necessary to start the updater with administrative rights.
[XmlIgnore]
public string ApplicationDir = Path.GetDirectoryName(Application.ExecutablePath);
 
// the files added to the notUpdatedFiles string[] won't be added to the xml and therefore not be downloaded and patched. Furthermore files of that kind won't be deleted when found in the savePath.
// I needed this function for one annoying file that somehow changed it's sha1-Hashcode for being downloaded so it was always shown as outdated (not disturbing the functionality of the program).
// You might want to dig into the code when you experience similar issius but need your file patched for new versions. But the one I was talking about was created on runtime anyway.
public static string[] NotUpdatedFiles()
{
var notUpdatedFiles = new[]
{
"Log.txt",
"MRU.xml",
"setup.exe",
"Setup.tmp",
"Updater.application",
"Updater.exe",
"Updater.exe.manifest",
"UEExplorerConfig.xml",
"register.xml"
};
return notUpdatedFiles;
}
/// <summary>
/// Loads the program's update configuration from an XML file such as "Updater.xml".
/// </summary>
/// <returns>the deserialized XML file as an UpdaterSettings instance</returns>
public static UpdaterSettings Load()
{
var settingsDir = Application.StartupPath;
const string settingsExtension = "xml";
const string settingsName = "Updater" + "." + settingsExtension;
var settingsPath = Path.Combine( settingsDir, settingsName );
UpdaterSettings settings;
if( !File.Exists( settingsPath ) )
{
settings = new UpdaterSettings();
using( var writer = new XmlTextWriter( settingsPath, System.Text.Encoding.ASCII ) )
{
var serializer = new XmlSerializer( typeof(UpdaterSettings) );
serializer.Serialize( writer, settings );
}
return settings;
}
 
using( var reader = new XmlTextReader( settingsPath ) )
{
var serializer = new XmlSerializer( typeof(UpdaterSettings) );
settings = (UpdaterSettings)serializer.Deserialize( reader );
}
return settings;
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.