コード例 #1
0
ファイル: Update.cs プロジェクト: dmarijanovic/auto-update
        public Result.ResultType SelfUpdateProcedure()
        {
            Product autoUpdateProduct;
            Stream stream;
            string requestURL;
            bool result;
            int fileDownloadCount;

            try
            {
                // Authorization
                requestURL = serverAddress + AutoUpdate.Main.constURLParams_authorization;
                result = webCalls.WebAuthorization(requestURL, AutoUpdate.Main.constAuthorization_username, AutoUpdate.Main.constAuthorization_password);

                // Get product info, create product object
                requestURL = serverAddress + AutoUpdate.Main.constURLParams_get_product_from_product_name;
                requestURL = string.Format(requestURL, Main.constAutoUpdateProductName);
                stream = webCalls.WebGETMethod(requestURL);
                autoUpdateProduct = Product.Create(stream);

                // Get File list for autoupdate
                requestURL = serverAddress + string.Format(Main.constURLParams_get_update_xml, autoUpdateProduct.ProductID);
                stream = webCalls.WebGETMethod(requestURL);
                result = LoadUpdateXML_server(stream, autoUpdateProduct);

                // Find autoupdate.exe filesruct and modified it
                FileStruct fileStruct = autoUpdateProduct.GetFile(Main.constAutoUpdateExeName);
                fileStruct.autoStartArgs = string.Format("server={0} pid={1}", serverAddress, product.ProductID);

                Log.Write(autoUpdateProduct.Files, this, "SelfUpdateProcedure", Log.LogType.DEBUG);

                if (result == true)
                {
                    if (DownloadAllFile(autoUpdateProduct.Files, out fileDownloadCount))
                    {
                        if (fileDownloadCount > 0)
                        {
                            // New AutoUpdate version available
                            Log.Write("New AutoUpdate version available", this, "SelfUpdateProcedure", Log.LogType.DEBUG);

                            KillAllProccess(autoUpdateProduct);

                            //ExecuteFileStart(fileStruct.SavePath, fileStruct.autoStartArgs, 0);

                            BatchScripts bs = new BatchScripts(autoUpdateProduct);
                            bs.GenerateScript();

                            //AutoStartDownloadFiles(autoUpdateProduct.Files);

                            ExecuteFileStart("replace.bat", "", 3);

                            // Exit application now
                            Log.Write("Exiting application, restarting", this, "SelfUpdateProcedure", Log.LogType.DEBUG);
                            System.Windows.Forms.Application.Exit();
                            return Result.ResultType.Pass;
                        }
                        else
                        {
                            return Result.ResultType.True;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, this, "SelfUpdateProcedure", Log.LogType.ERROR);
            }

            return Result.ResultType.False;
        }
コード例 #2
0
ファイル: Update.cs プロジェクト: dmarijanovic/auto-update
        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);
            }
        }