Exemplo n.º 1
0
 public static void DeleteInstance(Instance instance)
 {
     PluginAPI.PluginManager.onRemoveInstance(instance);
     if (Directory.Exists(instance.Path))
         Directory.Delete(instance.Path,true);
     instances.Remove(instance);
 }
Exemplo n.º 2
0
 public ModSelector(Instance i)
 {
     InitializeComponent();
     this.instance = i;
     this.tabControl.SelectedIndex = 0;
     UpdateList();
 }
Exemplo n.º 3
0
        public static void LoadInstances()
        {
            if (File.Exists(InstanceFile))
            {
                string data = File.ReadAllText(InstanceFile);
                JObject obj = JObject.Parse(data);
                foreach (JObject obj2 in obj["instances"].Children<JObject>())
                {
                    Instance i = new Instance(obj2["name"].ToString());
                    i.Description = obj2["desc"].ToString();
                    i.Version = VersionManager.versions.Find(ver => obj2["version"].ToString() == ver.Key);
                    instances.Add(i);
                }
            }

            string[] dirs = Directory.GetDirectories(PathData.InstancesPath);
            foreach (string s in dirs)
            {
                Instance i = instances.Find(In => In.Path == s);
                if (i == null)
                {
                    Instance newI = new Instance(Path.GetFileName(s));
                    instances.Add(newI);
                }
            }

            App.InvokeAction(delegate
            {
                App.mainWindow.UpdateInstances();
            });
        }
Exemplo n.º 4
0
 public static void SyncOptions(Instance i)
 {
     if ((bool)SettingsManager.GetSetting("Sync options").data)
     {
         try
         {
             App.Log("Syncing options from " + i.Name);
             string path = i.MinecraftDirPath + "\\options.txt";
             foreach (Instance instance in InstanceManager.instances)
             {
                 if (instance != i)
                 {
                     App.Log("Options synced to: " + instance.Name);
                     string opath = instance.MinecraftDirPath + "\\options.txt";
                     File.Copy(path, opath, true);
                     if (File.Exists(i.MinecraftDirPath + "\\optionsof.txt"))
                     {
                         File.Copy(i.MinecraftDirPath + "\\optionsof.txt", instance.MinecraftDirPath + "\\optionsof.txt", true);
                     }
                 }
             }
             App.Log("Options synced!");
         }
         catch
         {
             App.Log("Options could not be synced!");
         }
     }
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
 public static void SyncServerlist(Instance i)
 {
     if ((bool)SettingsManager.GetSetting("Sync serverlists").data)
     {
         App.Log("Syncing serverlist from: " + i.Name);
         string path = i.MinecraftDirPath + "\\servers.dat";
         if (File.Exists(path))
         {
             foreach (Instance instance in InstanceManager.instances)
             {
                 if (instance != i)
                 {
                     App.Log("Serverlist synced to: " + instance.Name);
                     string ipath = instance.MinecraftDirPath + "\\servers.dat";
                     File.Copy(path, ipath, true);
                 }
             }
         }
         App.Log("Serverlists synced!");
     }
 }
Exemplo n.º 7
0
        public TreeViewItem treeItem(Instance i)
        {
            TreeViewItem item = new TreeViewItem();
            item.Header = "Mods";
            item.MouseUp += onClick_root;

            ContextMenu cmr = new ContextMenu();
            MenuItem mi_deleteAll = new MenuItem();
            mi_deleteAll.Header = "Remove all mods";
            mi_deleteAll.Click += delegate
            {
                throw new NotImplementedException();
            };
            cmr.Items.Add(mi_deleteAll);
            item.ContextMenu = cmr;
            List<Mod> mods = Main.GetModList(i);
            foreach (Mod mod in mods)
            {
                TreeViewItem modItem = new TreeViewItem();
                modItem.Header = mod.name;
                modItem.Tag = mod;

                ContextMenu cm = new ContextMenu();
                MenuItem item_delete = new MenuItem();
                item_delete.Header = "Delete";
                item_delete.Click += delegate
                {
                    TinyMinecraftVersion version = i.Version;
                    Mod.DeleteMod(mod, i);
                    mods.Remove(mod);
                    MCM.App.InvokeAction(delegate { MCM.App.mainWindow.UpdateInstances(); });
                };
                cm.Items.Add(item_delete);
                modItem.ContextMenu = cm;
                item.Items.Add(modItem);
            }
            return item;
        }
Exemplo n.º 8
0
 public static List<Mod> GetModList(Instance i)
 {
     List<Mod> mods = new List<Mod>();
     if (i.metaData != null)
     {
         foreach (object obj in i.metaData)
         {
             if (obj.GetType() == typeof(List<Mod>))
             {
                 mods = (obj as List<Mod>);
                 break;
             }
         }
     }
     return mods;
 }
Exemplo n.º 9
0
 public static void AddModToInstance(Instance i, Mod mod)
 {
     GetModList(i).Add(mod);
 }
Exemplo n.º 10
0
        private void Button_aInstance(object sender, RoutedEventArgs e)
        {
            StringPrompt sp = new StringPrompt("New Instance", "Name:");
            if (sp.ShowDialog() == true)
            {
                Instance i = new Instance(sp.theString);
                InstanceManager.instances.Add(i);

                UpdateInstances();
            }
        }
Exemplo n.º 11
0
 static void dummyA(Instance instance, MinecraftUser user)
 {
 }
Exemplo n.º 12
0
 internal static void RenameInstance(Instance instance, string p)
 {
     PluginAPI.PluginManager.onRenameInstance(instance);
     Directory.Move(instance.Path, PathData.InstancesPath + "\\" + p);
     instance.Name = p;
 }
Exemplo n.º 13
0
 static void dummyB(Instance instance)
 {
 }
Exemplo n.º 14
0
 public static string GetModsPath(Instance i)
 {
     return i.MinecraftDirPath + "\\mods";
 }
Exemplo n.º 15
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;
        }
Exemplo n.º 16
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);
 }
Exemplo n.º 17
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;
     }
 }
Exemplo n.º 18
0
 private void onCreateInstance(Instance instance)
 {
     Directory.CreateDirectory(GetModsPath(instance));
     Directory.CreateDirectory(GetCoreModsPath(instance));
 }
Exemplo n.º 19
0
 public static void InstallDirMod(Mod mod, Instance i)
 {
     string targetDir = GetTargetDir(mod, i);
     CopyDir.Copy(mod.path, targetDir);
 }
Exemplo n.º 20
0
        internal static void StartMinecraft(Instance instance)
        {
            try
            {
                if (instance.Version == null)
                {
                    App.InvokeAction(delegate { MCM.Utils.MessageBox.ShowDialog("Error", "Version not set in instance!"); });
                    return;
                }
                App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = false; });
                App.Log("Waiting for downloads to finish...");
                DownloadManager.WaitForAllMCRequire();
                App.Log("Downloads should be finished!");
                Process p = new Process();
                string java = SettingsManager.GetSetting("javapath").data.ToString();
                p.StartInfo.FileName = java;
                MinecraftUser user = null;
                MinecraftData.AppdataPath = instance.Version.FullVersion.LocalPath;
                App.InvokeAction(delegate {
                    user = mainWindow.GetSelectedUser();
                });
                if (!File.Exists(instance.MinecraftJarFilePath))
                {
                    throw new Exception("No version selected");
                }
                DownloadPackage dp = new DownloadPackage("Libraries", true);
                dp.ShouldContinue = true;
                instance.Version.FullVersion.Libraries.ForEach(l => { if (!File.Exists(l.Extractpath)) { l.ScheduleExtract(dp); } });
                if(dp.getDownloads().Count > 0)
                    DownloadManager.ScheduleDownload(dp);

                App.Log("Waiting for minecraft download...");
                DownloadManager.WaitForAllMCRequire();
                p.StartInfo.Arguments = instance.GetStartArguments(user.username, user.password);
                App.Log("Starting Minecraft with arguments: " + p.StartInfo.FileName + " " + p.StartInfo.Arguments);
                p.StartInfo.UseShellExecute = false;
                p.EnableRaisingEvents = true;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.OutputDataReceived += (s, e) =>
                {
                    App.LogMinecraft(e.Data);
                };
                p.ErrorDataReceived += (s, e) =>
                {
                    // No prefix since everything minecraft outputs seems to be an error
                    App.LogMinecraft(e.Data);
                };
                p.Exited += (s, e) =>
                {
                    App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = true; });
                    Thread.Sleep(200);
                    Syncronizer.SyncOptions(instance);
                    Syncronizer.SyncServerlist(instance);
                    PluginManager.onCloseMinecraft(instance,user);
                };
                PluginManager.onStartMinecraft(instance, user);
                p.Start();
                p.BeginErrorReadLine();
                p.BeginOutputReadLine();
            }
            catch (Exception ex)
            {
                App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = true; });
                App.Log("An error occured while starting minecraft: " + ex.ToString());
            }
        }
Exemplo n.º 21
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);
        }