private async void ToggleAddonEnabledCommand_Invoke(object sender, ExecutedRoutedEventArgs e)
        {
            var  holder  = e.Parameter as VpkHolder;
            bool enabled = !holder.IsEnabled;

            holder.IsEnabled = enabled;
            await Task.Run(() => addonsList.ToggleAddonEnabledStateAndWriteBack(holder.FileDispName, enabled));

            if (haventToggleEnabled)
            {
                var procL4d2 = ProcessQuitWaiter.GetRunningProcessOfPath(Path.Combine(gameDir, CommonConsts.L4d2ExeFileName));
                if (procL4d2 != null)
                {
                    procL4d2.Dispose();
                    MessageBox.Show("检测到L4D2正在运行。\n要使本软件中启用或禁用的操作" +
                                    "立即生效,您【不需要】重新启动游戏,但是需要以下额外操作:\n" +
                                    "1. 回到游戏主界面;\n" +
                                    "2. 点击“附加内容”选项,有两个的话应该是第一个,也可能显示Addons;\n" +
                                    "3. 如果有弹窗,点击“确定”;\n" +
                                    "4. 点击“完成”。", "需要额外操作");
                    haventToggleEnabled = false;
                }
            }
        }
Example #2
0
        public override void Do()
        {
            Action <VpkHolder, AutoRenameConfig> func;

            switch (cfg.Direction)
            {
            case AutoRenameConfig.RenameDirection.InternalToFile:
                func = DoRename_InternalNameToFileName;
                break;

            case AutoRenameConfig.RenameDirection.FileToInternal:
                MessageBox.Show("暂不支持。", "一个Boomer在你面前爆炸了");
                return;

            //func = DoRename_FileNameToInternalName;
            //break;
            default: return;
            }
            foreach (var item in list)
            {
retry:
                bool cancel;
                mutex.WaitOne();
                cancel = isCancelled;
                if (!cancel)
                {
                    bool gameNotRunning = true;
                    Application.Current.Dispatcher.Invoke(()
                                                          => gameNotRunning = ProcessQuitWaiter.WaitForProcessQuit(
                                                              Path.Combine(gameDir, CommonConsts.L4d2ExeFileName),
                                                              "正在等待Left 4 Dead 2退出。游戏运行期间进行此操作可能导致问题。" +
                                                              "当您结束游戏并退出时,此操作会自动继续。"));
                    if (!gameNotRunning)
                    {
                        cancel      = true;
                        isCancelled = true;
                    }
                }
                mutex.ReleaseMutex();
                if (cancel)
                {
                    break;
                }
                try {
                    func(item, cfg);
                } catch (Exception e) {
                    Debug.WriteLine(e);
                    mutex.WaitOne();
                    var resFail = ItemFailureDialog.Result.Abort;
                    if (isCancelled)
                    {
                        cancel = true;
                    }
                    else
                    {
                        Application.Current.Dispatcher.Invoke(() => {
                            var diaFail = new ItemFailureDialog(string.Format(
                                                                    "对附加组件{0}的操作失败了,这可能因为文件被其他程序占用" +
                                                                    "(游戏本身或GCFScape等)、文件损坏" +
                                                                    "或本应用程序存在的问题。您可以尝试排除问题,然后重试。", "xxx"));
                            bool?resBoolFail = diaFail.ShowDialog();
                            if (resBoolFail != true)
                            {
                                resFail = ItemFailureDialog.Result.Abort;
                            }
                            else
                            {
                                resFail = diaFail.GetResult();
                            }
                        });
                        if (resFail == ItemFailureDialog.Result.Abort)
                        {
                            cancel      = true;
                            isCancelled = true;
                        }
                    }
                    mutex.ReleaseMutex();
                    if (cancel || isCancelled)
                    {
                        break;
                    }
                    if (resFail == ItemFailureDialog.Result.Retry)
                    {
                        goto retry;
                    }
                }
                Application.Current.Dispatcher.Invoke(() => CurrentProgress++);
            }
            listTxt?.SaveToFile();
        }