using Microsoft.Win32; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.Http; using System.Reflection; using System.Diagnostics; using System.Net; using System.IO; using Neo.LegitimateLicences.Helpers; using System.Configuration; using Microsoft.VisualBasic; namespace Neo.LegitimateLicences.DesktopUpdater { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { string version = ""; try { string paramenters = ""; System.Threading.Thread.Sleep(1000); #region Validate the arguments if (args.Length == 0) { version = Interaction.InputBox("Enter version number to download", "Version Download", "1.0.0.0", -1, -1); } else { args[0] = args[0].ToLower(); paramenters = args[0]; } using (EventLog eventLog = new EventLog("Application")) { eventLog.Source = "Application"; eventLog.WriteEntry("Legitimate Desktop Install: Update started with the following parameters: " + paramenters, EventLogEntryType.Information, 101, 1); } var argumentString = paramenters; var arguments = argumentString.Split('_'); if(String.IsNullOrEmpty(version)) { if (arguments.Length != 4 && arguments.Length != 1) { MessageBox.Show("Invalid argument format."); return; } version = arguments.Length == 4 ? arguments[3] : arguments[0]; } #endregion //string downLoads = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "{374DE290-123F-4565-9164-39C4925E467B}", String.Empty).ToString(); if(String.IsNullOrEmpty(version)) { MessageBox.Show("Version not specified"); throw new Exception("Version not specified"); } if (File.Exists(Application.StartupPath + "\\" + version/*version number*/+ ".zip")) { File.Delete(Application.StartupPath + "\\" + version/*version number*/+ ".zip"); } #region Download file from Cdn using (var client = new WebClient()) { Helpers.Common common = new Common(); common.SetApiVersion(ConfigurationManager.AppSettings["Environment"]); using (EventLog eventLog = new EventLog("Application")) { eventLog.Source = "Application"; eventLog.WriteEntry("Legitimate Desktop Install: Download version : " + common.CdnUrl + version/*version number*/+ ".zip", EventLogEntryType.Information, 101, 1); } client.DownloadFile(common.CdnUrl + version/*version number*/+ ".zip", Application.StartupPath + "\\" + version/*version number*/+ ".zip"); } #endregion #region Extract Zip file Ionic.Zip.ZipFile zipFile = new Ionic.Zip.ZipFile(Application.StartupPath + "\\" + version/*version number*/+ ".zip"); zipFile.ExtractAll(Application.StartupPath, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently); zipFile.Dispose(); #endregion #region Delete Zip file if (File.Exists(Application.StartupPath + "\\" + version/*version number*/+ ".zip")) { File.Delete(Application.StartupPath + "\\" + version/*version number*/+ ".zip"); } #endregion #region Call Neo.LegitimateLicences.Desktop.exe if (arguments.Length == 4) { string filename = Path.Combine(Application.StartupPath, "Neo.LegitimateLicences.Desktop.exe"); string returnArray = args[0].ToLower(); var returnValue = returnArray.Split('_'); var returnString = returnValue[0] + "_" + returnValue[1] + "_" + returnValue[2]; var proc = System.Diagnostics.Process.Start(filename, returnString); using (EventLog eventLog = new EventLog("Application")) { eventLog.Source = "Application"; eventLog.WriteEntry("Legitimate Desktop: Called with the following parameters: " + returnString, EventLogEntryType.Information, 101, 1); } } #endregion } catch (Exception ex) { MessageBox.Show("Error downloading latest version " + version); using (EventLog eventLog = new EventLog("Application")) { eventLog.Source = "Application"; eventLog.WriteEntry("Legitimate Desktop Install Error: " + ex.Message, EventLogEntryType.Error, 101, 1); if(ex.InnerException != null) { eventLog.WriteEntry("Legitimate Desktop Install Error: " + ex.InnerException.ToString(), EventLogEntryType.Error, 101, 1); } } return; } return; } } }