コード例 #1
0
        /// <summary>
        /// Deletes a mod.
        /// </summary>
        public async void Delete(Mod m)
        {
            string modPath   = Mod.InstallPath + m.Slug;
            string imagePath = Mod.ImagePath + m.Thumbnail;

            if (InstalledMods.Where(x => x.Slug == m.Slug).Count() != 0)
            {
                await Uninstall(SelectedMod);
            }
            AvailableMods.Remove(m);
            UpdateSettings();
            if (Directory.Exists(modPath))
            {
                Directory.Delete(modPath, true);
            }
            if (File.Exists(m.Thumbnail))
            {
                File.Delete(m.Thumbnail);
            }
        }
コード例 #2
0
        /// <summary>
        /// Installs a mod into the game.
        /// </summary>
        public async Task <bool> Install(Mod m)
        {
            string mPath       = Mod.InstallPath + m.Slug;
            string mBackupPath = Mod.BackupPath + m.Slug;

            if (!Directory.Exists(mBackupPath))
            {
                Directory.CreateDirectory(mBackupPath);
            }
            Console.WriteLine("Install Mod");
            // Before installing get the list of affected ice files and make sure no installed
            // mod uses the same files
            if (!ModCollision(m))
            {
                m.ContentsMD5 = new Dictionary <string, string>();
                foreach (var f in Directory.GetFiles(mPath))
                {
                    var    fileName = Path.GetFileName(f);
                    string from     = mPath + "\\" + fileName;
                    string destin   = settings.PSO2Dir + "\\" + fileName;
                    string backup   = mBackupPath + "\\" + fileName;

                    if (!File.Exists(from))
                    {
                        MessageBox.Show("Mod file(s) are not found. please reinstall mod.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return(false);
                    }
                    if (!File.Exists(destin))
                    {
                        // backup target no match
                        continue;
                    }
                    //Console.WriteLine ("Backup FROM: " + settings.PSO2Dir + "\\" + fileName + "  TO: " + mBackupPath + "\\" + fileName);
                    //Console.WriteLine ("Replace FROM: " + mPath + "\\" + fileName + "  TO: " + settings.PSO2Dir + "\\" + fileName);

                    if (!Mod.modSettingsFiles.Contains(fileName))
                    {
                        var BackupTask   = new Helpers.FileCopy(destin, backup);
                        var ApplyModTask = new Helpers.FileCopy(from, destin);

                        // This is done here because some mods will have dynamic/setup content so we create
                        // the md5 hash over the file we copy on the pso2 dir
                        m.ContentsMD5.Add(fileName, Helpers.CheckMD5(destin));

                        Console.WriteLine("Backup Task");
                        await Task.Run(() => BackupTask.StartCopy());

                        Console.WriteLine("Apply Mod Task");
                        await Task.Run(() => ApplyModTask.StartCopy());
                    }
                }
                InstalledMods.Add(m);
                AvailableMods.Remove(m);
                UpdateSettings();
            }
            else
            {
                MessageBox.Show("Another installed mod is using the same files this mod will try to overwrite. Installation cancelled",
                                "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            return(true);
        }