Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
"set close after project: false" as default, remove update checker an…
Browse files Browse the repository at this point in the history
…d build powershell script, add 2019 to nearest version search
  • Loading branch information
unitycoder committed Feb 27, 2019
1 parent 30bd916 commit e31a364
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 91 deletions.
2 changes: 1 addition & 1 deletion UnityLauncher/App.config
Expand Up @@ -31,7 +31,7 @@
<value>True</value>
</setting>
<setting name="closeAfterProject" serializeAs="String">
<value>True</value>
<value>False</value>
</setting>
<setting name="formWidth" serializeAs="String">
<value>600</value>
Expand Down
8 changes: 3 additions & 5 deletions UnityLauncher/Form1.Designer.cs

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

29 changes: 4 additions & 25 deletions UnityLauncher/Form1.cs
Expand Up @@ -19,7 +19,6 @@ 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 githubReleaseAPICheckURL = "https://api.github.com/repos/unitycoder/unitylauncher/releases/latest";
const string githubReleasesLinkURL = "https://github.com/unitycoder/UnityLauncher/releases";

bool isDownloadingUnityList = false;
Expand Down Expand Up @@ -229,8 +228,9 @@ bool ScanUnityInstallations()
if (File.Exists(uninstallExe) == true)
{
var unityExe = Path.Combine(directories[i], "Editor", "Unity.exe");
if (File.Exists(uninstallExe) == true)
if (File.Exists(unityExe) == true)
{
// get full version number from uninstaller
var unityVersion = Tools.GetFileVersionData(uninstallExe).Replace("Unity", "").Trim();
if (unityList.ContainsKey(unityVersion) == false)
{
Expand All @@ -246,7 +246,6 @@ bool ScanUnityInstallations()
} // failed check
} // all root folders


lbl_unityCount.Text = "Found " + unityList.Count.ToString() + " versions";

SetStatus("Finished scanning");
Expand Down Expand Up @@ -313,7 +312,7 @@ void UpdateRecentProjectsList()
}
else
{
Console.WriteLine("Null registry key at " + registryPathsToCheck[i]);
//Console.WriteLine("Null registry key at " + registryPathsToCheck[i]);
}

// parse recent project path
Expand Down Expand Up @@ -1050,7 +1049,7 @@ private void gridRecent_CellEndEdit(object sender, DataGridViewCellEventArgs e)

private void btnCheckUpdates_Click(object sender, EventArgs e)
{
CheckUpdates();
Tools.OpenURL("https://github.com/unitycoder/UnityLauncher/releases");
}

private void btnRefreshProjectList_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -1196,26 +1195,6 @@ string GetSelectedRowData(string key)
return path;
}

void CheckUpdates()
{
var result = Tools.CheckUpdates(githubReleaseAPICheckURL, previousGitRelease);
if (string.IsNullOrEmpty(result) == false)
{
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
{
Tools.OpenURL(githubReleasesLinkURL);
}
}
else
{
SetStatus("No updates available. Current release is " + (float.Parse(previousGitRelease) + 0.01f));
}
}



void BrowseForExistingProjectFolder()
{
folderBrowserDialog1.Description = "Select existing project folder";
Expand Down
2 changes: 1 addition & 1 deletion UnityLauncher/Properties/Settings.Designer.cs

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

2 changes: 1 addition & 1 deletion UnityLauncher/Properties/Settings.settings
Expand Up @@ -19,7 +19,7 @@
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="closeAfterProject" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="formWidth" Type="System.Int32" Scope="User">
<Value Profile="(Default)">600</Value>
Expand Down
61 changes: 4 additions & 57 deletions UnityLauncher/Tools.cs
Expand Up @@ -111,6 +111,10 @@ public static string ReadCustomLaunchArguments(string projectPath, string launch
/// <returns></returns>
public static string FindNearestVersion(string currentVersion, List<string> allAvailable)
{
if (currentVersion.Contains("2019"))
{
return FindNearestVersionFromSimilarVersions(currentVersion, allAvailable.Where(x => x.Contains("2019")));
}
if (currentVersion.Contains("2018"))
{
return FindNearestVersionFromSimilarVersions(currentVersion, allAvailable.Where(x => x.Contains("2018")));
Expand Down Expand Up @@ -378,62 +382,5 @@ 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())
{
// apparently this is now required..otherwise: "The request was aborted: Could not create SSL/TLS secure channel"
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

// fetch current release info
client.Headers.Add("user-agent", "MuskBrowser");
string json = client.DownloadString(githubReleaseURL);

if (json.IndexOf('{') != 0)
{
// invalid json
return result;
}

var arr = json.Split(new string[] { "\"tag_name\":" }, StringSplitOptions.None);

// have tagname
if (arr.Length > 1)
{
var arr2 = arr[1].Trim().Split('"');
// have "
if (arr2.Length > 1)
{
var currentlyAvailableLatestReleaseTag = arr2[1];

// compare online version with build in release version, return github version if different from embedded version
float previous = 0;
float current = 0;
if (float.TryParse(previousGitRelease, out previous) == false) return result;
if (float.TryParse(currentlyAvailableLatestReleaseTag, out current) == false) return result;

if (Math.Abs(previous - current) > 0.1f)
{
result = currentlyAvailableLatestReleaseTag;
Console.WriteLine("update available: [" + currentlyAvailableLatestReleaseTag + "] / [" + previousGitRelease + "]");
}
else
{
Console.WriteLine("no update available: [" + currentlyAvailableLatestReleaseTag + "] / [" + previousGitRelease + "]");
}
}
}
}
return result;
}


}
}
3 changes: 2 additions & 1 deletion UnityLauncher/UnityLauncher.csproj
Expand Up @@ -132,6 +132,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>powershell.exe -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;$web = New-Object System.Net.WebClient;$web.Headers['User-Agent'] = 'DefinitelyBrowser';$results = $web.DownloadString('https://api.github.com/repos/unitycoder/unitylauncher/releases/latest');$results = $results | ConvertFrom-Json;$results = $results | select -expand tag_name;echo $results | Out-File \"$(ProjectDir)PreviousVersion.txt\";"</PreBuildEvent>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
</Project>

0 comments on commit e31a364

Please sign in to comment.