Exemplo n.º 1
0
        public static void TipToUpdateResource(this DEModManager self, DEModResource resource)
        {
            var ofd = new System.Windows.Forms.OpenFileDialog();

            ofd.InitialDirectory = _preOpenModDirectory ?? DOOMEternal.ModPacksDirectory;
            ofd.Title            = $"替换{resource.Path}";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                self.UpdateResource(resource, ofd.FileName);
            }
        }
Exemplo n.º 2
0
        public DEModResource UpdateResource(DEModResource resource, string resourcePath)
        {
            string oldResourceName = resource.Path;
            string newResourceFile = resourcePath;
            string newResourceName = Path.GetFileName(newResourceFile);

            // 如果新旧模组名同名,直接替换文件即可
            if (oldResourceName == newResourceName)
            {
                RemoveModResourceFileBackup(oldResourceName);
                BackupModResourceFile(newResourceFile);
            }
            else
            {
                // 否则逐一对模组配置中的相关文件进行修改
                BackupModResourceFile(newResourceFile);
                var newResource = new DEModResource(newResourceName);
                foreach (var modPack in ModPacks)
                {
                    // 如果模组列表中已有该模组,则将旧模组移除即可
                    if (modPack.ContainsResource(newResource))
                    {
                        for (int i = 0; i < modPack.Resources.Count; i++)
                        {
                            if (modPack.Resources[i].Path == oldResourceName)
                            {
                                modPack.RemoveResource(modPack.Resources[i]);
                                --i;
                            }
                        }
                    }
                    // 否则将所有旧模组名替换为新模组名即可
                    else
                    {
                        foreach (var res in modPack.Resources)
                        {
                            if (res.Path == oldResourceName)
                            {
                                res.Path = newResourceName;
                            }
                        }
                    }
                }
                OnPropertyChanged(nameof(UsedModResources));
            }
            return(resource);
        }
Exemplo n.º 3
0
 public static void TipToOpenResourceFile(DEModResource resource)
 {
     try {
         var    p        = new Process();
         string filePath = $@"{DOOMEternal.ModPacksDirectory}\{resource.Path}";
         if (!File.Exists(filePath))
         {
             throw new FileNotFoundException($"无法找到文件:{filePath}");
         }
         p.StartInfo.FileName  = "explorer.exe";
         p.StartInfo.Arguments = $@"/select, {DOOMEternal.ModPacksDirectory}\{resource.Path}";
         p.Start();
     }
     catch (Exception exp) {
         MessageBox.Show(exp.Message, "打开错误", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemplo n.º 4
0
        private DEModResource AddResourceHelper(string resourcePath)
        {
            if (DOOMEternal.GameDirectory == null)
            {
                throw new ArgumentException("请先选择游戏文件夹");
            }
            string resourceName  = Path.GetFileName(resourcePath);
            string modPackBackup = $@"{DOOMEternal.ModPacksDirectory}\{resourceName}";

            if (!File.Exists(modPackBackup))
            {
                File.Copy(resourcePath, modPackBackup);
            }
            if (CheckIfContainsResource(resourceName))
            {
                throw new ArgumentException($"模组包[{resourceName}]已添加,不可重复添加");
            }
            var t = new DEModResource(resourceName);

            Resources.Add(t);
            return(t);
        }
Exemplo n.º 5
0
        public DEModResource InsertResource(int index, string resourcePath)
        {
            if (DOOMEternal.GameDirectory == null)
            {
                throw new ArgumentException("请先选择游戏文件夹");
            }
            string resourceName  = Path.GetFileName(resourcePath);
            string modPackBackup = $@"{DOOMEternal.ModPacksDirectory}\{resourceName}";

            if (!File.Exists(modPackBackup))
            {
                File.Copy(resourcePath, modPackBackup);
            }
            if (CheckIfContainsResource(resourceName))
            {
                throw new ArgumentException($"模组包[{resourceName}]已添加,不可重复添加");
            }
            var res = new DEModResource(resourceName);

            Resources.Insert(index, res);
            DOOMEternal.ModificationSaved = false;
            return(res);
        }
Exemplo n.º 6
0
 public bool ContainsResource(DEModResource resource)
 {
     return(CheckIfContainsResource(resource.Path));
 }
Exemplo n.º 7
0
 public DEModResource ResortResource(int index, DEModResource source)
 {
     Resources.ReInsert(index, source);
     DOOMEternal.ModificationSaved = false;
     return(source);
 }
Exemplo n.º 8
0
 public DEModResource RemoveResource(DEModResource resource)
 {
     Resources.Remove(resource);
     DOOMEternal.ModificationSaved = false;
     return(resource);
 }