Exemplo n.º 1
0
        /// <summary>
        /// 更新全部mod
        /// </summary>
        private async void UpdateAllModButton_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                Global.ServerModsDirWatcherIsEnable = false;
                var tempPath = Environment.CurrentDirectory + @"\Temp\";
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }
                Directory.CreateDirectory(tempPath);
                foreach (var mod in _mods.ModList)
                {
                    var dialogWindow = new DialogWindow(mod.Name + "下载中")
                    {
                        Owner = Application.Current.MainWindow
                    };
                    dialogWindow.InitializeComponent();
                    MainGrid.IsEnabled  = false;
                    dialogWindow.Width  = 450;
                    dialogWindow.Height = 350;
                    dialogWindow.DialogWindowCanvas.Width  = 430;
                    dialogWindow.DialogWindowCanvas.Height = 340;
                    dialogWindow.Show();
                    await Task.Run(() =>
                    {
                        try
                        {
                            // 下载
                            var modId             = mod.ModDirName.Replace("workshop-", "");
                            var modDownloadObject = ModDownloadHelper.DownloadModFromId(modId);
                            ModDownloadHelper.DownloadModFile(modDownloadObject);
                            // 解压
                            ZipFile.ExtractToDirectory(@".\Temp\ModUpdate\workshop-" + modId + ".zip",
                                                       CommonPath.ServerModsDirPath + "\\" + mod.ModDirName + ".tmp");
                            if (Directory.Exists(CommonPath.ServerModsDirPath + "\\" + mod.ModDirName))
                            {
                                Directory.Delete(CommonPath.ServerModsDirPath + "\\" + mod.ModDirName, true);
                            }
                            new FileInfo(CommonPath.ServerModsDirPath + "\\" + mod.ModDirName + ".tmp").MoveTo(CommonPath.ServerModsDirPath + "\\" + mod.ModDirName);
                        }
                        catch
                        {
                            // ignored
                        }
                    });

                    MainGrid.IsEnabled = true;
                    dialogWindow.Close();
                }
                RefreshModButton_OnClick(null, null);
                Global.ServerModsDirWatcherIsEnable = true;
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.ToString());
            }
        }
        /// <summary>
        /// 面板初始化
        /// </summary>
        private async void PanelInitalize()
        {
            // 隐藏所有面板
            PanelVisibility("Null");
            #region 设置PathCommon类数据
            // 服务器版本[Steam/WeGame]
            GamePlatformSelectBox.TextList = new List <string> {
                "Steam", "WeGame"
            };
            // 检查通用设置
            CheckCommonSetting();
            #endregion
            #region BaseSet初始化
            BaseSetGameModeSelectBox.TextList = new List <string> {
                "生存", "荒野", "无尽"
            };
            BaseSetPvpSelectBox.TextList = new List <string> {
                "关闭", "开启"
            };
            var maxPlayer = new List <string>();
            for (var i = 1; i <= 64; i++)
            {
                maxPlayer.Add(i.ToString());
            }
            BaseSetMaxPlayerSelectBox.TextList = maxPlayer;
            BaseSetOfflineSelectBox.TextList   = new List <string> {
                "在线", "离线"
            };
            BaseSetIsPauseSelectBox.TextList = new List <string> {
                "关闭", "开启"
            };;
            EditWorldIsCaveSelectBox.TextList = new List <string> {
                "关闭", "开启"
            };;
            #endregion
            #region Mod初始化
            // 此时的mod没有被current覆盖
            _mods = null;
            if (!string.IsNullOrEmpty(CommonPath.ServerModsDirPath))
            {
                var dialogWindow = new DialogWindow("mod加载中")
                {
                    Owner = Application.Current.MainWindow
                };
                dialogWindow.InitializeComponent();
                MainGrid.IsEnabled = false;
                dialogWindow.Show();
                _mods = await Task.Run(() => new Mods());

                MainGrid.IsEnabled = true;
                dialogWindow.Close();
            }
            #endregion
            // 初始化
            InitServer();
            // 显示通用设置面板
            PanelVisibility("CommonSetting");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 刷新mod列表[重新读取mods文件夹和modoverrides.lua]
        /// </summary>
        private async void RefreshModButton_OnClick(object sender, RoutedEventArgs e)
        {
            var dialogWindow = new DialogWindow("mod加载中")
            {
                Owner = Application.Current.MainWindow
            };

            dialogWindow.InitializeComponent();
            MainGrid.IsEnabled = false;
            dialogWindow.Show();
            _mods = null;
            if (!string.IsNullOrEmpty(CommonPath.ServerModsDirPath))
            {
                _mods = await Task.Run(() => new Mods());
            }
            SetModSet();
            MainGrid.IsEnabled = true;
            dialogWindow.Close();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 从创意工坊添加mod
        /// </summary>
        private async void AddModButton_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                Global.ServerModsDirWatcherIsEnable = false;
                var tempPath = Environment.CurrentDirectory + @"\Temp\";
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }
                Directory.CreateDirectory(tempPath);

                var dialogWindowWithButton = new DialogWindowWithButton("请输入mod ID", DialogWindowWithButton.DialogButtons.OKCancel);
                dialogWindowWithButton.InitializeComponent();
                dialogWindowWithButton.OKbuttonEvent += Sender =>
                {
                    var modIdString = Sender.InputTextBox.Text;
                    if (modIdString.Length >= 9 && modIdString.Length <= 10)
                    {
                        double.TryParse(modIdString, out var modId);
                        Sender.Result = modId;
                    }
                    else
                    {
                        Sender.Result = (double)0;
                    }
                };
                dialogWindowWithButton.ShowDialog();
                var modIdFromResult = (double)dialogWindowWithButton.Result;
                if (modIdFromResult == 0)
                {
                    Debug.WriteLine("无效的mod ID");
                    return;
                }
                var modDirName = CommonPath.ServerModsDirPath + "\\workshop-" + modIdFromResult;

                var dialogWindow = new DialogWindow(modIdFromResult + "下载中")
                {
                    Owner = Application.Current.MainWindow
                };
                dialogWindow.InitializeComponent();
                MainGrid.IsEnabled  = false;
                dialogWindow.Width  = 450;
                dialogWindow.Height = 350;
                dialogWindow.DialogWindowCanvas.Width  = 430;
                dialogWindow.DialogWindowCanvas.Height = 340;
                dialogWindow.Show();
                await Task.Run(() =>
                {
                    try
                    {
                        // 下载
                        var modDownloadObject = ModDownloadHelper.DownloadModFromId(modIdFromResult.ToString(CultureInfo.InvariantCulture));
                        ModDownloadHelper.DownloadModFile(modDownloadObject);
                        // 解压
                        ZipFile.ExtractToDirectory(@".\Temp\ModUpdate\workshop-" + modIdFromResult + ".zip",
                                                   modDirName + ".tmp");
                        if (Directory.Exists(modDirName))
                        {
                            Directory.Delete(modDirName, true);
                        }
                        new FileInfo(modDirName + ".tmp").MoveTo(modDirName);
                    }
                    catch
                    {
                        // ignored
                    }
                });

                MainGrid.IsEnabled = true;
                dialogWindow.Close();
                RefreshModButton_OnClick(null, null);
                Global.ServerModsDirWatcherIsEnable = true;
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.ToString());
            }
        }