コード例 #1
0
 private void _UpdateSucess()
 {
     Mydebug.MyDEBUG("成功更新");
     this.Invoke(new UIperDelegate(_UpdateUI), new object[] { UItype.UpdateProgress, 100 });
     if (!string.IsNullOrEmpty(_startExePath))
     {
         KillExe.StartExeByCMD(_startExePath);
         ScreenTool.MinScreen();
         Mydebug.MyDEBUG("启动:" + _startExePath);
         Console.WriteLine("更新完成功启动" + _startExePath);
     }
     else
     {
         Mydebug.MyDEBUG("未启动:启动前exe未运行");
         Console.WriteLine("更新完成功未启动:启动前exe未运行");
     }
     _zipTest.Clear();
     if (_boolonlyOne)
     {
         Thread.Sleep(1500);
         Application.Exit();
         _httpDownload.Clear();
     }
     else
     {
         _isdownloading = false;
         _httpDownload.Clear();
     }
 }
コード例 #2
0
        private void _UzipErr()
        {
            this.Invoke(new UIperDelegate(_UpdateUI), new object[] { UItype.Uziptext, 0 });
            _zipTest.Clear();
            if (!string.IsNullOrEmpty(_startExePath))
            {
                KillExe.StartExeByCMD(_startExePath);
                ScreenTool.MinScreen();
                Mydebug.MyDEBUG("解压到本地失败,启动:" + _startExePath);
                Console.WriteLine("解压到本地失败,启动" + _startExePath);
            }
            else
            {
                Mydebug.MyDEBUG("解压到本地失败,未启动");
                Console.WriteLine("解压到本地失败,未启动");
            }

            if (_boolonlyOne)
            {
                Thread.Sleep(1500);
                Application.Exit();
                _httpDownload.Clear();
            }
            else
            {
                _isdownloading = false;
                _httpDownload.Clear();
            }
        }
コード例 #3
0
        private void _UpdateFile(string filePath)
        {
            Console.WriteLine("准备更新:" + filePath);
            //开始替换更新包

            if (Directory.Exists(filePath))
            {
                Console.WriteLine("____________0_____________");
                if (Directory.Exists(_updatePath))
                {
                    Console.WriteLine("____________01_____________");

                    //DirectoryInfo inff = new DirectoryInfo(_updatePath);
                    //List<IntPtr> explorer = User32API.GetWindowHandleByName("explorer");
                    //Console.WriteLine("资源管理器长度:"+explorer.Count);

                    //if (explorer.Count > 0)
                    //{
                    //    Console.WriteLine("资源管理器[0]:" + explorer[0]);
                    //    //KillExe.KillExeByCMD("explorer.exe");
                    //    //KillExe.StartExeByCMD("explorer.exe");
                    //}

                    _OverwiteDirectory(filePath, _updatePath);
                    //try
                    //{
                    //    inff.Delete(true);
                    //}
                    //catch (Exception ex)
                    //{
                    //    KillExe.KillExeByCMD("explorer.exe");
                    //    inff.Delete(true);
                    //    KillExe.StartExeByCMD("explorer.exe");
                    //}
                }
                else
                {
                    Directory.CreateDirectory(_updatePath.Substring(0, _updatePath.LastIndexOf('\\')));
                    DirectoryInfo info = new DirectoryInfo(filePath);
                    try
                    {
                        info.MoveTo(_updatePath);
                    }
                    catch (Exception ex)
                    {
                        KillExe.KillExeByCMD("explorer.exe");
                        info.MoveTo(_updatePath);
                        KillExe.StartExeByCMD("explorer.exe");
                    }
                }
                Console.WriteLine("更新完成:" + _updatePath);
                _UpdateSucess();
            }
            else
            {
                Mydebug.MyDEBUG("!!!更新失败");
                this.Invoke(new UIperDelegate(_UpdateUI), new object[] { UItype.Updatetext, 0 });
                _zipTest.Clear();

                if (!string.IsNullOrEmpty(_startExePath))
                {
                    KillExe.StartExeByCMD(_startExePath);
                    ScreenTool.MinScreen();
                    Mydebug.MyDEBUG("更新指定位置失败,启动:" + _startExePath);
                    Console.WriteLine("更新指定位置失败,启动" + _startExePath);
                }
                else
                {
                    Mydebug.MyDEBUG("更新指定位置失败,未启动");
                    Console.WriteLine("更新指定位置失败,未启动");
                }
                if (_boolonlyOne)
                {
                    Thread.Sleep(1500);
                    Application.Exit();
                    _httpDownload.Clear();
                }
                else
                {
                    _isdownloading = false;
                    _httpDownload.Clear();
                }
            }
        }
コード例 #4
0
        private void _Start()
        {
            Process[] localByName = Process.GetProcessesByName(_killExeName);
            if (localByName.Length > 0)
            {
                _startExePath = localByName[0].MainModule.FileName;
                Console.WriteLine("杀掉进程的路径:" + _startExePath);
                Mydebug.MyDEBUG("杀掉进程的路径:" + _startExePath);
            }
            else
            {
                Console.WriteLine("未找到杀掉进程的路径:");
                Mydebug.MyDEBUG("杀掉进程的路径:" + _startExePath);
            }

            KillExe.KillExeByCMD(_killExeName + ".exe");
            //int pr = ScreenTool.GetCurrentWindowHandle();
            //ScreenTool.MaxScreen();
            //Console.WriteLine(pr);

            if (!_startSucess)
            {
                return;
            }

            if (!_isdownloading)
            {
                _isdownloading = true;
            }
            else
            {
                return;
            }
            _UIInit();


            if (Directory.Exists(_rootPath))
            {
                try
                {
                    Console.WriteLine("开始删除");
                    Mydebug.MyDEBUG("开始删除上次缓存");

                    FileSystemInfo[] fileinfo = new DirectoryInfo(_rootPath).GetFileSystemInfos();
                    foreach (FileSystemInfo i in fileinfo)
                    {
                        if (i is DirectoryInfo)
                        {
                            DirectoryInfo info = new DirectoryInfo(i.FullName);
                            info.Delete(true);
                        }
                        else
                        {
                            FileInfo info = new FileInfo(i.FullName);
                            if (info.IsReadOnly)
                            {
                                info.IsReadOnly = false;
                            }
                            File.Delete(i.FullName);
                        }
                    }
                    Mydebug.MyDEBUG("删除上次缓存完毕");
                }

                catch (Exception ex)
                {
                    KillExe.KillExeByCMD("explorer.exe");
                    Directory.Delete(_rootPath, true);
                    Directory.CreateDirectory(_rootPath);
                    KillExe.StartExeByCMD("explorer.exe");
                }
            }
            else
            {
                Directory.CreateDirectory(_rootPath);
            }


            if (_isOSS)
            {
                //if (_downLoadOSS == null)
                //{
                //    _downLoadOSS = new DownLoadOSS();
                //    _downLoadOSS.rootPath = _downloadPath;
                //    _downLoadOSS.ProgrecessEvent += _UpdateUIAsy;
                //}
                //_downLoadOSS.EventCompelete += _SaveComPelete;
                //_downLoadOSS.DownloadZip(_ossPath);
            }
            else
            {
                if (_httpDownload == null)
                {
                    _httpDownload                  = new HttpDownload();
                    _httpDownload.rootPath         = _downloadPath;
                    _httpDownload.ProgrecessEvent += _UpdateUIAsy;
                }
                _httpDownload.EventCompelete += _SaveComPelete;
                _httpDownload.DownloadFile(_ossPath);
            }
        }