Example #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();
     }
 }
Example #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();
            }
        }
Example #3
0
        public static List <IntPtr> GetWindowHandleByName(string Name)
        {
            IntPtr        ptrWnd      = IntPtr.Zero;
            List <IntPtr> intPtrArray = new List <IntPtr>();

            Process[] localByName = Process.GetProcessesByName(Name);
            uint      uiPid       = 0;//进程id

            if (localByName.Length > 0)
            {
                for (int i = 0; i < localByName.Length; i++)
                {
                    uiPid = (uint)localByName[i].Id;
                    Console.WriteLine("当前进程id" + uiPid);
                    object objWnd = processWnd[uiPid];

                    if (objWnd != null)
                    {
                        Console.WriteLine("! null");
                        ptrWnd = (IntPtr)objWnd;
                        if (ptrWnd != IntPtr.Zero && IsWindow(ptrWnd))  // 从缓存中获取句柄
                        {
                            intPtrArray.Add(ptrWnd);
                        }
                        else
                        {
                            Console.WriteLine("再次查询null");
                            ptrWnd = IntPtr.Zero;
                        }
                    }
                    bool bResult = EnumWindows(new WNDENUMPROC(EnumWindowsProc), uiPid);
                    // 枚举窗口返回 false 并且没有错误号时表明获取成功
                    Console.WriteLine(bResult);
                    if (!bResult && Marshal.GetLastWin32Error() == 0)
                    {
                        objWnd = processWnd[uiPid];
                        if (objWnd != null)
                        {
                            ptrWnd = (IntPtr)objWnd;
                            intPtrArray.Add(ptrWnd);
                            Mydebug.MyDEBUG("screenTool_suscess");
                        }
                    }
                    else
                    {
                        Mydebug.MyDEBUG("screenTool_error");
                    }
                }
            }
            return(intPtrArray);
        }
Example #4
0
        private void _UzipCompelete(bool suscess, string filePath)
        {
            _zipTest.UzipCompeleteEvent -= _UzipCompelete;
            if (suscess)
            {
                Mydebug.MyDEBUG("解压完毕");

                this.Invoke(new UIperDelegate(_UpdateUI), new object[] { UItype.UzipProgress, 100 });
                _UpdateFile(filePath);
            }
            else
            {
                Mydebug.MyDEBUG("解压失败");
                _UzipErr();
            }
        }
Example #5
0
        public static IntPtr GetCurrentWindowHandle()
        {
            IntPtr ptrWnd = IntPtr.Zero;
            uint   uiPid  = (uint)Process.GetCurrentProcess().Id; // 当前进程 ID

            Console.WriteLine("当前进程id" + uiPid);
            object objWnd = processWnd[uiPid];

            if (objWnd != null)
            {
                Console.WriteLine("! null");
                ptrWnd = (IntPtr)objWnd;
                if (ptrWnd != IntPtr.Zero && IsWindow(ptrWnd))  // 从缓存中获取句柄
                {
                    return(ptrWnd);
                }
                else
                {
                    Console.WriteLine("再次查询null");
                    ptrWnd = IntPtr.Zero;
                }
            }
            bool bResult = EnumWindows(new WNDENUMPROC(EnumWindowsProc), uiPid);

            // 枚举窗口返回 false 并且没有错误号时表明获取成功
            Console.WriteLine(bResult);
            if (!bResult && Marshal.GetLastWin32Error() == 0)
            {
                objWnd = processWnd[uiPid];
                if (objWnd != null)
                {
                    ptrWnd = (IntPtr)objWnd;
                }
                Mydebug.MyDEBUG("句柄suscess");
            }
            else
            {
                Mydebug.MyDEBUG("句柄error");
            }
            return(ptrWnd);
        }
Example #6
0
        public Form1(string[] args)
        {
            Mydebug.MyDEBUG("=====================Init====================");
            FormClosing += _Quit_Form;
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    Console.WriteLine("接收参数:" + args[i]);
                    Mydebug.MyDEBUG("接收参数:" + args[i]);

                    string[] arg = args[i].Split('=');
                    if (arg.Length == 2)
                    {
                        switch (arg[0].ToLower())
                        {
                        case "winname":
                            if (arg[1] != "")
                            {
                                _myname = arg[1];
                            }
                            break;

                        case "downloadpath":
                            _ossPath = arg[1];
                            break;

                        case "updatepath":
                            _updatePath = arg[1];
                            break;

                        case "exename":
                            _killExeName = arg[1];
                            break;

                        default:
                            Console.WriteLine("!!!" + arg[0]);
                            break;
                        }
                    }
                }
                if (string.IsNullOrEmpty(_ossPath) || string.IsNullOrEmpty(_updatePath) || string.IsNullOrEmpty(_killExeName))
                {
                    string err = string.Format("接收参数有误:下载地址:{0} 更新地址:{1} 目标程序名字:{2}", _ossPath, _updatePath, _killExeName);
                    Mydebug.MyDEBUG(err);
                    return;
                }
                _downloadPath = _rootPath;
                _uzipPath     = _rootPath;
                _startSucess  = true;
                InitializeComponent();
                this.Text           = _myname;
                Startbutton.Visible = true;
            }
            else
            {
                Mydebug.MyDEBUG("=====================Init====没有接收参数======Exit==========");
                Console.WriteLine("没有接收参数");
                System.Environment.Exit(0);
            }
        }
Example #7
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();
                }
            }
        }
Example #8
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);
            }
        }