Пример #1
0
 public MainForm(UpdateWork _updateWork)
 {
     InitializeComponent();
     updateWork = _updateWork;
     foreach (var item in _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].VersionDesc.Split('$'))
     {
         this.lblContent.Text = this.lblContent.Text + item + Environment.NewLine;
     }
 }
Пример #2
0
 public UpdateForm(UpdateWork _work)
 {
     work = _work;
     InitializeComponent();
     UpdateUIDelegate = new UpdateUI((obj) =>
     {
         this.updateBar.Value = obj;
     });
     work.OnUpdateProgess += new UpdateWork.UpdateProgess((obj) =>
     {
         this.Invoke(UpdateUIDelegate, (int)obj);
     });
 }
Пример #3
0
        public MainForm(UpdateWork _updateWork)
        {
            InitializeComponent();
            updateWork = _updateWork;
            var res = _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].ReleaseUrl;

            var temp   = WebRequest.Create(res);
            var stream = temp.GetResponse().GetResponseStream();

            foreach (var item in _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].VersionDesc.Split('$'))
            {
                this.lblContent.Text = this.lblContent.Text + item + Environment.NewLine;
            }
        }
Пример #4
0
        public MainForm(UpdateWork _updateWork)
        {
            InitializeComponent();
            updateWork = _updateWork;
            var res = _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].VersionDesc;

            this.lblContent.Text = res;
            //var temp = WebRequest.Create(res);
            //var stream = temp.GetResponse().GetResponseStream();
            //using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default))
            //{
            //    string text = reader.ReadToEnd();
            //    this.lblContent.Text = text;
            //}
        }
Пример #5
0
        public MainForm(UpdateWork _updateWork)
        {
            InitializeComponent();
            updateWork = _updateWork;
            var res = _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].VersionDesc;

            var temp   = WebRequest.Create(res);
            var stream = temp.GetResponse().GetResponseStream();

            using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default))
            {
                string text = reader.ReadToEnd();
                this.lblContent.Text = text;
            }
            //foreach (var item in _updateWork.UpdateVerList[_updateWork.UpdateVerList.Count - 1].VersionDesc.Split('$'))
            //{
            //    this.lblContent.Text = this.lblContent.Text + item + Environment.NewLine;
            //}
        }
Пример #6
0
        static void Main(string[] args)
        {
            if (f)
            {
                try
                {
                    if (String.IsNullOrEmpty(args[0]) == false)
                    {
                        UpdateWork updateWork = new UpdateWork(args[0]);
                        if (updateWork.UpdateVerList.Count > 0)
                        {
                            /* 当前用户是管理员的时候,直接启动应用程序
                             * 如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行
                             */
                            //获得当前登录的Windows用户标示
                            System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
                            //创建Windows用户主题
                            Application.EnableVisualStyles();
                            System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
                            //判断当前登录用户是否为管理员
                            if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
                            {
                                if (args[1] == "1")
                                {
                                    updateWork.Do();
                                }
                                else
                                {
                                    Application.EnableVisualStyles();
                                    Application.SetCompatibleTextRenderingDefault(false);
                                    Application.Run(new MainForm(updateWork));
                                }
                            }
                            else
                            {
                                String result = Environment.GetEnvironmentVariable("systemdrive");
                                if (AppDomain.CurrentDomain.BaseDirectory.Contains(result))
                                {
                                    //创建启动对象
                                    ProcessStartInfo startInfo = new ProcessStartInfo
                                    {
                                        //设置运行文件
                                        FileName = System.Windows.Forms.Application.ExecutablePath,
                                        //设置启动动作,确保以管理员身份运行
                                        Verb = "runas",

                                        Arguments = " " + args[0] + " " + args[1]
                                    };
                                    //如果不是管理员,则启动UAC
                                    System.Diagnostics.Process.Start(startInfo);
                                }
                                else
                                {
                                    if (args[1] == "1")
                                    {
                                        updateWork.Do();
                                    }
                                    else
                                    {
                                        Application.EnableVisualStyles();
                                        Application.SetCompatibleTextRenderingDefault(false);
                                        Application.Run(new MainForm(updateWork));
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            if (f)
            {
                try
                {
                    if (args.Length == 0)
                    {
                        args = new string[] { "MAutoUpdate.Test.exe", "0" };
                    }

                    string programName   = args[0];
                    string silentUpdate  = args[1];
                    string isClickUpdate = "0";
                    string localAddress  = AppDomain.CurrentDomain.BaseDirectory;
                    if (args.Length == 3)
                    {
                        isClickUpdate = args[2];
                    }
                    if (string.IsNullOrEmpty(programName) == false)
                    {
                        UpdateWork updateWork = new UpdateWork(programName, localAddress, isClickUpdate);
                        if (updateWork.UpdateVerList == null)
                        {
                            //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, programName);
                            //Process.Start(path);
                            Application.Exit();
                            return;
                        }

                        if (updateWork.UpdateVerList.Count > 0)
                        {
                            /* 当前用户是管理员的时候,直接启动应用程序
                             * 如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行
                             */
                            //获得当前登录的Windows用户标示
                            System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
                            //创建Windows用户主题
                            Application.EnableVisualStyles();
                            System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
                            //判断当前登录用户是否为管理员
                            if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
                            {
                                if (silentUpdate == "1")
                                {
                                    updateWork.Do();
                                }
                                else
                                {
                                    Application.EnableVisualStyles();
                                    Application.SetCompatibleTextRenderingDefault(false);
                                    Application.Run(new MainForm(updateWork));
                                }
                            }
                            else
                            {
                                string result = Environment.GetEnvironmentVariable("systemdrive");
                                if (AppDomain.CurrentDomain.BaseDirectory.Contains(result))
                                {
                                    //创建启动对象
                                    ProcessStartInfo startInfo = new ProcessStartInfo
                                    {
                                        //设置运行文件
                                        FileName = System.Windows.Forms.Application.ExecutablePath,
                                        //设置启动动作,确保以管理员身份运行
                                        Verb      = "runas",
                                        Arguments = " " + programName + " " + silentUpdate
                                    };
                                    //如果不是管理员,则启动UAC
                                    System.Diagnostics.Process.Start(startInfo);
                                }
                                else
                                {
                                    if (silentUpdate == "1")
                                    {
                                        updateWork.Do();
                                    }
                                    else
                                    {
                                        Application.EnableVisualStyles();
                                        Application.SetCompatibleTextRenderingDefault(false);
                                        Application.Run(new MainForm(updateWork));
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }