private void CopyFiles(object sender, EventArgs e)
 {
     fileutils.copyFolder(fileutils.path, fileutils.target);
     foreach (string soft in selectSoft)
     {
         if (soft.Contains(".exe"))
         {
             System.IO.File.Copy(fileutils.path + @"\softs\" + soft, fileutils.target.Split('\\')[0] + '\\' + soft);
         }
         else
         {
             fileutils.copyFolder(fileutils.path + @"\softs\" + soft, fileutils.target.Split('\\')[0] + '\\' + soft);
         }
     }
     this.Close();
 }
Esempio n. 2
0
        //main process
        public MainWindow()
        {
            //ProgramManager initialize
            InitializeComponent();
            ((INotifyCollectionChanged)lv_uninstalled.Items).CollectionChanged  += uninstalled_CollectionChanged;
            ((INotifyCollectionChanged)lv_dellnk.Items).CollectionChanged       += dellnk_CollectionChanged;
            ((INotifyCollectionChanged)lv_delstartmenu.Items).CollectionChanged += delstartmenu_CollectionChanged;

            //background process initialize
            m_BackgroundWorker = new BackgroundWorker();          // 实例化后台对象
            m_BackgroundWorker.WorkerReportsProgress      = true; // 设置可以通告进度
            m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消
            m_BackgroundWorker.DoWork             += new DoWorkEventHandler(DoWork);
            m_BackgroundWorker.ProgressChanged    += new ProgressChangedEventHandler(UpdateProgress);
            m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);

            //ConsoleManager initialize
            ConsoleManager.Toggle();

            //ProgramManager initialize
            //ShortcutManager() must init before programManager()
            shortcutManager();
            programManager();


            //config store initialize
            tb_ip.Text = cfg.tb_ip;

            /*TreeViewItem item = (TreeViewItem)treeview_IP.SelectedItem;
             * IPDISTRIBUTION device=(IPDISTRIBUTION) item.Tag;
             * tb_ip.Text = device.ip;*/
            tb_gateway.Text               = cfg.tb_gateway;
            cb_waken.IsChecked            = cfg.cb_waken;
            cb_firewall.IsChecked         = cfg.cb_firewall;
            cb_ip.IsChecked               = cfg.cb_ip;
            cb_gateway.IsChecked          = cfg.cb_gateway;
            cb_swsoft_startup.IsChecked   = cfg.cb_swsoft_startup;
            cb_swsoft_privilege.IsChecked = cfg.cb_swsoft_privilege;
            cb_vnc.IsChecked              = cfg.cb_vnc;
            cb_klite.IsChecked            = cfg.cb_klite;
            cb_office.IsChecked           = cfg.cb_office;
            cb_power.IsChecked            = cfg.cb_power;
            cb_zoom.IsChecked             = cfg.cb_zoom;

            //flashdisk relate initialize
            //total path of self;
            string path = System.Reflection.Assembly.GetEntryAssembly().Location;

            string[] array       = path.Split(new[] { @"\" }, StringSplitOptions.None);
            string   name        = array.Last();
            string   folder      = path.Replace(name, "");
            string   currentdisk = array[0];

            currentdisk = Regex.Match(currentdisk, @"\w").Groups[0].Value;
            DriveInfo[] allDrives = DriveInfo.GetDrives();
            foreach (DriveInfo d in allDrives)
            {
                string disk = Regex.Match(d.Name, @"\w").Groups[0].Value;
                if (disk == currentdisk)
                {
                    if (d.DriveType.ToString() == "Removable")
                    {
                        //Copy file prompt
                        Prompt prompt = new Prompt(fileutils);
                        prompt.ShowDialog();
                        //System.Windows.Forms.MessageBox.Show("本软件目前运行与U盘,是否复制到" + fileutils.target + ",并打开文件夹?");
                        if (System.Windows.Forms.MessageBox.Show("Yes or no", "本软件目前运行与U盘,是否复制到" + fileutils.target + ",并打开文件夹?",
                                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                                                 MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                        {
                            fileutils.copyFolder(folder, fileutils.target);
                        }    // opens the folder in explorer
                        System.Diagnostics.Process.Start(fileutils.target);
                        System.Environment.Exit(1);
                    }
                    else
                    {
                        string drive = System.IO.Path.GetPathRoot(fileutils.path);
                        if (System.Windows.Forms.MessageBox.Show("Yes or no", "复制\"开关机软件\"/\"中控客户端\"到" + drive,
                                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                                                 MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                        {
                            fileutils.copyFolder(fileutils.path + @"\softs", drive);
                        }
                    }
                }
                if (d.DriveType.ToString() == "Removable")
                {
                    flashdisk = d;
                    string   keyword = "*IP分配*.txt";
                    string[] files   = fileutils.searchFile(flashdisk.Name + @"部署工具", keyword);
                    string   file    = files.OrderByDescending(pathx => File.GetLastWriteTime(pathx)).FirstOrDefault();
                    tb_ipfile.Text = file;
                    tb_save.Text   = tb_ipfile.Text;
                    IPDistribution();
                }
            }
        }
Esempio n. 3
0
        void DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = sender as BackgroundWorker;

            bw.ReportProgress(10, null);
            Console.WriteLine("文件复制中,请耐心等待...");
            UnSelectItems = ItemsSource.Where(x => x.Checked == false).Select(x => x.Name).ToList();
            IEnumerable <string> FilterDirs  = fileutils.FilterFolder(fileutils.path + @"\softs", UnSelectItems);
            IEnumerable <string> FilterFiles = fileutils.GetFiles(fileutils.path + @"\softs", UnSelectItems, SearchOption.TopDirectoryOnly);

            foreach (string item in FilterFiles)
            {
                _busy.WaitOne();
                String ItemName       = item.Split('\\').Last();
                String FullPath       = fileutils.target + ItemName;
                String DestinationDir = FullPath.Split(new string[] { ".zip" }, StringSplitOptions.None)[0];
                System.IO.File.Copy(item, FullPath, true);
                if (ItemName.Contains(".zip"))
                {
                    try
                    {
                        System.IO.Compression.ZipFile.ExtractToDirectory(FullPath, DestinationDir);
                        DestinationDir = DestinationDir + @"\" + ItemName.Split(new string[] { ".zip" }, StringSplitOptions.None)[0];
                    }
                    catch
                    {
                        Directory.Delete(DestinationDir, true);
                        System.IO.Compression.ZipFile.ExtractToDirectory(FullPath, DestinationDir);
                        DestinationDir = DestinationDir + @"\" + ItemName.Split(new string[] { ".zip" }, StringSplitOptions.None)[0];
                    }
                    if (ItemName.Contains("关机"))
                    {
                        fileutils.ShutdownSoftFolderName = DestinationDir;
                    }
                    else if (ItemName.Contains("客户端"))
                    {
                        fileutils.PlusbeZKFolderName = DestinationDir;
                    }
                    else if (ItemName.IndexOf("Office", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        fileutils.OfficeFolderName = DestinationDir;
                    }
                    else if (ItemName.Contains("zkplay") || ItemName.Contains("客户端2"))
                    {
                        fileutils.ZkplayFolderName = DestinationDir;
                    }
                }
                if (bw.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                bw.ReportProgress(50, null);
                Console.WriteLine(item + "已复制并解压.");
            }
            foreach (string item in FilterDirs)
            {
                _busy.WaitOne();
                String ItemName = item.Split('\\').Last();
                String FullPath = fileutils.target + ItemName;
                fileutils.copyFolder(item, fileutils.target + ItemName);
                if (ItemName.Contains("开关机"))
                {
                    fileutils.ShutdownSoftFolderName = FullPath;
                }
                else if (ItemName.Contains("客户端"))
                {
                    fileutils.PlusbeZKFolderName = FullPath;
                }
                else if (ItemName.IndexOf("Office", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    fileutils.OfficeFolderName = FullPath;
                }
                if (bw.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                bw.ReportProgress(100, null);
                Console.WriteLine(item + "已复制.");
            }
            Save_List(ListFile);
        }