public static async Task LaunchGameAsync(FileManager.Modpacks modpack)
        {
            try
            {
                var path     = new MinecraftPath(Directory.GetCurrentDirectory() + $@"\Launcher\{modpack}");
                var launcher = new CMLauncher(path);


                // more options : https://github.com/AlphaBs/CmlLib.Core/wiki/MLaunchOption
                var launchOption = new MLaunchOption
                {
                    MaximumRamMb = Settings.RAM,
                    Session      = SESSION
                };

                forgeVersion = File.ReadAllText($"Launcher/{modpack}/Forge Version.txt");
                var process = await launcher.CreateProcessAsync(forgeVersion, launchOption);

                process.Start();
            }
            catch (Exception)
            {
                main.GetError($"Failed Launching {modpack}!");
            }
        }
        public static void XBoxLogin(FileManager.Modpacks modpack)
        {
            MicrosoftLoginWindow loginWindow = new MicrosoftLoginWindow();
            MSession             session     = loginWindow.ShowLoginDialog();

            if (session != null)
            {
                SESSION = session;
                _       = LaunchGameAsync(modpack);
            }
        }
示例#3
0
 static void GetModpack(FileManager.Modpacks modpack)
 {
     if (File.Exists($"Cache/{modpack.ToString().ToLower()}.zip"))
     {
         File.Delete($"Cache/{modpack.ToString().ToLower()}.zip");
     }
     if (Directory.Exists($"Launcher/{modpack}"))
     {
         Directory.Delete($"Launcher/{modpack}", true);
     }
     DownloadFile(0, modpack);
     FileManager.ModInstall(modpack);
 }
示例#4
0
        private void RefreshTab(FileManager.Modpacks modpack)
        {
            switch (modpack)
            {
            case FileManager.Modpacks.BlockyCrafters:
                FileServer.Connect(0, FileManager.Modpacks.BlockyCrafters);
                FileServer.Connect(1, FileManager.Modpacks.BlockyCrafters);
                BC_CheckModpack();
                break;

            case FileManager.Modpacks.ProjectCenturos:
                FileServer.Connect(0, FileManager.Modpacks.ProjectCenturos);
                FileServer.Connect(1, FileManager.Modpacks.ProjectCenturos);
                PC_CheckModpack();
                break;
            }

            if (FileServer.isConnected)
            {
                Dispatcher.Invoke(() =>
                {
                    switch (modpack)
                    {
                    case FileManager.Modpacks.BlockyCrafters:
                        AvalVerLabel_BC.Content = "Available Version: " + FileServer.info[0];
                        PatchBox_BC.Text        = FileServer.info[1];
                        break;

                    case FileManager.Modpacks.ProjectCenturos:
                        AvalVerLabel_PC.Content = "Available Version: " + FileServer.info[0];
                        PatchBox_PC.Text        = FileServer.info[1];
                        break;
                    }
                });
            }
            else
            {
                switch (modpack)
                {
                case FileManager.Modpacks.BlockyCrafters:
                    BC_SetOffline();
                    break;

                case FileManager.Modpacks.ProjectCenturos:
                    PC_SetOffline();
                    break;
                }
            }
        }
示例#5
0
 public static void Connect(int index, FileManager.Modpacks modpack)
 {
     try
     {
         socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(Settings.IP_ADDRESS), Settings.PORT);
         socket.Connect(endPoint);
         HandleData(index, modpack);
     }
     catch (Exception e)
     {
         if (lastError != e.Message || lastError == null)
         {
             lastError = $"Connection failed: {e.Message}";
             MainWindow.CurrentWindow.GetError($"Connection failed: {e.Message}");
         }
         isConnected = false;
     }
     socket.Close();
 }
        public static void Login(FileManager.Modpacks modpack)
        {
            var login = new MLogin();

            string[] userData = File.ReadAllText("Launcher/BlockyCrafters/Login.txt").Split(' ');
            var      response = login.Authenticate(userData[0], userData[1]);

            if (!response.IsSuccess)
            {
                MCClient_Login mcClient = new MCClient_Login();
                mcClient.Show();
                mcClient.GetError($"Login Failed!\n" +
                                  "E-Mail or Password invalid!");
            }
            else
            {
                SESSION = response.Session;
                _       = LaunchGameAsync(modpack);
            }
        }
示例#7
0
        static void HandleData(int index, FileManager.Modpacks modpack)
        {
            try
            {
                string[] input = { "VER", "PAT", "NEW", "UPD" };

                lastInput = (input[index] + "_" + (int)modpack).Split('_');
                byte[] data = Encoding.ASCII.GetBytes(input[index] + "_" + (int)modpack);

                socket.Send(data);

                switch (lastInput[0])
                {
                case "VER":
                    GetVersion();
                    break;

                case "PAT":
                    GetPatch();
                    break;

                case "NEW":
                    GetModpack(modpack);
                    break;

                case "UPD":
                    GetUpdate(modpack);
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
                socket.Close();
            }
        }
示例#8
0
        static void DownloadFile(int index, FileManager.Modpacks modpack)
        {
            string[] fileName = { $"{modpack.ToString().ToLower()}.zip", $"{modpack.ToString().ToLower()}_update.zip" };


            if (!File.Exists("Cache/" + fileName[index]))
            {
                byte[] formatted = ReceiveData();
                while (formatted.Length != 0)
                {
                    using (var stream = new FileStream("Cache/" + fileName[index], FileMode.Append))
                    {
                        stream.Write(formatted, 0, formatted.Length);
                    }
                    formatted = ReceiveData();
                }
            }
            else
            {
                Console.WriteLine("{0} already exists!", fileName[index]);
            }
        }
示例#9
0
        private void DeleteModpack(FileManager.Modpacks modpack)
        {
            if (Directory.Exists($"Launcher/{modpack}"))
            {
                try
                {
                    BC_ClientState(3);
                    Directory.Delete($"Launcher/{modpack}", true);

                    Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show($"{modpack} deleted!");
                        switch (modpack)
                        {
                        case FileManager.Modpacks.BlockyCrafters:
                            CurrVerLabel_BC.Content = "Current Version: " + "No Version";
                            BC_ClientState(0);
                            break;

                        case FileManager.Modpacks.ProjectCenturos:
                            CurrVerLabel_PC.Content = "Current Version: " + "No Version";
                            PC_ClientState(0);
                            break;
                        }
                    });
                }
                catch (Exception)
                {
                    switch (modpack)
                    {
                    case FileManager.Modpacks.BlockyCrafters:
                        BC_ClientState(4);
                        break;

                    case FileManager.Modpacks.ProjectCenturos:
                        PC_ClientState(4);
                        break;
                    }
                    GetError($"Failed to delete {modpack}!");
                }
            }
            else
            {
                switch (modpack)
                {
                case FileManager.Modpacks.BlockyCrafters:
                    GetError(
                        $"Failed to delete {modpack}!\n" +
                        $"{modpack} doesn't exist.");
                    BC_ClientState(4);
                    break;

                case FileManager.Modpacks.ProjectCenturos:
                    GetError(
                        $"Failed to delete {modpack}!\n" +
                        $"{modpack} doesn't exist.");
                    PC_ClientState(4);
                    break;
                }
            }
        }
示例#10
0
 static void GetUpdate(FileManager.Modpacks modpack)
 {
     DownloadFile(1, modpack);
     FileManager.ModUpdate(modpack);
 }