示例#1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string[] arrSv = File.ReadAllLines(Path.Combine(Application.StartupPath, "ftpServer.txt"));
            if (arrSv.Length < 3)
            {
                MessageBox.Show("Lỗi file ftpServer.txt. Hãy kiểm tra lại! ");
            }

            DocUtils.InitFTPQLSX(arrSv[0].Trim(), arrSv[1].Trim(), arrSv[2].Trim());
            string[] lines            = File.ReadAllLines(_pathFileConfigUpdate);
            string[] stringSeparators = new string[] { "||" };
            string[] arr = lines[1].Split(stringSeparators, 4, StringSplitOptions.RemoveEmptyEntries);
            _appName          = arr[0].Trim();
            _pathFolderUpdate = Path.Combine(Application.StartupPath, arr[1].Trim());
            _pathUpdateServer = arr[2].Trim();
            _pathFileVersion  = Path.Combine(Application.StartupPath, arr[3].Trim());
            if (backgroundWorker1.IsBusy)
            {
                backgroundWorker1.CancelAsync();
            }
            else
            {
                //Tắt các ứng dụng RTC
                try
                {
                    TurnOffApp(_appName);
                    backgroundWorker1.RunWorkerAsync();
                }
                catch (Exception ex)
                {
                    Application.Exit();
                }
            }
        }
示例#2
0
        void updateVersion(string PathFileVersion)
        {
            try
            {
                string[]      listFileSv = DocUtils.GetFilesList(@_pathUpdateServer);
                List <string> lst        = listFileSv.ToList();
                lst = lst.Where(o => o.Contains(".zip")).ToList();
                int    newVersion = lst.Max(o => TextUtils.ToInt(Path.GetFileNameWithoutExtension(o)));
                string fileName   = newVersion + ".zip";

                if (File.Exists(Path.Combine(_pathFolderUpdate, fileName)))
                {
                    File.Delete(Path.Combine(_pathFolderUpdate, fileName));
                }
                DocUtils.DownloadFile(_pathFolderUpdate, fileName, Path.Combine(_pathUpdateServer, fileName));
                if (File.Exists(Path.Combine(_pathFolderUpdate, fileName)))
                {
                    if (!_extractPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
                    {
                        _extractPath += Path.DirectorySeparatorChar;
                    }
                    using (ZipArchive archive = ZipFile.OpenRead(Path.Combine(_pathFolderUpdate, fileName)))
                    {
                        foreach (ZipArchiveEntry entry in archive.Entries)
                        {
                            try
                            {
                                string destinationPath = Path.GetFullPath(Path.Combine(_extractPath, entry.FullName));
                                if (destinationPath.StartsWith(_extractPath, StringComparison.Ordinal))
                                {
                                    entry.ExtractToFile(destinationPath, true);
                                }
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show(e.ToString());
                                _isErrorExtract = true;
                                break;
                            }
                        }
                        if (!_isErrorExtract)
                        {
                            File.WriteAllText(PathFileVersion, TextUtils.ToString(newVersion));
                        }
                    }
                }
            }
            catch (Exception ex) {
            }
        }