예제 #1
0
        public bool downloadMod(LocalMod mod, String location)
        {
            Console.WriteLine(mod.source.url + "download/mod/" + mod.id);
            WebClientTimeOut wc = new WebClientTimeOut();

            try {
                wc.DownloadFile(new Uri(mod.source.url + "download/mod/" + mod.id), location);
            } catch (WebException) {
                return(false);
            }

            // now check whether the downloaded file is actually a mod, and not an error
            String[] keys = wc.ResponseHeaders.AllKeys;

            String contentType = "";

            for (int i = 0; i < keys.Length; i++)
            {
                if (keys[i].Equals("Content-Type"))
                {
                    contentType = wc.ResponseHeaders.Get(i);
                }
            }

            if (contentType.Equals("application/x-msdos-program"))             // success
            {
                return(true);
            }
            else             // for example "application/json" or none at all, error
            {
                return(false);
            }
        }
예제 #2
0
        public static bool tryUpdate()
        {
            WebClientTimeOut client = new WebClientTimeOut ();
            String versionMessageRaw;
            try {
                versionMessageRaw = client.DownloadString (new Uri("http://mods.scrollsguide.com/version"));
            } catch (WebException) {
                return false;
            }

            JsonReader reader = new JsonReader ();
            VersionMessage versionMessage = (VersionMessage)reader.Read (versionMessageRaw, typeof(VersionMessage));

            int version = versionMessage.version ();
            String installPath = Platform.getGlobalScrollsInstallPath () + Path.DirectorySeparatorChar + "ModLoader" + Path.DirectorySeparatorChar;

            try {
                File.Delete (installPath + "Updater.exe");
            } catch {}

            if (!System.IO.Directory.Exists(installPath)) {
                System.IO.Directory.CreateDirectory(installPath);
            }

            if (version > ModLoader.getVersion()) {

                byte[] asm;
                try {
                    asm = client.DownloadData(new Uri("http://mods.scrollsguide.com/download/update"));
                } catch (WebException) {
                    return false;
                }
                File.WriteAllBytes (installPath + "Updater.exe", asm);
                if (CheckToken (installPath + "Updater.exe", token)) {

                    try {
                        App.Popups.ShowInfo ("Scrolls Summoner is updating", "Please wait while the update is being downloaded");
                        Dialogs.showNotification("Scrolls Summoner is updating", "Please wait while the update is being downloaded");
                    } catch { }

                    if (Platform.getOS () == Platform.OS.Win) {
                        new Process { StartInfo = { FileName = installPath + "Updater.exe", Arguments = "" } }.Start ();
                    } else if (Platform.getOS () == Platform.OS.Mac) {
                        Assembly.LoadFrom (installPath + "Updater.exe").EntryPoint.Invoke (null, new object[] { new string[] {} });
                    }
                    return true;
                }

                try {
                    App.Popups.KillCurrentPopup();
                } catch {}
            }

            return false;
        }
예제 #3
0
        private bool readRepository(string url)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;            // or you get an exeption, because mono doesnt trust anyone
            //normalize it

            if (!url.StartsWith("https://raw.github.com/"))
            {
                Uri urlNorm = new Uri(url);
                url = urlNorm.Host;
            }
            String repoinfo = null;

            try {
                WebClientTimeOut client = new WebClientTimeOut();
                if (url.StartsWith("https://raw.github.com/"))
                {
                    repoinfo = client.DownloadString(new Uri(url + "/repoinfo.txt"));
                }
                else
                {
                    repoinfo = client.DownloadString(new Uri("http://" + url + "/repoinfo"));
                }
            } catch (WebException ex) {
                Console.WriteLine(ex);
                return(false);
            }

            RepoInfoMessage message = null;

            try {
                JsonReader reader = new JsonReader();
                message = reader.Read(repoinfo, typeof(RepoInfoMessage)) as RepoInfoMessage;
            } catch {
                return(false);
            }

            if (message == null)
            {
                return(false);
            }

            if (!message.msg.Equals("success"))
            {
                return(false);
            }

            Repo repo = message.data;

            repo.tryToGetFavicon();
            repositories.Add(repo);

            return(this.tryToFetchModList(repo));
        }
예제 #4
0
        public bool tryToFetchModList(Repo repo)
        {
            String modlist = null;

            try {
                WebClientTimeOut client = new WebClientTimeOut();
                if (repo.url.StartsWith("https://raw.github.com/"))
                {
                    modlist = client.DownloadString(new Uri(repo.url + "modlist.txt"));
                }
                else
                {
                    modlist = client.DownloadString(new Uri(repo.url + "modlist"));
                }
            } catch (WebException ex) {
                Console.WriteLine(ex);
                repositories.Remove(repo);
                return(false);
            }

            ModListMessage message = null;

            try {
                JsonReader reader = new JsonReader();
                message = reader.Read(modlist, typeof(ModListMessage)) as ModListMessage;
            } catch {
                repositories.Remove(repo);
                return(false);
            }

            if (message == null)
            {
                repositories.Remove(repo);
                return(false);
            }

            if (!message.msg.Equals("success"))
            {
                repositories.Remove(repo);
                return(false);
            }

            modsPerRepo.Add(repo, new List <Item>(message.data));
            return(true);
        }
예제 #5
0
        private bool readRepository(string url)
        {
            //normalize it
            Uri urlNorm = new Uri(url);

            url = urlNorm.Host;

            String repoinfo = null;

            try {
                WebClientTimeOut client = new WebClientTimeOut();
                repoinfo = client.DownloadString(new Uri("http://" + url + "/repoinfo"));
            } catch (WebException ex) {
                Console.WriteLine(ex);
                return(false);
            }

            RepoInfoMessage message = null;

            try {
                JsonReader reader = new JsonReader();
                message = reader.Read(repoinfo, typeof(RepoInfoMessage)) as RepoInfoMessage;
            } catch {
                return(false);
            }

            if (message == null)
            {
                return(false);
            }

            if (!message.msg.Equals("success"))
            {
                return(false);
            }

            Repo repo = message.data;

            repo.tryToGetFavicon();
            repositories.Add(repo);

            return(this.tryToFetchModList(repo));
        }
예제 #6
0
        private bool readRepository(string url)
        {
            //normalize it
            Uri urlNorm = new Uri (url);
            url = urlNorm.Host;

            String repoinfo = null;
            try {
                WebClientTimeOut client = new WebClientTimeOut ();
                repoinfo = client.DownloadString (new Uri("http://"+url+"/repoinfo"));
            } catch (WebException ex) {
                Console.WriteLine (ex);
                return false;
            }

            RepoInfoMessage message = null;
            try {
                JsonReader reader = new JsonReader();
                message = reader.Read(repoinfo, typeof(RepoInfoMessage)) as RepoInfoMessage;
            } catch {
                return false;
            }

            if (message == null) {
                return false;
            }

            if (!message.msg.Equals("success")) {
                return false;
            }

            Repo repo = message.data;
            repo.tryToGetFavicon ();
            repositories.Add(repo);

            return this.tryToFetchModList (repo);
        }
예제 #7
0
        public bool tryToFetchModList(Repo repo)
        {
            String modlist = null;
            try {
                WebClientTimeOut client = new WebClientTimeOut ();
                modlist = client.DownloadString (new Uri(repo.url+"modlist"));
            } catch (WebException ex) {
                Console.WriteLine (ex);
                repositories.Remove (repo);
                return false;
            }

            ModListMessage message = null;
            try {
                JsonReader reader = new JsonReader();
                message = reader.Read(modlist, typeof(ModListMessage)) as ModListMessage;
            } catch {
                repositories.Remove (repo);
                return false;
            }

            if (message == null) {
                repositories.Remove (repo);
                return false;
            }

            if (!message.msg.Equals("success")) {
                repositories.Remove (repo);
                return false;
            }

            modsPerRepo.Add (repo, new List<Item>(message.data));
            return true;
        }
예제 #8
0
        public void PatchScrollsWindows()
        {
            String URL;

            if (Platform.getOS() == Platform.OS.Win)
            {
                URL = "http://download.scrolls.com/client/windows.zip";
            }
            else
            {
                URL = "http://download.scrolls.com/client/mac.zip";
            }

            String gameFolder = Path.GetFullPath(Directory.GetParent(Platform.getGlobalScrollsInstallPath()).Parent.Parent.Parent.FullName) + Path.DirectorySeparatorChar;

            //wait
            WebClientTimeOut webClient = new WebClientTimeOut();

            if (File.Exists(gameFolder + "game.zip"))
            {
                File.Delete(gameFolder + "game.zip");
            }
            try
            {
                webClient.DownloadFile(URL, gameFolder + "game.zip");
            }
            catch (WebException)
            {
                App.Popups.KillCurrentPopup();
                App.Popups.ShowOk(null, "info", "Error", "And error occured while downloading the update.", "OK");
                return;
            }

            //backup assembly
            String backupPath = gameFolder + "ScrollsModLoader.dll";

            if (File.Exists(backupPath))
            {
                File.Delete(backupPath);
            }
            File.Copy(Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll", backupPath);

            //backup modloader folder
            String modBackupPath = gameFolder + "ModLoader" + Path.DirectorySeparatorChar;

            if (Directory.Exists(modBackupPath))
            {
                Extensions.DeleteDirectory(modBackupPath);
            }
            Directory.Move(Platform.getGlobalScrollsInstallPath() + "ModLoader", modBackupPath);
            File.Delete(modBackupPath + "mods.ini");
            File.Delete(modBackupPath + "Assembly-CSharp.dll");

            if (Platform.getOS() == Platform.OS.Win)
            {
                Extensions.DeleteDirectory(gameFolder + "game");
            }
            else
            {
                Extensions.DeleteDirectory(gameFolder + "MacScrolls.app");
            }

            //extract
            ZipFile zip = ZipFile.Read(gameFolder + "game.zip");

            foreach (ZipEntry e in zip)
            {
                e.Extract(gameFolder + "game");
            }

            //move assembly
            File.Copy(backupPath, Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll");
            // File.Delete(backupPath);

            //move modloader folder back
            Directory.Move(modBackupPath, Platform.getGlobalScrollsInstallPath() + "ModLoader");

            //make new repatch backup
            File.Copy(Platform.getGlobalScrollsInstallPath() + "Assembly-CSharp.dll", Platform.getGlobalScrollsInstallPath() + "ModLoader" + Path.DirectorySeparatorChar + "Assembly-CSharp.dll");

            //make sure mods get hooks set with new version
            File.Delete(Platform.getGlobalScrollsInstallPath() + "ModLoader" + Path.DirectorySeparatorChar + "mods.ini");
            ScrollsFilter.clearHooks();
            Console.WriteLine("Cleared Hooks");

            //repatch
            Patcher patcher = new Patcher();

            if (!patcher.patchAssembly(Platform.getGlobalScrollsInstallPath()))
            {
                if (!patcher.safeModePatchAssembly())
                {
                    Dialogs.showNotification("Summoner patch failed", "Summoner failed in patch itself into the updated files. It will uninstall itself. For more informations visit scrollsguide.com/summoner");
                    File.Delete(Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll");
                    Extensions.DeleteDirectory(Platform.getGlobalScrollsInstallPath() + "ModLoader");
                }
            }

            Console.WriteLine("Now restarting the game...");

            //restart the game
            Platform.RestartGame();
        }
예제 #9
0
        public void PatchScrollsMac()
        {
            String URL;
            if (Platform.getOS () == Platform.OS.Win) {
                URL = "http://download.scrolls.com/client/windows.zip";
            } else {
                URL = "http://download.scrolls.com/client/mac.zip";
            }

            String gameFolder = Path.GetFullPath(Directory.GetParent(Platform.getGlobalScrollsInstallPath()).Parent.Parent.Parent.Parent.FullName)+ Path.DirectorySeparatorChar;
            String modLoaderPath = Platform.getModLoaderPath ();
            String globalScrollsInstallPath = Platform.getGlobalScrollsInstallPath ();
            //wait
            WebClientTimeOut webClient = new WebClientTimeOut();
            if (File.Exists (gameFolder + "game.zip"))
            {
                File.Delete (gameFolder + "game.zip");
            }
            try {
                webClient.DownloadFile(URL, gameFolder + "game.zip");
            } catch (WebException) {
                App.Popups.KillCurrentPopup();
                App.Popups.ShowOk (null, "info", "Error", "And error occured while downloading the update.", "OK");
                return;
            }

            //backup assembly
            String backupPath = gameFolder + "ScrollsModLoader.dll";
            if (File.Exists(backupPath)){
                File.Delete (backupPath);
            }
            File.Copy (globalScrollsInstallPath + "ScrollsModLoader.dll", backupPath);

            //backup modloader folder
            String modBackupPath = modLoaderPath+ Path.DirectorySeparatorChar;
            if (Directory.Exists (modBackupPath)){
                Extensions.DeleteDirectory (modBackupPath);
            }
            Directory.Move (modLoaderPath , modBackupPath);
            File.Delete (modBackupPath + "mods.ini");
            File.Delete (modBackupPath + "Assembly-CSharp.dll");

            if (Platform.getOS () == Platform.OS.Win) {
                Extensions.DeleteDirectory (gameFolder + "game" + Path.DirectorySeparatorChar + "Scrolls_Data");
                File.Delete (gameFolder + "game" + Path.DirectorySeparatorChar + "Scrolls.exe");
            } else {
                Extensions.DeleteDirectory (gameFolder + "MacScrolls.app");
            }

            //extract
            String zipLocation = gameFolder + "game.zip";
            if (Platform.getOS() == Platform.OS.Win){
                String newZipLocation = gameFolder + "game" + Path.DirectorySeparatorChar + "game.zip";
                File.Move(zipLocation, newZipLocation);
                zipLocation = newZipLocation;
            }
            ZipFile zip = ZipFile.Read(zipLocation);
            foreach (ZipEntry e in zip)
            {
                e.Extract();
            }

            //move assembly
            File.Copy (backupPath, globalScrollsInstallPath + "ScrollsModLoader.dll");
            File.Delete (backupPath);

            //move modloader folder back
            Directory.Move (modBackupPath, modLoaderPath);

            //make new repatch backup
            File.Copy (globalScrollsInstallPath + "Assembly-CSharp.dll", modLoaderPath + Path.DirectorySeparatorChar + "Assembly-CSharp.dll");

            //make sure mods get hooks set with new version
            File.Delete (modLoaderPath + Path.DirectorySeparatorChar + "mods.ini");
            ScrollsFilter.clearHooks ();

            //repatch
            Patcher patcher = new Patcher ();
            if (!patcher.patchAssembly (globalScrollsInstallPath)) {
                if (!patcher.safeModePatchAssembly ()) {
                    Dialogs.showNotification ("Summoner patch failed", "Summoner failed in patch itself into the updated files. It will uninstall itself. For more informations visit scrollsguide.com/summoner");
                    File.Delete (globalScrollsInstallPath + "ScrollsModLoader.dll");
                    Extensions.DeleteDirectory (modLoaderPath);
                }
            }

            //restart the game
            Platform.RestartGame ();
        }
예제 #10
0
        private static byte[] token = new byte[] { 8, 95, 174, 161, 22, 41, 180, 133 };         //public key

        public static bool tryUpdate()
        {
            WebClientTimeOut client = new WebClientTimeOut();
            String           versionMessageRaw;

            try {
                versionMessageRaw = client.DownloadString(new Uri("http://mods.scrollsguide.com/version"));
            } catch (WebException) {
                return(false);
            }

            JsonReader     reader         = new JsonReader();
            VersionMessage versionMessage = (VersionMessage)reader.Read(versionMessageRaw, typeof(VersionMessage));

            int    version     = versionMessage.version();
            String installPath = Platform.getModLoaderPath() + Path.DirectorySeparatorChar;             //;Platform.getGlobalScrollsInstallPath () + Path.DirectorySeparatorChar + "ModLoader" + Path.DirectorySeparatorChar;

            try {
                File.Delete(installPath + "Updater.exe");
            } catch {}

            if (!System.IO.Directory.Exists(installPath))
            {
                System.IO.Directory.CreateDirectory(installPath);
            }

            if (version > ModLoader.getVersion())
            {
                byte[] asm;
                try {
                    asm = client.DownloadData(new Uri("http://mods.scrollsguide.com/download/update"));
                } catch (WebException) {
                    return(false);
                }
                File.WriteAllBytes(installPath + "Updater.exe", asm);
                if (CheckToken(installPath + "Updater.exe", token))
                {
                    try {
                        App.Popups.ShowInfo("Scrolls Summoner is updating", "Please wait while the update is being downloaded");
                        Dialogs.showNotification("Scrolls Summoner is updating", "Please wait while the update is being downloaded");
                    } catch { }

                    if (Platform.getOS() == Platform.OS.Win)
                    {
                        new Process {
                            StartInfo = { FileName = installPath + "Updater.exe", Arguments = "" }
                        }.Start();
                    }
                    else if (Platform.getOS() == Platform.OS.Mac)
                    {
                        Assembly.LoadFrom(installPath + "Updater.exe").EntryPoint.Invoke(null, new object[] { new string[] {} });
                    }
                    return(true);
                }

                try {
                    App.Popups.KillCurrentPopup();
                } catch {}
            }

            return(false);
        }
예제 #11
0
        public bool downloadMod(LocalMod mod, String location)
        {
            Console.WriteLine (mod.source.url + "download/mod/" + mod.id);
            WebClientTimeOut wc = new WebClientTimeOut();

            try {
                wc.DownloadFile (new Uri(mod.source.url + "download/mod/" + mod.id), location);
            } catch (WebException) {
                return false;
            }

            // now check whether the downloaded file is actually a mod, and not an error
            String[] keys = wc.ResponseHeaders.AllKeys;

            String contentType = "";
            for (int i = 0; i < keys.Length; i++)
            {
                if (keys[i].Equals("Content-Type"))
                {
                    contentType = wc.ResponseHeaders.Get(i);
                }
            }

            if (contentType.Equals("application/x-msdos-program")) // success
            {
                return true;
            }
            else
            {   // from github its an text/plain file
                if (mod.source.url.StartsWith ("https://raw.github.com/") && (contentType.Equals("text/plain") || contentType.Equals("application/octet-stream")))
                {
                    return true;
                }
                else // for example "application/json" or none at all, error
                {
                    return false;
                }
            }
        }
예제 #12
0
        private bool readRepository(string url)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;// or you get an exeption, because mono doesnt trust anyone
            //normalize it

            if (!url.StartsWith ("https://raw.github.com/")) {
                Uri urlNorm = new Uri (url);
                url = urlNorm.Host;
            }
            String repoinfo = null;
            try {
                WebClientTimeOut client = new WebClientTimeOut ();
                if(url.StartsWith("https://raw.github.com/"))
                {
                    repoinfo = client.DownloadString (new Uri(url+"/repoinfo.txt"));
                }
                else
                {
                    repoinfo = client.DownloadString (new Uri("http://"+url+"/repoinfo"));
                }

            } catch (WebException ex) {
                Console.WriteLine (ex);
                return false;
            }

            RepoInfoMessage message = null;
            try {
                JsonReader reader = new JsonReader();
                message = reader.Read(repoinfo, typeof(RepoInfoMessage)) as RepoInfoMessage;
            } catch {
                return false;
            }

            if (message == null) {
                return false;
            }

            if (!message.msg.Equals("success")) {
                return false;
            }

            Repo repo = message.data;
            repo.tryToGetFavicon ();
            repositories.Add(repo);

            return this.tryToFetchModList (repo);
        }