Skip to content

Commit

Permalink
adjust statusbar texts fixes unitycoder#37, compare version numbers, …
Browse files Browse the repository at this point in the history
…if difference is more than 0.1 then show update available fixes unitycoder#38, clear folder list when loading settings fixes#39
  • Loading branch information
unitycoder committed Feb 21, 2018
1 parent a5731f8 commit 96b1a38
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
22 changes: 14 additions & 8 deletions UnityLauncher/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class Form1 : Form
public static Dictionary<string, string> unityList = new Dictionary<string, string>();
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
const string launcherArgumentsFile = "LauncherArguments.txt";
const string githubReleaseCheckURL = "https://api.github.com/repos/unitycoder/unitylauncher/releases/latest";
const string githubReleaseAPICheckURL = "https://api.github.com/repos/unitycoder/unitylauncher/releases/latest";
const string githubReleasesURL = "https://github.com/unitycoder/UnityLauncher/releases";

bool isDownloadUnityList = false;
Expand Down Expand Up @@ -135,6 +135,7 @@ void LoadSettings()
gridRecent.Columns["_gitBranch"].Visible = chkShowGitBranchColumn.Checked;

// update installations folder listbox
lstRootFolders.Items.Clear();
lstRootFolders.Items.AddRange(Properties.Settings.Default.rootFolders.Cast<string>().ToArray());
// update packages folder listbox
lstPackageFolders.Items.AddRange(Properties.Settings.Default.packageFolders.Cast<string>().ToArray());
Expand Down Expand Up @@ -167,7 +168,7 @@ bool HaveExactVersionInstalled(string version)

void AddUnityInstallationRootFolder()
{
folderBrowserDialog1.Description = "Select root folder";
folderBrowserDialog1.Description = "Select Unity installations root folder";
var d = folderBrowserDialog1.ShowDialog();
var newRoot = folderBrowserDialog1.SelectedPath;

Expand Down Expand Up @@ -363,8 +364,14 @@ void LaunchProject(string projectPath, string version, bool openProject = true,

if (HaveExactVersionInstalled(version) == true)
{
//Console.WriteLine("Opening unity version " + version);
SetStatus("Launching project in unity " + version);
if (openProject == true)
{
SetStatus("Launching project in Unity " + version);
}
else
{
SetStatus("Launching Unity " + version);
}

try
{
Expand Down Expand Up @@ -527,7 +534,6 @@ void LaunchSelectedProject(bool openProject = true)
var selected = gridRecent.CurrentCell.RowIndex;
if (selected > -1)
{
SetStatus("Launching project..");
var projectPath = gridRecent.Rows[selected].Cells["_path"].Value.ToString();
var version = Tools.GetProjectVersion(projectPath);
LaunchProject(projectPath, version, openProject);
Expand Down Expand Up @@ -1100,10 +1106,10 @@ string GetSelectedRowData(string key)

void CheckUpdates()
{
var result = Tools.CheckUpdates(githubReleaseCheckURL, previousGitRelease);
var result = Tools.CheckUpdates(githubReleaseAPICheckURL, previousGitRelease);
if (string.IsNullOrEmpty(result) == false)
{
SetStatus("Update available: " + result);
SetStatus("Update available: " + result + " - Previous release was:" + previousGitRelease);
DialogResult dialogResult = MessageBox.Show("Update " + result + " is available, open download page?", "UnityLauncher - Check Update", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes) // open download page
{
Expand All @@ -1112,7 +1118,7 @@ void CheckUpdates()
}
else
{
SetStatus("No updates available..");
SetStatus("No updates available. Current release is " + previousGitRelease);
}
}
}
Expand Down
Binary file modified UnityLauncher/PreviousVersion.txt
Binary file not shown.
12 changes: 10 additions & 2 deletions UnityLauncher/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,18 @@ public static bool LaunchExplorer(string folder)
return result;
}

/// <summary>
///
/// </summary>
/// <param name="githubReleaseURL">api to check releases</param>
/// <param name="previousGitRelease">embedded previous release version</param>
/// <returns>null if no info available, otherwise returns current github release number</returns>
public static string CheckUpdates(string githubReleaseURL, string previousGitRelease)
{
string result = null;
using (WebClient client = new WebClient())
{
// fetch current release info
client.Headers.Add("user-agent", "MuskBrowser");
string json = client.DownloadString(githubReleaseURL);
var arr = json.Split(new string[] { "\"tag_name\":" }, StringSplitOptions.None);
Expand All @@ -342,8 +349,9 @@ public static string CheckUpdates(string githubReleaseURL, string previousGitRel
if (arr2.Length > 1)
{
var currentlyAvailableLatestReleaseTag = arr2[1];
// compare with this build release version
if (currentlyAvailableLatestReleaseTag != previousGitRelease)
// compare online version with build in release version, return github version if different from embedded version
if (Math.Abs(float.Parse(currentlyAvailableLatestReleaseTag)-float.Parse(previousGitRelease))>0.1f)
// if (currentlyAvailableLatestReleaseTag != previousGitRelease)
{
result = currentlyAvailableLatestReleaseTag;
Console.WriteLine("update available: [" + currentlyAvailableLatestReleaseTag + "] / [" + previousGitRelease + "]");
Expand Down

0 comments on commit 96b1a38

Please sign in to comment.