Esempio n. 1
0
        public static string DownloadText(Uri uri)
        {
            string result = string.Empty;

            using (var client = new WebClient())
            {
                try
                {
                    Stream       stream = client.OpenRead(uri);
                    StreamReader reader = new StreamReader(stream);
                    result = reader.ReadToEnd();

                    reader.Close();
                    stream.Flush();
                    stream.Close();
                }
                catch (WebException e)
                {
                    OutputConsole.PrintVerbose(e, $"Cannot download file '{uri}'.", 1);
                    return(string.Empty);
                }
            }

            return(result);
        }
Esempio n. 2
0
        public static Image ReadImage(XElement item, string itemName)
        {
            try
            {
                string relativePath = item.XPathSelectElement($"{itemName}/relPath").Value;
                string filename     = Path.Combine(Paths.ExecutingDirectory, relativePath.Replace(@"/", "\\"));
                if (File.Exists(filename))
                {
                    string hash      = item.XPathSelectElement($"{itemName}/hash").Value;
                    string localHash = MD5Hash.FromFile(filename);
                    if (hash == localHash)
                    {
                        return(Image.FromFile(filename));
                    }
                }

                Uri imageUri = new Uri(item.XPathSelectElement($"{itemName}/url").Value);
                Downloader.Download(imageUri, filename);

                return(Image.FromFile(filename));
            }
            catch (Exception e)
            {
                OutputConsole.PrintVerbose(e, $"Unable to load image '{itemName}'.", 1);
                return(null);
            }
        }
Esempio n. 3
0
        private Server ReadServer(XElement server)
        {
            XElement images          = server.XPathSelectElement("style/images");
            XElement launcherProfile = server.XPathSelectElement("launcherProfile");
            XElement options         = server.XPathSelectElement("options");

            Server result = new Server
            {
                Name                = XElementExtender.ReadName(server),
                Version             = XElementExtender.ReadString(server, "version"),
                Ip                  = XElementExtender.ReadString(server, "server/url"),
                State               = XElementExtender.ReadString(server, "state"),
                StatusUri           = XElementExtender.ReadUri(server, "status"),
                PatchNotesUri       = XElementExtender.ReadUri(server, "patchnotesUrl"),
                PatchFilesUri       = XElementExtender.ReadUri(server, "patchUrl"),
                Image               = XElementExtender.ReadImage(images, "background") ?? Properties.Resources.filenotfound,
                LauncherProfileData = ReadLauncherProfileData(launcherProfile),
                Options             = ReadOptions(options)
            };

            result.GrayScaledImage = ImageManipulation.CreateGrayScaledImage(result.Image as Bitmap);

            OutputConsole.PrintVerbose(result, 1);
            return(result);
        }
Esempio n. 4
0
        private Style ReadStyle(XElement style)
        {
            XElement images = style.XPathSelectElement("images");

            Style result = new Style
            {
                LauncherTitle               = XElementExtender.ReadName(style),
                LauncherVersion             = XElementExtender.ReadString(style, "version"),
                LauncherWidth               = XElementExtender.ReadInteger(style, "width"),
                LauncherHeight              = XElementExtender.ReadInteger(style, "height"),
                FontColor                   = XElementExtender.ReadColor(style, "fontColor"),
                DialogBackgroundColor       = XElementExtender.ReadColor(style, "dialogBackgroundColor"),
                DialogFontColor             = XElementExtender.ReadColor(style, "dialogFontColor"),
                LauncherBackgroundImage     = XElementExtender.ReadImage(images, "background") ?? Properties.Resources.filenotfound,
                LauncherOverlayImage        = XElementExtender.ReadImage(images, "overlay") ?? Properties.Resources.filenotfound,
                ServerOnlineImage           = XElementExtender.ReadImage(images, "serverOnline") ?? Properties.Resources.filenotfound,
                ServerOfflineImage          = XElementExtender.ReadImage(images, "serverOffline") ?? Properties.Resources.filenotfound,
                ServerPlayButtonImage       = XElementExtender.ReadImage(images, "buttonPlay") ?? Properties.Resources.filenotfound,
                ServerInstallButtonImage    = XElementExtender.ReadImage(images, "buttonInstall") ?? Properties.Resources.filenotfound,
                ServerUninstallButtonImage  = XElementExtender.ReadImage(images, "buttonUninstall") ?? Properties.Resources.filenotfound,
                ServerUpdateButtonImage     = XElementExtender.ReadImage(images, "buttonUpdate") ?? Properties.Resources.filenotfound,
                SettingsButtonImage         = XElementExtender.ReadImage(images, "buttonSettings") ?? Properties.Resources.filenotfound,
                RefreshButtonImage          = XElementExtender.ReadImage(images, "buttonRefresh") ?? Properties.Resources.filenotfound,
                ServerPatchNotesButtonImage = XElementExtender.ReadImage(images, "buttonPatchnotes") ?? Properties.Resources.filenotfound
            };

            result.ServerUninstallButtonGrayScaledImage = ImageManipulation.CreateGrayScaledImage(result.ServerUninstallButtonImage as Bitmap);


            OutputConsole.PrintVerbose(result, 3);
            return(result);
        }
Esempio n. 5
0
        private CleanupDirectory ReadCleanupDirectory(XElement item)
        {
            CleanupDirectory result = new CleanupDirectory
            {
                LocalDirectory = XElementExtender.ReadPath(item)
            };

            OutputConsole.PrintVerbose(result, 5);
            return(result);
        }
Esempio n. 6
0
        private Player ReadPlayer(XElement player)
        {
            Player result = new Player
            {
                Name  = XElementExtender.ReadName(player),
                Image = XElementExtender.ReadImage(player)
            };

            OutputConsole.PrintVerbose(result, 2);
            return(result);
        }
Esempio n. 7
0
        public Launcher Read(XDocument document)
        {
            Launcher result = new Launcher
            {
                Server    = new ServerReader().Read(document),
                Style     = new StyleReader().Read(document),
                FileInfos = new FileInfosReader().Read(document)
            };

            OutputConsole.PrintVerbose(result, 1);
            return(result);
        }
Esempio n. 8
0
        private PatchFile ReadPatchFile(XElement item)
        {
            PatchFile result = new PatchFile
            {
                Filename       = XElementExtender.ReadName(item),
                DownloadUri    = XElementExtender.ReadUri(item),
                LocalDirectory = XElementExtender.ReadPath(item),
                Hash           = XElementExtender.ReadHash(item)
            };

            OutputConsole.PrintVerbose(result, 5);
            return(result);
        }
Esempio n. 9
0
        private LauncherProfileData ReadLauncherProfileData(XElement launcherProfile)
        {
            LauncherProfileData result = new LauncherProfileData
            {
                Name          = XElementExtender.ReadName(launcherProfile),
                Type          = XElementExtender.ReadString(launcherProfile, "type"),
                Icon          = XElementExtender.ReadString(launcherProfile, "icon"),
                LastVersionId = XElementExtender.ReadString(launcherProfile, "lastVersionId"),
                JavaArgs      = XElementExtender.ReadString(launcherProfile, "javaArgs"),
                GameDirectory = XElementExtender.ReadString(launcherProfile, "gameDir")
            };

            OutputConsole.PrintVerbose(result, 1);
            return(result);
        }
Esempio n. 10
0
        public Serverstatus Read(XDocument document)
        {
            XElement root = document.XPathSelectElement("root");

            Serverstatus result = new Serverstatus
            {
                Online          = XElementExtender.ReadBoolean(root, "online"),
                MessageOfTheDay = XElementExtender.ReadString(root, "motd"),
                GameMode        = XElementExtender.ReadString(root, "gameType"),
                MaxPlayers      = XElementExtender.ReadInteger(root, "playerMax"),
                CurrentPlayers  = XElementExtender.ReadInteger(root, "playerOnline"),
                Players         = new PlayerReader().Read(document)
            };

            OutputConsole.PrintVerbose(result, 2);
            return(result);
        }
Esempio n. 11
0
        public FileInfos Read(XDocument document)
        {
            XElement launcherProfilesJson = document.XPathSelectElement("root/launcher/launcherProfilesJson");
            XElement optionsTxt           = document.XPathSelectElement("root/launcher/optionsTxt");
            XElement minecraftExecutable  = document.XPathSelectElement("root/launcher/minecraftExecutable");

            FileInfos result = new FileInfos()
            {
                DefaultLauncherProfilesFile  = XElementExtender.ReadUri(launcherProfilesJson),
                LauncherProfilesFilename     = XElementExtender.ReadPath(launcherProfilesJson),
                DefaultOptionsFile           = XElementExtender.ReadUri(optionsTxt),
                OptionsFilename              = XElementExtender.ReadRelativePath(optionsTxt),
                DefaultMinecraftLauncherFile = XElementExtender.ReadUri(minecraftExecutable),
                MinecraftLauncherFilename    = XElementExtender.ReadPath(minecraftExecutable),
                MinecraftLauncherHash        = XElementExtender.ReadHash(minecraftExecutable)
            };

            OutputConsole.PrintVerbose(result, 1);
            return(result);
        }
Esempio n. 12
0
 public static Image DownloadImage(Uri uri)
 {
     try
     {
         Image result = null;
         using (var client = new WebClient())
         {
             Stream stream = client.OpenRead(uri);
             result = new Bitmap(stream);
             stream.Flush();
             stream.Close();
         }
         return(result);
     }
     catch (WebException e)
     {
         OutputConsole.PrintVerbose(e, $"Cannot download file '{uri}'.", 1);
         return(Properties.Resources.filenotfound);
     }
 }
Esempio n. 13
0
        public static void Download(Uri uri, string target)
        {
            try
            {
                using (var client = new WebClient())
                {
                    string path = Path.GetDirectoryName(target);

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    client.DownloadFile(uri, target);
                    OutputConsole.PrintVerbose($"[Download] '{uri}'.", 3);
                }
            }
            catch (WebException e)
            {
                OutputConsole.PrintVerbose(e, $"Cannot download file '{uri}'.", 1);
            }
        }