public Update(string serverAddress, string productName, int productID) { this.serverAddress = serverAddress; applicationPath = Common.SetSlashOnEndOfDirectory(System.Windows.Forms.Application.StartupPath); product = new Product(productName, "", productID); webCalls = WebCalls.Create(); }
public Update(string serverAddress, Product product) { this.serverAddress = serverAddress; this.product = product; applicationPath = Common.SetSlashOnEndOfDirectory(System.Windows.Forms.Application.StartupPath); webCalls = WebCalls.Create(); }
/// <summary> /// Update product from stream /// </summary> /// <param name="stream">XML data in stream</param> /// <returns>Return product object</returns> public static Product Create(Stream stream, Product product) { // try { XmlTextReader reader = new XmlTextReader(stream); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "Product") { // New product class int productID; productID = int.Parse(reader.GetAttribute("id")); if (product == null) { product = new Product(productID); } else { product.productID = productID; } } if (reader.NodeType == XmlNodeType.Element && reader.Name == "Name") { product.name = reader.ReadInnerXml(); } if (reader.NodeType == XmlNodeType.Element && reader.Name == "Version") { product.versionServer = reader.ReadInnerXml(); } if (reader.NodeType == XmlNodeType.Element && reader.Name == "Description") { product.description = reader.ReadInnerXml(); } if (reader.NodeType == XmlNodeType.Element && reader.Name == "UpdateReady") { product.updateReady = reader.ReadInnerXml().Equals("1") ? true : false; } if (reader.NodeType == XmlNodeType.Element && reader.Name == "AllowStart") { product.allowStart = reader.ReadInnerXml().Equals("1") ? true : false; } if (reader.NodeType == XmlNodeType.Element && reader.Name == "AutoStartUpdate") { product.autoStartUpdate = reader.ReadInnerXml().Equals("1") ? true : false; } } reader.Close(); } catch (Exception ex) { Log.Write(ex, typeof(Product), "Create", Log.LogType.ERROR); } return product; }
public Main(string serverAddress, Product product) { InitializeComponent(); this.Text = "Damir Marijanovic - AutoUpdate application (" + Application.ProductVersion + ")"; ShowInfo("AutoUpdate application", LogType.Normal); ShowInfo("Update for " + product.name, LogType.Normal); ShowInfo("Copyright © 2008 - 2011", LogType.Normal); // process //applicationPath = Common.SetSlashOnEndOfDirectory(Application.StartupPath); //webCalls = WebCalls.Create(); //webCalls.DownloadProgress += new WebCalls.delWebCallsDownloadProgress(webCalls_DownloadProgress); update = new Update(this, serverAddress, product); Log.NewMessage += new Log.delGenericLogMessage(Log_NewMessage); }
private void bOK_Click(object sender, EventArgs e) { if (isAuthorized) { product = this.SelectedProduct; this.Close(); } else { RequestAuthorization(tbUsername.Text, tbPassword.Text); } }
public BatchScripts(Product product) { this.product = product; }
public bool GetProductListFromXML(Stream stream, ArrayList productList) { Product product = null; XmlTextReader reader = new XmlTextReader(stream); //XmlReader reader = XmlReader.Create(stream); try { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "Product") { // New product class product = new Product(int.Parse(reader.GetAttribute("id"))); // Add product to list productList.Add(product); } if (reader.NodeType == XmlNodeType.Element && reader.Name == "Name") { product.name = reader.ReadInnerXml(); } if (reader.NodeType == XmlNodeType.Element && reader.Name == "Version") { product.versionServer = reader.ReadInnerXml(); } //if (reader.NodeType == XmlNodeType.Element && reader.Name == "") //{ //} if (reader.NodeType == XmlNodeType.Element && reader.Name == "Description") { product.description = reader.ReadInnerXml(); } } } catch (Exception ex) { Log.Write(ex, this, "GetProductListFromXML", Log.LogType.ERROR); } finally { reader.Close(); } return true; }
public static void LoadUpdateXML_local(ArrayList fileList, out Product product) { //string autoUpdateVersion_local = ""; string applicationPath = System.Windows.Forms.Application.StartupPath; string xmlPath = ""; string fileName = ""; int localVersion; FileStruct fileStruct = null; product = new Product(); if (!applicationPath.EndsWith("\\")) applicationPath += "\\"; xmlPath = applicationPath + Main.constUpdateXMLLocal; // Ako upd.xml ne postoji, predpostavka je da je update potreban if (!File.Exists(xmlPath)) { return; } // parse xml XmlTextReader reader = new XmlTextReader(xmlPath); try { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "Update") { product.versionLocal = reader.GetAttribute("verzija"); product.ProductID = int.Parse(reader.GetAttribute("productid")); } else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Datoteka") { // Ako je fileList null, tada poziv metodi dolati od vanjske aplikacije, aplikacija kojoj treba samo verzija zadnjeg update-a if (fileList != null) { // get file name fileName = reader.GetAttribute("ime").ToLower(); // search for collection of file from server xml list for (int i = 0; i < fileList.Count; i++) { // cast to file list type, make reference to list ithem fileStruct = (FileStruct)fileList[i]; // if (fileStruct.name.ToLower() == fileName) { // update local version of file int.TryParse(reader.GetAttribute("ver"), out localVersion); fileStruct.versionLocal = localVersion; //fileStruct.md5Local = reader.GetAttribute("md5"); break; } } } } } } catch (Exception ex) { Log.Write(ex, typeof(Main), "LoadUpdateXML_local", Log.LogType.ERROR); } finally { reader.Close(); } }
private bool LoadUpdateXML_server(Stream stream, Product product) { bool result = false; FileStruct fileStruct; try { XmlTextReader reader = new XmlTextReader(stream); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "File") { fileStruct = new FileStruct(serverAddress + Main.constURLParams_download_file, applicationPath); bool autoStart = reader.GetAttribute("autoStart") == "1"; int fileID = int.Parse(reader.GetAttribute("id")); int versionServer = int.Parse(reader.GetAttribute("version")); fileStruct.AddFileInfo(reader.GetAttribute("name"), fileID, reader.GetAttribute("savePath"), reader.GetAttribute("url"), versionServer, reader.GetAttribute("md5"), autoStart); fileStruct.md5Local = MD5Hash(fileStruct.SavePath); product.AddFile(fileStruct); } } reader.Close(); result = true; } catch (Exception ex) { ShowInfo("ERROR: " + ex.Message, Main.LogType.Normal); Log.Write(ex, this, "LoadUpdateXML_server", Log.LogType.ERROR); } return result; }
private bool KillAllProccess(Product product) { bool showMessage = false; bool restart = false; foreach (FileStruct fileStruct in product.Files) { if (fileStruct.SaveSuccessfully == false && fileStruct.FileHaveNewVersion()) { // Copy is in _tmp directory if (fileStruct.name.ToLower().EndsWith(".exe")) { // File is application try to kill it if (!fileStruct.name.ToLower().StartsWith("autoupdate")) { if (!FindAndKillProcess(fileStruct.name.Replace(".exe", ""))) { showMessage = true; } } } else { // File is not exe, is dll ... } restart = true; } } if (showMessage) { System.Windows.Forms.MessageBox.Show("Ugasi applikacije sve!!"); } return restart; }
public Update(Main main, string serverAddress, Product product) : this(serverAddress, product) { this.main = main; webCalls.DownloadProgress += new WebCalls.delWebCallsDownloadProgress(main.webCalls_DownloadProgress); }
public void MainUpdateProcedure() { Stream stream; bool result = false; string updateXMLURL; int fileDownloadCount; // Get File list for selected product updateXMLURL = serverAddress + string.Format(Main.constURLParams_get_update_xml, product.ProductID); stream = webCalls.WebGETMethod(updateXMLURL); result = LoadUpdateXML_server(stream, product); //GetUpdateLog(autoUpdateProduct, txtLog, "autoupdatelog.txt"); //GetUpdateLog(product, txtLog, "log.txt"); Log.Write("Skiping update change log...", this, "MainUpdateProcedure", Log.LogType.INFO); // List all files for download Log.Write(product.Files, this, "MainUpdateProcedure", Log.LogType.DEBUG); // Start main update method if (result == true) { // Load local update xml file, Product dummyProduct = new Product(); LoadUpdateXML_local(product.Files, out dummyProduct); // Download all file if (DownloadAllFile(product.Files, out fileDownloadCount)) { // Upgrade successfull WriteXML(applicationPath + Main.constUpdateXMLLocal); ShowInfo("", Main.LogType.Normal); if (fileDownloadCount == 0) { Log.Write("Done", this, "MainUpdateProcedure", Log.LogType.DEBUG); ShowInfo("Done", Main.LogType.Normal); } else { if (KillAllProccess(product)) { BatchScripts bs = new BatchScripts(product); bs.GenerateScript(); ExecuteFileStart("replace.bat", "", 3); // Exit application now Log.Write("Exiting application, restarting", this, "SelfUpdateProcedure", Log.LogType.DEBUG); System.Windows.Forms.Application.Exit(); } else { Log.Write("Update successful", this, "MainUpdateProcedure", Log.LogType.DEBUG); ShowInfo("Update successful", Main.LogType.Normal); } } main.btnAzuriraj.Enabled = true; } else { // Error upgrading ShowInfo("", Main.LogType.Normal); ShowInfo("An error occurred while trying to update", Main.LogType.Normal); Log.Write("An error occurred while trying to update", this, "MainUpdateProcedure", Log.LogType.WARNING); } } else { ShowInfo("", Main.LogType.Normal); ShowInfo("Error connecting to update server", Main.LogType.Normal); Log.Write("Error connecting to update server", this, "MainUpdateProcedure", Log.LogType.WARNING); } }
public static string Debug(Product product) { string buff; if (product != null) { buff = "Name: " + product.name + Environment.NewLine; buff += "Description: " + product.description + Environment.NewLine; buff += "ProductID: " + product.productID + Environment.NewLine; buff += "VersionServer: " + product.versionServer + Environment.NewLine; buff += "VersionLocal: " + product.versionLocal + Environment.NewLine; buff += "UpdateReady: " + product.updateReady + Environment.NewLine; buff += "AllowStart: " + product.allowStart + Environment.NewLine; buff += "AutoStartUpdate: " + product.autoStartUpdate + Environment.NewLine; } else { buff = "Product is empty"; } return buff; }