Пример #1
0
        private bool CreateMklinks(string currentFolder, string destFolder, List <string> movingModelDesktopFoldersAndFiles)
        {
            var defaultDektopFolder = GetDefaultDektopFolder();

            //只有桌面转移到其它路径,才添加软链接
            if (currentFolder == defaultDektopFolder)
            {
                var priviousDataFolder = currentFolder.TrimEnd(_folderEndTrimChars);
                var userDefinedFolder  = destFolder.TrimEnd(_folderEndTrimChars);
                foreach (var itemPath in movingModelDesktopFoldersAndFiles)
                {
                    var extension    = Path.GetExtension(itemPath);
                    var partFilePath = itemPath.Replace(priviousDataFolder, string.Empty);
                    var newFilePath  = userDefinedFolder + partFilePath;
                    if (string.IsNullOrWhiteSpace(extension))
                    {
                        var commands = $"mklink /D {itemPath} {newFilePath}";
                        ExecuteCmdHelper.ExecuteCmd(commands);
                    }
                    else if (extension != ".ink")
                    {
                        var commands = $"mklink /H {itemPath} {newFilePath}";
                        ExecuteCmdHelper.ExecuteCmd(commands);
                    }
                }

                return(true);
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// 时间较长,额外处理
        /// </summary>
        private async void ExecuteDelayCommands()
        {
            var cleanDelayedCommands = ToCleanUpManager.GetCleanDelayedCommands();

            foreach (var cleanDelayedCommand in cleanDelayedCommands)
            {
                await Task.Run(() =>
                {
                    ExecuteCmdHelper.ExecuteCmd(cleanDelayedCommand);
                });

                OutputText += $"删除命令{cleanDelayedCommand}\r\n";
            }
        }
Пример #3
0
        /// <summary>
        /// 执行Cmd命令清理缓存
        /// </summary>
        /// <param name="worker"></param>
        private void CacheCacheByCmd(BackgroundWorker worker)
        {
            worker.ReportProgress(0);
            var commands = ToCleanUpManager.GetCleanCacheCommands();

            int index = 0;

            foreach (var command in commands)
            {
                index++;
                var currentOperationError  = string.Empty;
                var currentOperationOutput = string.Empty;
                try
                {
                    var currentOperationDetail = $"执行{command},可能需要几分钟,请等待";
                    worker.ReportProgress(-1,
                                          new ProgressChangedContent()
                    {
                        OperationDetail = currentOperationDetail,
                    });
                    if (command.Contains(@"C:\Windows\Installer\$PatchCache$"))
                    {
                        ExecuteCmdHelper.ExecuteCmd("Net Start msiserver /Y");
                        ExecuteCmdHelper.ExecuteCmd("Net Stop msiserver /Y");
                        ExecuteCmdHelper.ExecuteCmd(@"Reg Add HKLM\Software\Policies\Microsoft\Windows\Installer /v MaxPatchCacheSize /t REG_DWORD /d 0 /f");
                        ExecuteCmdHelper.ExecuteCmd(command);
                        ExecuteCmdHelper.ExecuteCmd("Net Start msiserver /Y");
                        ExecuteCmdHelper.ExecuteCmd("Net Stop msiserver /Y");
                        ExecuteCmdHelper.ExecuteCmd(@"Reg Add HKLM\Software\Policies\Microsoft\Windows\Installer /v MaxPatchCacheSize /t REG_DWORD /d 10 /f");
                        ExecuteCmdHelper.ExecuteCmd("Net Start msiserver /Y");
                    }
                    var executeCmdResult = ExecuteCmdHelper.ExecuteCmd(command);
                    currentOperationOutput += $"命令{command}";
                }
                catch (Exception e)
                {
                    LogHelper.Error(e.Message);
                    currentOperationError = $"{command}执行失败";
                }
                finally
                {
                    worker.ReportProgress(Convert.ToInt32(Convert.ToDouble(index) / Convert.ToDouble(commands.Count)),
                                          new ProgressChangedContent()
                    {
                        OperationOutput = currentOperationOutput,
                        OperationError  = currentOperationError
                    });
                }
            }
        }