Skip to content
This repository has been archived by the owner on Feb 3, 2019. It is now read-only.

Commit

Permalink
Auto updater
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Tarkus committed May 23, 2014
1 parent 7f9df04 commit cf99092
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
9 changes: 7 additions & 2 deletions cls_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace hyperdesktop2
public static class Settings
{
// Unused
public static Int32 build = 1;
public static Int32 build = 3;
public static String build_url = "https://raw.githubusercontent.com/TheTarkus/Hyperdesktop2/master/BUILD";
public static String release_url = "https://github.com/TheTarkus/Hyperdesktop2/releases";

public static String app_data = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Hyperdesktop2\";
public static String exe_path = app_data + @"hyperdesktop2.exe";
Expand Down Expand Up @@ -38,6 +39,8 @@ public static String Exists(String section, String key, String value)
return (str.Length > 0) ? Read(section, key) : Write(section, key, value);
}

public static String settings_build;

public static String imgur_client_id;

public static Boolean save_screenshots;
Expand All @@ -59,7 +62,9 @@ public static String Exists(String section, String key, String value)
public static void get_settings()
{
Global_Func.app_data_folder_create();
imgur_client_id = Exists("upload", "imgur_client_id", "84c55d06b4c9686");
settings_build = Exists("hyperdesktop2", "build", Convert.ToString(build));

imgur_client_id = Exists("upload", "imgur_client_id", "84c55d06b4c9686");

save_screenshots = Global_Func.str_to_bool(Exists("general", "save_screenshots", "false"));
save_folder = Exists("general", "save_folder", Environment.CurrentDirectory + "\\captures\\");
Expand Down
23 changes: 12 additions & 11 deletions frm_About.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions frm_About.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ void Btn_reportClick(object sender, System.EventArgs e)
{
Process.Start("https://github.com/TheTarkus/Hyperdesktop2/issues");
}
void Frm_AboutLoad(object sender, System.EventArgs e)
{
label_build.Text = "Build: " + Settings.build;
}
}
}
32 changes: 31 additions & 1 deletion frm_Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,26 @@ void drag_drop(object sender, DragEventArgs e)
public frm_Main()
{
InitializeComponent();

// Delete older executable on update
try {
if(Convert.ToInt32(Settings.Read("hyperdesktop2", "build")) < Settings.build) {
File.Delete(Settings.exe_path);
Settings.Write("hyperdesktop2", "build", Settings.build.ToString());
}
} catch (Exception ex) {
Console.WriteLine("Couldn't delete old hyperdesktop2 executable.");
Console.WriteLine(ex.Message);
}

Global_Func.app_data_folder_create();
Global_Func.copy_files();

var web_client = new WebClient();
Int32 build = Convert.ToInt32(web_client.DownloadString(Settings.build_url));

// Confirm if user wants to add to system startup
// on first rnu
// on first run
if(!File.Exists(Settings.ini_path)) {
DialogResult result = MessageBox.Show(
"Do you want to run Hyperdesktop2 at Windows startup?",
Expand All @@ -63,6 +78,21 @@ public frm_Main()
if(result == DialogResult.Yes)
Global_Func.run_at_startup(true);
}
// Update notification
else if(build > Settings.build) {
DialogResult result = MessageBox.Show(
"A new version of Hyperdesktop2 has been released. Would you like to download it?",
"Update available",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1
);

if(result == DialogResult.Yes) {
Process.Start(Settings.release_url);
Process.GetCurrentProcess().Kill();
}
}

var hook = new Hotkeys();
hook.KeyPressed += hook_KeyPressed;
Expand Down

0 comments on commit cf99092

Please sign in to comment.