示例#1
0
 private void addItem(Mod mod,bool inBackuppedList)
 {
     ListBoxItem item = new ListBoxItem();
     item.Content = mod.name;
     item.Tag = mod;
     if (inBackuppedList)
         listBox_backup.Items.Add(item);
     else
         listBox_instance.Items.Add(item);
 }
示例#2
0
 public static void DeleteMod(Mod mod, Instance i)
 {
     string targetDir = GetTargetDir(mod, i);
     if (mod.type == ModType.ZipMod)
         File.Delete(targetDir);
     else if (mod.type == ModType.DirMod)
         Directory.Delete(targetDir, true);
     else
         throw new Exception("Cannot delete jarmod");
     Main.GetModList(i).Remove(mod);
 }
示例#3
0
 public static void AddModToInstance(Instance i, Mod mod)
 {
     GetModList(i).Add(mod);
 }
示例#4
0
        public static void InstallJarMod(Mod mod, Instance i)
        {
            string jarFile = i.MinecraftJarFilePath;
            FileStream stream = new FileStream(jarFile, FileMode.Open);
            ZipArchive arch = new ZipArchive(stream, ZipArchiveMode.Update);

            List<ZipArchiveEntry> markedRemove = new List<ZipArchiveEntry>();
            foreach (ZipArchiveEntry entry in arch.Entries)
            {
                if (entry.FullName.Contains("META-INF"))
                    markedRemove.Add(entry);
            }

            while (markedRemove.Count > 0)
                markedRemove[0].Delete();

            foreach (string filePath in Directory.GetFiles(mod.path, "*", SearchOption.AllDirectories))
            {
                ZipArchiveEntry entry =  arch.CreateEntry(filePath.Replace(mod.path, ""));
                using (StreamWriter writer = new StreamWriter(entry.Open()))
                {
                    writer.Write(File.ReadAllBytes(filePath));
                }
            }
            Main.AddModToInstance(i, mod);
        }
示例#5
0
 public static void InstallDirMod(Mod mod, Instance i)
 {
     string targetDir = GetTargetDir(mod, i);
     CopyDir.Copy(mod.path, targetDir);
 }
示例#6
0
        private static string GetTargetDir(Mod mod, Instance i)
        {
            string targetDir;
            if (mod.level == ModLevel.mod)
                targetDir = Main.GetModsPath(i);
            else if (mod.level == ModLevel.coremod)
                targetDir = Main.GetCoreModsPath(i);
            else
                throw new Exception("Dafuq? this isn't possible");

            targetDir = targetDir + "\\" + Path.GetFileName(mod.path);
            return targetDir;
        }
示例#7
0
 public static void InstallZipMod(Mod mod, Instance i)
 {
     string targetDir = GetTargetDir(mod, i);
     try
     {
         File.Copy(mod.path, targetDir);
     }
     catch (IOException e)
     {
         if (!e.Message.Contains("already exists"))
             throw e;
     }
     Main.AddModToInstance(i, mod);
 }
示例#8
0
 public static void InstallMod(Mod mod, Instance i)
 {
     switch (mod.type)
     {
         case ModType.DirMod:
             InstallDirMod(mod, i);
             break;
         case ModType.JarMod:
             InstallJarMod(mod, i);
             break;
         case ModType.ZipMod:
             InstallZipMod(mod, i);
             break;
     }
 }
示例#9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (tb_path.Text != "" && tb_name.Text != "" && comboBox_mcver.SelectedIndex != -1)
            {
                Mod mod = new Mod();
                switch (tabControl_modType.SelectedIndex)
                {
                    case 0:
                        mod.type = Mod.ModType.ZipMod;
                        break;
                    case 1:
                        mod.type = Mod.ModType.DirMod;
                        break;
                    case 2:
                        mod.type = Mod.ModType.JarMod;
                        break;
                }
                mod.name = tb_name.Text;
                mod.level = Mod.ModLevel.mod;
                mod.version = (comboBox_mcver.SelectedItem as ComboBoxItem).Tag as TinyMinecraftVersion;

                string target;
                if (mod.type == Mod.ModType.DirMod)
                {
                    target = Main.DataPath + "\\" + new System.IO.DirectoryInfo(tb_path.Text).Name;
                    MCM.Utils.CopyDirectory.Copy(tb_path.Text, target);
                }
                else
                {
                    target = Main.DataPath + "\\" + System.IO.Path.GetFileName(tb_path.Text);
                    System.IO.File.Copy(tb_path.Text, target);
                }
                mod.path = target;
                Main.BackuppedMods.Add(mod);
                this.Close();
            }
        }