diff --git a/RZ.OneGetProvider/Properties/AssemblyInfo.cs b/RZ.OneGetProvider/Properties/AssemblyInfo.cs index a7a79e4..030004f 100644 --- a/RZ.OneGetProvider/Properties/AssemblyInfo.cs +++ b/RZ.OneGetProvider/Properties/AssemblyInfo.cs @@ -24,7 +24,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Zander Tools")] [assembly: AssemblyProduct("RuckZuck OneGet provider")] -[assembly: AssemblyCopyright("Copyright © 2018 by Roger Zander")] +[assembly: AssemblyCopyright("Copyright © 2019 by Roger Zander")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -49,5 +49,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.6.2.11")] -[assembly: AssemblyFileVersion("1.6.2.11")] +[assembly: AssemblyVersion("1.6.2.13")] +[assembly: AssemblyFileVersion("1.6.2.13")] diff --git a/RZ.OneGetProvider/RZRestAPI.cs b/RZ.OneGetProvider/RZRestAPI.cs index 865e949..f514790 100644 --- a/RZ.OneGetProvider/RZRestAPI.cs +++ b/RZ.OneGetProvider/RZRestAPI.cs @@ -32,11 +32,11 @@ public static string sURL { if (sWebSVC.StartsWith("http", StringComparison.CurrentCultureIgnoreCase)) { - RZRestAPI._sURL = sWebSVC; + RZRestAPI._sURL = sWebSVC.TrimEnd('/'); } } - if (_sURL == "UDP" & !DisableBroadcast) + if (_sURL == "UDP" && !DisableBroadcast) { try { @@ -147,7 +147,7 @@ public static List SWGet(string PackageName, string PackageVersion) { try { - return SWResults("").Where(t => t.ProductName == PackageName & t.ProductVersion == PackageVersion).ToList(); + return SWResults("").Where(t => t.ProductName == PackageName && t.ProductVersion == PackageVersion).ToList(); } catch { } @@ -158,7 +158,7 @@ public static List SWGet(string PackageName, string Manufacturer, s { try { - return SWResults("").Where(t => t.ProductName == PackageName & t.ProductVersion == PackageVersion & t.Manufacturer == Manufacturer).ToList(); + return SWResults("").Where(t => t.ProductName == PackageName && t.ProductVersion == PackageVersion && t.Manufacturer == Manufacturer).ToList(); } catch { } @@ -267,7 +267,7 @@ public static List CheckForUpdate(List lSoftware) if (contentType == "application/json") { var response = oClient.PostAsync(sURL + "/rest/CheckForUpdate", oCont); - response.Wait(15000); + response.Wait(60000); if (response.IsCompleted) { List lRes = ser.Deserialize>(response.Result.Content.ReadAsStringAsync().Result); @@ -309,15 +309,20 @@ public static bool UploadSWEntry(AddSoftware lSoftware) //vNext 5.9.2017 - public static async void TrackDownloads2(long SWId, string Architecture) + public static async void TrackDownloads2(long SWId, string Architecture, string Shortname = "") { try { - await oClient.GetStringAsync(sURL + "/rest/TrackDownloadsNew?SWId=" + SWId.ToString() + "&arch=" + WebUtility.UrlEncode(Architecture)); + string sID = SWId.ToString(); + if (SWId == 0) + sID = ""; + + await oClient.GetStringAsync(sURL + "/rest/TrackDownloadsNew?SWId=" + sID + "&arch=" + WebUtility.UrlEncode(Architecture) + "&shortname=" + WebUtility.UrlEncode(Shortname)); } catch { } } + public static List GetCategories(List oSWList) { List lResult = new List(); @@ -339,7 +344,8 @@ public static byte[] GetIcon(long SWId) using (MemoryStream ms = new MemoryStream()) { response.Result.CopyTo(ms); - return ms.ToArray(); + byte[] bRes = ms.ToArray(); + return bRes; } } @@ -394,6 +400,10 @@ public class GetSoftware public long IconId { get; set; } + public long SWId { get; set; } + + public string IconHash { get; set; } + public bool isInstalled { get; set; } //public string XMLFile { get; set; } @@ -404,14 +414,25 @@ public string IconURL { get { - if (IconId > 0) + //Support new V2 REST API + if (!string.IsNullOrEmpty(IconHash)) { - return RZRestAPI.sURL + "/rest/GetIcon?id=" + IconId.ToString(); + return RZRestAPI.sURL + "/rest/v2/GetIcon?iconhash=" + IconHash; } - else + + if (SWId > 0) { - return ""; // "File://" + IconFile; + return RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); } + + if (IconId > 0) + { + SWId = IconId; + return RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); + } + + return ""; + //return "https://ruckzuck.azurewebsites.net/wcf/RZService.svc/rest/GetIcon?id=" + IconId.ToString(); } } @@ -464,6 +485,9 @@ public class AddSoftware //public long SWId { get { return IconId; } set { IconId = value; } } public long SWId { get; set; } + public long IconId { get; set; } + + public string IconHash { get; set; } //remove if SWId is in place 5.9.2017 //public long IconId { get; set; } @@ -476,6 +500,19 @@ public string IconURL string sURL = RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); return sURL; } + + //Support new V2 REST API + if (!string.IsNullOrEmpty(IconHash)) + { + return RZRestAPI.sURL + "/rest/v2/GetIcon?iconhash=" + IconHash; + } + + if (IconId > 0) + { + SWId = IconId; + string sURL = RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); + return sURL; + } return ""; } } @@ -524,17 +561,17 @@ public string Status { if (string.IsNullOrEmpty(_status)) { - if (Installing & !Error) + if (Installing && !Error) return "Installing"; - if (Downloading & !Error) + if (Downloading && !Error) return "Downloading"; - if (Installed & !Error) + if (Installed && !Error) return "Installed"; - if (UnInstalled & !Error) + if (UnInstalled && !Error) return "Uninstalled"; if (WaitingForDependency) return "Installing dependencies"; - if (PercentDownloaded == 100 & !Error) + if (PercentDownloaded == 100 && !Error) return "Downloaded"; if (Error) return ErrorMessage; diff --git a/RZ.OneGetProvider/RZScan.cs b/RZ.OneGetProvider/RZScan.cs index d0647f1..461d25e 100644 --- a/RZ.OneGetProvider/RZScan.cs +++ b/RZ.OneGetProvider/RZScan.cs @@ -68,7 +68,7 @@ public RZScan(bool RunScan, bool CheckForUpdates) { bRunScan = true; //SWScan(); - GetSWRepository().ConfigureAwait(false); + GetSWRepository().ConfigureAwait(false); //Scan Runs when Repo is loaded } //Check every 60s @@ -165,17 +165,18 @@ public async Task GetSWRepository() { SoftwareRepository = oDB.Select(item => new GetSoftware() { - Categories = item.Categories.ToList(), + Categories = item.Categories ?? new List(), Description = item.Description, Downloads = item.Downloads, IconId = item.IconId, + SWId = item.SWId, Image = item.Image, Manufacturer = item.Manufacturer, ProductName = item.ProductName, ProductURL = item.ProductURL, ProductVersion = item.ProductVersion, - Quality = item.Quality, - Shortname = item.Shortname + Shortname = item.Shortname, + IconHash = item.IconHash }).ToList(); } } @@ -291,9 +292,13 @@ internal void _CheckUpdates(List aSWCheck) var vSWCheck = aSWCheck.Select(t => new AddSoftware() { ProductName = t.ProductName, ProductVersion = t.ProductVersion, Manufacturer = t.Manufacturer }).ToList(); //we do not have to check for updates if it's in the Catalog - List tRes = vSWCheck.Where(t => SoftwareRepository.FirstOrDefault(r => r.ProductName == t.ProductName && r.ProductVersion == t.ProductVersion && r.Manufacturer == t.Manufacturer) == null).ToList(); + //List tRes = vSWCheck.Where(t => SoftwareRepository.Count(r => r.ProductName.ToLower().Trim() == t.ProductName.ToLower().Trim() && r.ProductVersion.ToLower().Trim() == t.ProductVersion.ToLower().Trim() && r.Manufacturer.ToLower().Trim() == t.Manufacturer.ToLower().Trim()) == 0).ToList(); + foreach (var oSW in SoftwareRepository) + { + vSWCheck.RemoveAll(t => t.ProductName.ToLower().Trim() == oSW.ProductName.ToLower().Trim() && t.Manufacturer.ToLower().Trim() == oSW.Manufacturer.ToLower().Trim() && t.ProductVersion.ToLower().Trim() == oSW.ProductVersion.ToLower().Trim()); + } - List lCheckResult = RZRestAPI.CheckForUpdate(tRes).ToList(); + List lCheckResult = RZRestAPI.CheckForUpdate(vSWCheck).ToList(); var lResult = lCheckResult.Select(item => new AddSoftware() { @@ -307,7 +312,9 @@ internal void _CheckUpdates(List aSWCheck) ProductVersion = item.ProductVersion, MSIProductID = item.MSIProductID, Shortname = item.Shortname, - SWId = item.SWId + SWId = item.SWId, + IconId = item.IconId, + IconHash = item.IconHash }).ToList(); //Only take updated Versions @@ -655,17 +662,17 @@ internal static Bitmap GetImageFromExe(string Filename) try { - /*TsudaKageyu.IconExtractor iE = new TsudaKageyu.IconExtractor(Filename); - if (iE.FileName != null) - { - List lIcons = TsudaKageyu.IconUtil.Split(iE.GetIcon(0)).ToList(); - //Max Size 128px... - var ico = lIcons.Where(t => t.Height <= 128 && t.ToBitmap().PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb).OrderByDescending(t => t.Height).FirstOrDefault(); - if (ico != null) - return ico.ToBitmap(); - else - return bResult; - }*/ + //TsudaKageyu.IconExtractor iE = new TsudaKageyu.IconExtractor(Filename); + //if (iE.FileName != null) + //{ + // List lIcons = TsudaKageyu.IconUtil.Split(iE.GetIcon(0)).ToList(); + // //Max Size 128px... + // var ico = lIcons.Where(t => t.Height <= 128 && t.ToBitmap().PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb).OrderByDescending(t => t.Height).FirstOrDefault(); + // if (ico != null) + // return ico.ToBitmap(); + // else + // return bResult; + //} } catch { } diff --git a/RZ.OneGetProvider/RZUpdate.cs b/RZ.OneGetProvider/RZUpdate.cs index 375d3be..7f2f4f9 100644 --- a/RZ.OneGetProvider/RZUpdate.cs +++ b/RZ.OneGetProvider/RZUpdate.cs @@ -258,7 +258,20 @@ internal static AddSoftware ParseJSON(string sFile) try { JavaScriptSerializer ser = new JavaScriptSerializer(); - AddSoftware lRes = ser.Deserialize(File.ReadAllText(sFile)); + string sJson = File.ReadAllText(sFile); + AddSoftware lRes; + + //Check if it's an Arrya (new in V2) + if (sJson.TrimStart().StartsWith("[")) + { + List lItems = ser.Deserialize>(sJson); + lRes = lItems[0]; + } + else + { + lRes = ser.Deserialize(sJson); + } + if (lRes.PreRequisites != null) { lRes.PreRequisites = lRes.PreRequisites.Where(x => !string.IsNullOrEmpty(x)).ToArray(); @@ -542,6 +555,7 @@ private bool _Download(bool Enforce, string DLPath) { foreach (var vFile in SW.Files) { + bool bDLSuccess = false; try { if (string.IsNullOrEmpty(vFile.URL)) @@ -629,20 +643,7 @@ private bool _Download(bool Enforce, string DLPath) } else { - - if (SendFeedback) - { - if (SW.SWId > 0) - { - RZRestAPI.TrackDownloads2(SW.SWId, SW.Architecture); - } - else - { - //Depreciated - //RZRestAPI.TrackDownloads(SW.ContentID); - } - } - + bDLSuccess = true; } //Sleep 1s to complete @@ -775,7 +776,14 @@ private bool _Download(bool Enforce, string DLPath) Console.WriteLine("ERROR: " + ex.Message); bError = true; } + + if (SendFeedback && bDLSuccess) + { + RZRestAPI.TrackDownloads2(SW.SWId, SW.Architecture, SW.Shortname); + } } + + } else { @@ -865,10 +873,17 @@ public async Task Download(bool Enforce, string DLPath) bool bAutoInstall = downloadTask.AutoInstall; downloadTask = new DLTask() { ProductName = SW.ProductName, ProductVersion = SW.ProductVersion, Manufacturer = SW.Manufacturer, Shortname = SW.Shortname, Image = SW.Image, Files = SW.Files }; - if (SW.PreRequisites.Length > 0) + if (SW.PreRequisites != null) { - downloadTask.WaitingForDependency = true; - downloadTask.AutoInstall = false; + if (SW.PreRequisites.Length > 0) + { + downloadTask.WaitingForDependency = true; + downloadTask.AutoInstall = false; + } + else + { + downloadTask.AutoInstall = bAutoInstall; + } } else { @@ -971,7 +986,7 @@ private bool _Install(bool Force = false) downloadTask.Installing = true; ProgressDetails(this.downloadTask, EventArgs.Empty); - var oResult = _RunPS(psPath + SW.PSPreInstall + ";" + SW.PSInstall + ";" + SW.PSPostInstall + ";$ExitCode", "", new TimeSpan(0, 30, 0)); + var oResult = _RunPS(psPath + SW.PSPreInstall + ";" + SW.PSInstall + ";" + SW.PSPostInstall + ";$ExitCode", "", new TimeSpan(0, 60, 0)); try { @@ -1631,7 +1646,7 @@ private bool _checkFileX509(string FilePath, string X509) /// public static PSDataCollection _RunPS(string PSScript, string WorkingDir = "", TimeSpan? Timeout = null) { - TimeSpan timeout = new TimeSpan(0, 5, 0); //default timeout = 5min + TimeSpan timeout = new TimeSpan(0, 15, 0); //default timeout = 15min if (Timeout != null) timeout = (TimeSpan)Timeout; diff --git a/RZUpdate/Properties/AssemblyInfo.cs b/RZUpdate/Properties/AssemblyInfo.cs index 177964b..f84b698 100644 --- a/RZUpdate/Properties/AssemblyInfo.cs +++ b/RZUpdate/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Zander Tools")] [assembly: AssemblyProduct("RZUpdate")] -[assembly: AssemblyCopyright("Copyright © 2018 by Roger Zander")] +[assembly: AssemblyCopyright("Copyright © 2019 by Roger Zander")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.6.2.*")] -[assembly: AssemblyFileVersion("1.6.2.11")] +[assembly: AssemblyFileVersion("1.6.2.13")] diff --git a/RZUpdate/RZRestAPI.cs b/RZUpdate/RZRestAPI.cs index daff067..f514790 100644 --- a/RZUpdate/RZRestAPI.cs +++ b/RZUpdate/RZRestAPI.cs @@ -32,7 +32,7 @@ public static string sURL { if (sWebSVC.StartsWith("http", StringComparison.CurrentCultureIgnoreCase)) { - RZRestAPI._sURL = sWebSVC; + RZRestAPI._sURL = sWebSVC.TrimEnd('/'); } } @@ -267,7 +267,7 @@ public static List CheckForUpdate(List lSoftware) if (contentType == "application/json") { var response = oClient.PostAsync(sURL + "/rest/CheckForUpdate", oCont); - response.Wait(15000); + response.Wait(60000); if (response.IsCompleted) { List lRes = ser.Deserialize>(response.Result.Content.ReadAsStringAsync().Result); @@ -309,15 +309,20 @@ public static bool UploadSWEntry(AddSoftware lSoftware) //vNext 5.9.2017 - public static async void TrackDownloads2(long SWId, string Architecture) + public static async void TrackDownloads2(long SWId, string Architecture, string Shortname = "") { try { - await oClient.GetStringAsync(sURL + "/rest/TrackDownloadsNew?SWId=" + SWId.ToString() + "&arch=" + WebUtility.UrlEncode(Architecture)); + string sID = SWId.ToString(); + if (SWId == 0) + sID = ""; + + await oClient.GetStringAsync(sURL + "/rest/TrackDownloadsNew?SWId=" + sID + "&arch=" + WebUtility.UrlEncode(Architecture) + "&shortname=" + WebUtility.UrlEncode(Shortname)); } catch { } } + public static List GetCategories(List oSWList) { List lResult = new List(); @@ -339,7 +344,8 @@ public static byte[] GetIcon(long SWId) using (MemoryStream ms = new MemoryStream()) { response.Result.CopyTo(ms); - return ms.ToArray(); + byte[] bRes = ms.ToArray(); + return bRes; } } @@ -394,6 +400,10 @@ public class GetSoftware public long IconId { get; set; } + public long SWId { get; set; } + + public string IconHash { get; set; } + public bool isInstalled { get; set; } //public string XMLFile { get; set; } @@ -404,14 +414,25 @@ public string IconURL { get { - if (IconId > 0) + //Support new V2 REST API + if (!string.IsNullOrEmpty(IconHash)) { - return RZRestAPI.sURL + "/rest/GetIcon?id=" + IconId.ToString(); + return RZRestAPI.sURL + "/rest/v2/GetIcon?iconhash=" + IconHash; } - else + + if (SWId > 0) { - return ""; // "File://" + IconFile; + return RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); } + + if (IconId > 0) + { + SWId = IconId; + return RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); + } + + return ""; + //return "https://ruckzuck.azurewebsites.net/wcf/RZService.svc/rest/GetIcon?id=" + IconId.ToString(); } } @@ -464,6 +485,9 @@ public class AddSoftware //public long SWId { get { return IconId; } set { IconId = value; } } public long SWId { get; set; } + public long IconId { get; set; } + + public string IconHash { get; set; } //remove if SWId is in place 5.9.2017 //public long IconId { get; set; } @@ -476,6 +500,19 @@ public string IconURL string sURL = RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); return sURL; } + + //Support new V2 REST API + if (!string.IsNullOrEmpty(IconHash)) + { + return RZRestAPI.sURL + "/rest/v2/GetIcon?iconhash=" + IconHash; + } + + if (IconId > 0) + { + SWId = IconId; + string sURL = RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); + return sURL; + } return ""; } } diff --git a/RZUpdate/RZScan.cs b/RZUpdate/RZScan.cs index 9c6eebe..461d25e 100644 --- a/RZUpdate/RZScan.cs +++ b/RZUpdate/RZScan.cs @@ -165,17 +165,18 @@ public async Task GetSWRepository() { SoftwareRepository = oDB.Select(item => new GetSoftware() { - Categories = item.Categories.ToList(), + Categories = item.Categories ?? new List(), Description = item.Description, Downloads = item.Downloads, IconId = item.IconId, + SWId = item.SWId, Image = item.Image, Manufacturer = item.Manufacturer, ProductName = item.ProductName, ProductURL = item.ProductURL, ProductVersion = item.ProductVersion, - Quality = item.Quality, - Shortname = item.Shortname + Shortname = item.Shortname, + IconHash = item.IconHash }).ToList(); } } @@ -291,9 +292,13 @@ internal void _CheckUpdates(List aSWCheck) var vSWCheck = aSWCheck.Select(t => new AddSoftware() { ProductName = t.ProductName, ProductVersion = t.ProductVersion, Manufacturer = t.Manufacturer }).ToList(); //we do not have to check for updates if it's in the Catalog - List tRes = vSWCheck.Where(t => SoftwareRepository.FirstOrDefault(r => r.ProductName == t.ProductName && r.ProductVersion == t.ProductVersion && r.Manufacturer == t.Manufacturer) == null).ToList(); + //List tRes = vSWCheck.Where(t => SoftwareRepository.Count(r => r.ProductName.ToLower().Trim() == t.ProductName.ToLower().Trim() && r.ProductVersion.ToLower().Trim() == t.ProductVersion.ToLower().Trim() && r.Manufacturer.ToLower().Trim() == t.Manufacturer.ToLower().Trim()) == 0).ToList(); + foreach (var oSW in SoftwareRepository) + { + vSWCheck.RemoveAll(t => t.ProductName.ToLower().Trim() == oSW.ProductName.ToLower().Trim() && t.Manufacturer.ToLower().Trim() == oSW.Manufacturer.ToLower().Trim() && t.ProductVersion.ToLower().Trim() == oSW.ProductVersion.ToLower().Trim()); + } - List lCheckResult = RZRestAPI.CheckForUpdate(tRes).ToList(); + List lCheckResult = RZRestAPI.CheckForUpdate(vSWCheck).ToList(); var lResult = lCheckResult.Select(item => new AddSoftware() { @@ -307,7 +312,9 @@ internal void _CheckUpdates(List aSWCheck) ProductVersion = item.ProductVersion, MSIProductID = item.MSIProductID, Shortname = item.Shortname, - SWId = item.SWId + SWId = item.SWId, + IconId = item.IconId, + IconHash = item.IconHash }).ToList(); //Only take updated Versions @@ -655,17 +662,17 @@ internal static Bitmap GetImageFromExe(string Filename) try { - /*TsudaKageyu.IconExtractor iE = new TsudaKageyu.IconExtractor(Filename); - if (iE.FileName != null) - { - List lIcons = TsudaKageyu.IconUtil.Split(iE.GetIcon(0)).ToList(); - //Max Size 128px... - var ico = lIcons.Where(t => t.Height <= 128 && t.ToBitmap().PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb).OrderByDescending(t => t.Height).FirstOrDefault(); - if (ico != null) - return ico.ToBitmap(); - else - return bResult; - }*/ + //TsudaKageyu.IconExtractor iE = new TsudaKageyu.IconExtractor(Filename); + //if (iE.FileName != null) + //{ + // List lIcons = TsudaKageyu.IconUtil.Split(iE.GetIcon(0)).ToList(); + // //Max Size 128px... + // var ico = lIcons.Where(t => t.Height <= 128 && t.ToBitmap().PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb).OrderByDescending(t => t.Height).FirstOrDefault(); + // if (ico != null) + // return ico.ToBitmap(); + // else + // return bResult; + //} } catch { } diff --git a/RZUpdate/RZUpdate.cs b/RZUpdate/RZUpdate.cs index 5d91972..7f2f4f9 100644 --- a/RZUpdate/RZUpdate.cs +++ b/RZUpdate/RZUpdate.cs @@ -258,7 +258,20 @@ internal static AddSoftware ParseJSON(string sFile) try { JavaScriptSerializer ser = new JavaScriptSerializer(); - AddSoftware lRes = ser.Deserialize(File.ReadAllText(sFile)); + string sJson = File.ReadAllText(sFile); + AddSoftware lRes; + + //Check if it's an Arrya (new in V2) + if (sJson.TrimStart().StartsWith("[")) + { + List lItems = ser.Deserialize>(sJson); + lRes = lItems[0]; + } + else + { + lRes = ser.Deserialize(sJson); + } + if (lRes.PreRequisites != null) { lRes.PreRequisites = lRes.PreRequisites.Where(x => !string.IsNullOrEmpty(x)).ToArray(); @@ -542,6 +555,7 @@ private bool _Download(bool Enforce, string DLPath) { foreach (var vFile in SW.Files) { + bool bDLSuccess = false; try { if (string.IsNullOrEmpty(vFile.URL)) @@ -629,20 +643,7 @@ private bool _Download(bool Enforce, string DLPath) } else { - - if (SendFeedback) - { - if (SW.SWId > 0) - { - RZRestAPI.TrackDownloads2(SW.SWId, SW.Architecture); - } - else - { - //Depreciated - //RZRestAPI.TrackDownloads(SW.ContentID); - } - } - + bDLSuccess = true; } //Sleep 1s to complete @@ -775,7 +776,14 @@ private bool _Download(bool Enforce, string DLPath) Console.WriteLine("ERROR: " + ex.Message); bError = true; } + + if (SendFeedback && bDLSuccess) + { + RZRestAPI.TrackDownloads2(SW.SWId, SW.Architecture, SW.Shortname); + } } + + } else { @@ -865,10 +873,17 @@ public async Task Download(bool Enforce, string DLPath) bool bAutoInstall = downloadTask.AutoInstall; downloadTask = new DLTask() { ProductName = SW.ProductName, ProductVersion = SW.ProductVersion, Manufacturer = SW.Manufacturer, Shortname = SW.Shortname, Image = SW.Image, Files = SW.Files }; - if (SW.PreRequisites.Length > 0) + if (SW.PreRequisites != null) { - downloadTask.WaitingForDependency = true; - downloadTask.AutoInstall = false; + if (SW.PreRequisites.Length > 0) + { + downloadTask.WaitingForDependency = true; + downloadTask.AutoInstall = false; + } + else + { + downloadTask.AutoInstall = bAutoInstall; + } } else { @@ -971,7 +986,7 @@ private bool _Install(bool Force = false) downloadTask.Installing = true; ProgressDetails(this.downloadTask, EventArgs.Empty); - var oResult = _RunPS(psPath + SW.PSPreInstall + ";" + SW.PSInstall + ";" + SW.PSPostInstall + ";$ExitCode", "", new TimeSpan(0,60,0)); + var oResult = _RunPS(psPath + SW.PSPreInstall + ";" + SW.PSInstall + ";" + SW.PSPostInstall + ";$ExitCode", "", new TimeSpan(0, 60, 0)); try { @@ -1173,7 +1188,7 @@ private bool _UnInstall(bool Force = false) downloadTask.Installing = true; ProgressDetails(this.downloadTask, EventArgs.Empty); - var oResult = _RunPS(SW.PSUninstall + ";$ExitCode", "", new TimeSpan(0,30,0)); + var oResult = _RunPS(SW.PSUninstall + ";$ExitCode", "", new TimeSpan(0, 30, 0)); try { @@ -1391,7 +1406,7 @@ public bool _DownloadFile2(string URL, string FileName) //Check if URL is HTTP, otherwise it must be a PowerShell if (!URL.StartsWith("http", StringComparison.CurrentCultureIgnoreCase) && !URL.StartsWith("ftp", StringComparison.CurrentCultureIgnoreCase)) { - var oResults = _RunPS(URL, FileName, new TimeSpan(2,0,0)); //2h timeout + var oResults = _RunPS(URL, FileName, new TimeSpan(2, 0, 0)); //2h timeout if (File.Exists(FileName)) { DLProgress((int)100, EventArgs.Empty); @@ -1629,7 +1644,7 @@ private bool _checkFileX509(string FilePath, string X509) /// /// PowerShell Script /// - public static PSDataCollection _RunPS(string PSScript, string WorkingDir = "",TimeSpan? Timeout = null) + public static PSDataCollection _RunPS(string PSScript, string WorkingDir = "", TimeSpan? Timeout = null) { TimeSpan timeout = new TimeSpan(0, 15, 0); //default timeout = 15min diff --git a/RuckZuck_Tool/MainWindow.xaml.cs b/RuckZuck_Tool/MainWindow.xaml.cs index 3bb2aee..fbfb4d7 100644 --- a/RuckZuck_Tool/MainWindow.xaml.cs +++ b/RuckZuck_Tool/MainWindow.xaml.cs @@ -204,6 +204,8 @@ public void Authenticate() catch { } } + tbURL.IsEnabled = true; + //Authenticate with dummy account if (string.IsNullOrEmpty(sAuthToken)) sAuthToken = RZRestAPI.GetAuthToken("FreeRZ", GetTimeToken()); diff --git a/RuckZuck_Tool/Properties/AssemblyInfo.cs b/RuckZuck_Tool/Properties/AssemblyInfo.cs index fb5faa5..ca078c7 100644 --- a/RuckZuck_Tool/Properties/AssemblyInfo.cs +++ b/RuckZuck_Tool/Properties/AssemblyInfo.cs @@ -12,7 +12,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Zander Tools")] [assembly: AssemblyProduct("RuckZuck")] -[assembly: AssemblyCopyright("Copyright © 2018 by Roger Zander")] +[assembly: AssemblyCopyright("Copyright © 2019 by Roger Zander")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -52,4 +52,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.6.2.*")] -[assembly: AssemblyFileVersion("1.6.2.12")] +[assembly: AssemblyFileVersion("1.6.2.13")] diff --git a/RuckZuck_Tool/Properties/Resources.resx b/RuckZuck_Tool/Properties/Resources.resx index ccc665f..b06479f 100644 --- a/RuckZuck_Tool/Properties/Resources.resx +++ b/RuckZuck_Tool/Properties/Resources.resx @@ -405,7 +405,7 @@ namespace RuckZuck_WCF if (contentType == "application/json") { var response = oClient.PostAsync(sURL + "/rest/CheckForUpdate", oCont); - response.Wait(15000); + response.Wait(60000); if (response.IsCompleted) { List<AddSoftware> lRes = ser.Deserialize<List<AddSoftware>>(response.Result.Content.ReadAsStringAsync().Result); @@ -447,15 +447,16 @@ namespace RuckZuck_WCF //vNext 5.9.2017 - public static async void TrackDownloads2(long SWId, string Architecture) + public static async void TrackDownloads2(long SWId, string Architecture, string Shortname = "") { try { - await oClient.GetStringAsync(sURL + "/rest/TrackDownloadsNew?SWId=" + SWId.ToString() + "&arch=" + WebUtility.UrlEncode(Architecture)); + await oClient.GetStringAsync(sURL + "/rest/TrackDownloadsNew?SWId=" + SWId.ToString() + "&arch=" + WebUtility.UrlEncode(Architecture) + "&shortname=" + Shortname); } catch { } } + public static List<string> GetCategories(List<GetSoftware> oSWList) { List<string> lResult = new List<string>(); @@ -477,7 +478,8 @@ namespace RuckZuck_WCF using (MemoryStream ms = new MemoryStream()) { response.Result.CopyTo(ms); - return ms.ToArray(); + byte[] bRes = ms.ToArray(); + return bRes; } } @@ -532,6 +534,10 @@ namespace RuckZuck_WCF public long IconId { get; set; } + public long SWId { get; set; } + + public string IconHash { get; set; } + public bool isInstalled { get; set; } //public string XMLFile { get; set; } @@ -542,14 +548,25 @@ namespace RuckZuck_WCF { get { - if (IconId > 0) + //Support new V2 REST API + if (!string.IsNullOrEmpty(IconHash)) { - return RZRestAPI.sURL + "/rest/GetIcon?id=" + IconId.ToString(); + return RZRestAPI.sURL + "/rest/v2/GetIcon?iconhash=" + IconHash; } - else + + if (SWId > 0) { - return ""; // "File://" + IconFile; + return RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); } + + if (IconId > 0) + { + SWId = IconId; + return RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); + } + + return ""; + //return "https://ruckzuck.azurewebsites.net/wcf/RZService.svc/rest/GetIcon?id=" + IconId.ToString(); } } @@ -602,6 +619,9 @@ namespace RuckZuck_WCF //public long SWId { get { return IconId; } set { IconId = value; } } public long SWId { get; set; } + public long IconId { get; set; } + + public string IconHash { get; set; } //remove if SWId is in place 5.9.2017 //public long IconId { get; set; } @@ -614,6 +634,19 @@ namespace RuckZuck_WCF string sURL = RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); return sURL; } + + //Support new V2 REST API + if (!string.IsNullOrEmpty(IconHash)) + { + return RZRestAPI.sURL + "/rest/v2/GetIcon?iconhash=" + IconHash; + } + + if (IconId > 0) + { + SWId = IconId; + string sURL = RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); + return sURL; + } return ""; } } @@ -976,7 +1009,20 @@ namespace RZUpdate try { JavaScriptSerializer ser = new JavaScriptSerializer(); - AddSoftware lRes = ser.Deserialize<AddSoftware>(File.ReadAllText(sFile)); + string sJson = File.ReadAllText(sFile); + AddSoftware lRes; + + //Check if it's an Arrya (new in V2) + if (sJson.TrimStart().StartsWith("[")) + { + List<AddSoftware> lItems = ser.Deserialize<List<AddSoftware>>(sJson); + lRes = lItems[0]; + } + else + { + lRes = ser.Deserialize<AddSoftware>(sJson); + } + if (lRes.PreRequisites != null) { lRes.PreRequisites = lRes.PreRequisites.Where(x => !string.IsNullOrEmpty(x)).ToArray(); @@ -1260,6 +1306,7 @@ namespace RZUpdate { foreach (var vFile in SW.Files) { + bool bDLSuccess = false; try { if (string.IsNullOrEmpty(vFile.URL)) @@ -1347,20 +1394,7 @@ namespace RZUpdate } else { - - if (SendFeedback) - { - if (SW.SWId > 0) - { - RZRestAPI.TrackDownloads2(SW.SWId, SW.Architecture); - } - else - { - //Depreciated - //RZRestAPI.TrackDownloads(SW.ContentID); - } - } - + bDLSuccess = true; } //Sleep 1s to complete @@ -1493,7 +1527,17 @@ namespace RZUpdate Console.WriteLine("ERROR: " + ex.Message); bError = true; } + + if (SendFeedback && bDLSuccess) + { + if (SW.SWId > 0) + { + RZRestAPI.TrackDownloads2(SW.SWId, SW.Architecture, SW.Shortname); + } + } } + + } else { @@ -1583,10 +1627,17 @@ namespace RZUpdate bool bAutoInstall = downloadTask.AutoInstall; downloadTask = new DLTask() { ProductName = SW.ProductName, ProductVersion = SW.ProductVersion, Manufacturer = SW.Manufacturer, Shortname = SW.Shortname, Image = SW.Image, Files = SW.Files }; - if (SW.PreRequisites.Length > 0) + if (SW.PreRequisites != null) { - downloadTask.WaitingForDependency = true; - downloadTask.AutoInstall = false; + if (SW.PreRequisites.Length > 0) + { + downloadTask.WaitingForDependency = true; + downloadTask.AutoInstall = false; + } + else + { + downloadTask.AutoInstall = bAutoInstall; + } } else { diff --git a/RuckZuck_Tool/RZRestAPI.cs b/RuckZuck_Tool/RZRestAPI.cs index 6ac964f..fe68001 100644 --- a/RuckZuck_Tool/RZRestAPI.cs +++ b/RuckZuck_Tool/RZRestAPI.cs @@ -32,7 +32,7 @@ public static string sURL { if (sWebSVC.StartsWith("http", StringComparison.CurrentCultureIgnoreCase)) { - RZRestAPI._sURL = sWebSVC; + RZRestAPI._sURL = sWebSVC.TrimEnd('/'); } } @@ -309,15 +309,20 @@ public static bool UploadSWEntry(AddSoftware lSoftware) //vNext 5.9.2017 - public static async void TrackDownloads2(long SWId, string Architecture) + public static async void TrackDownloads2(long SWId, string Architecture, string Shortname = "") { try { - await oClient.GetStringAsync(sURL + "/rest/TrackDownloadsNew?SWId=" + SWId.ToString() + "&arch=" + WebUtility.UrlEncode(Architecture)); + string sID = SWId.ToString(); + if (SWId == 0) + sID = ""; + + await oClient.GetStringAsync(sURL + "/rest/TrackDownloadsNew?SWId=" + sID + "&arch=" + WebUtility.UrlEncode(Architecture) + "&shortname=" + WebUtility.UrlEncode(Shortname)); } catch { } } + public static List GetCategories(List oSWList) { List lResult = new List(); @@ -409,17 +414,17 @@ public string IconURL { get { - if (SWId > 0) - { - return RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); - } - //Support new V2 REST API if(!string.IsNullOrEmpty(IconHash)) { return RZRestAPI.sURL + "/rest/v2/GetIcon?iconhash=" + IconHash; } + if (SWId > 0) + { + return RZRestAPI.sURL + "/rest/GetIcon?id=" + SWId.ToString(); + } + if (IconId > 0) { SWId = IconId; diff --git a/RuckZuck_Tool/RZUpdate.cs b/RuckZuck_Tool/RZUpdate.cs index 147fd6e..cd0e0e8 100644 --- a/RuckZuck_Tool/RZUpdate.cs +++ b/RuckZuck_Tool/RZUpdate.cs @@ -779,10 +779,7 @@ private bool _Download(bool Enforce, string DLPath) if (SendFeedback && bDLSuccess) { - if (SW.SWId > 0) - { - RZRestAPI.TrackDownloads2(SW.SWId, SW.Architecture); - } + RZRestAPI.TrackDownloads2(SW.SWId, SW.Architecture, SW.Shortname); } } diff --git a/RuckZuck_Tool/RuckZuck_Tool.csproj b/RuckZuck_Tool/RuckZuck_Tool.csproj index 861c62d..5f72c29 100644 --- a/RuckZuck_Tool/RuckZuck_Tool.csproj +++ b/RuckZuck_Tool/RuckZuck_Tool.csproj @@ -18,6 +18,9 @@ SAK SAK false + + + publish\ true Disk @@ -32,9 +35,6 @@ 1.0.0.%2a false true - - - AnyCPU