Inheritance: JsonEntity
Exemplo n.º 1
0
        public void TestCheckForUpdateEqualToCurrentVersionAvailable()
        {
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));

            MockFile gamesManagerFile = (MockFile)FileSystem.Current.GetFile("C:\\program files\\MGDF\\GamesManager.exe");
            gamesManagerFile.WriteText("EXECUTABLE");
            gamesManagerFile.AssemblyVersion = new Version(1, 0, 0, 0);

            var newFrameworkData = GenerateDataBlock(65536);
            var frameworkMd5 = GenerateMd5Hash(newFrameworkData);

            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://www.matchstickframework.org/downloads/1/MGDF.zip", newFrameworkData);
            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://games.junkship.org/gamesource.asmx/downloads/1/Console/latest.json", @"{""Framework"":{
            ""Version"":""1.0.0.0"",
            ""Url"":""http://www.matchstickframework.org/downloads/1/MGDF.zip"",
            ""MD5"":""" + frameworkMd5 + @"""
            }}");

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            AvailableUpdates update = UpdateChecker.CheckForUpdate(game);

            Assert.IsNotNull(update);
            Assert.IsNull(update.Framework);
        }
Exemplo n.º 2
0
        public static AvailableUpdates CheckForUpdate(Game game)
        {
            AvailableUpdates result = new AvailableUpdates();
            GameUpdate availableUpdates;

            if (!string.IsNullOrEmpty(game.UpdateService))
            {
                try
                {
                    using (var responseStream = HttpRequestManager.Current.GetResponseStream(game.UpdateService))
                    {
                        using (var reader = new StreamReader(responseStream))
                        {
                            availableUpdates = JsonConvert.DeserializeObject<GameUpdate>(reader.ReadToEnd());
                        }
                    }

                    var currentVersion = FileSystem.Current.GetFile(Resources.GamesManagerExecutable).AssemblyVersion;

                    //if the available version is specified and is newer than what we have already, then the framework needs an update
                    if (availableUpdates.Framework!=null && new Version(availableUpdates.Framework.Version) > currentVersion)
                    {
                        result.Framework = availableUpdates.Framework;
                    }

                    //if the available version isn't newer than what we have already, then don't bother updating.
                    if (availableUpdates.Latest!=null && new Version(availableUpdates.Latest.Version) > game.Version)
                    {
                        if (availableUpdates.UpdateOlderVersions != null)
                        {
                            //try to find a partial update for this version if possible
                            foreach (var olderVersion in availableUpdates.UpdateOlderVersions)
                            {
                                if (new Version(olderVersion.FromVersion) == game.Version)
                                {
                                    result.Game = new UpdateDownload
                                               {
                                                   Url = olderVersion.Url,
                                                   Version = availableUpdates.Latest.Version,
                                                   MD5 = olderVersion.MD5
                                               };
                                }
                            }
                        }

                        //otherwise resort to a full update
                        if (result.Game==null) result.Game = availableUpdates.Latest;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Unable to read " + game.UpdateService + " - " + ex);
                }
            }
            return result;
        }
Exemplo n.º 3
0
 public GameDownloader(Game game,string sourceUrl, string destinationFileName, string expectedMd5, Func<GetCredentialsEventArgs, bool> getCredentials)
     : base(sourceUrl, destinationFileName, expectedMd5,null)
 {
     _game = game;
     //wrap the credentials call back in our own handler
     //which first looks for stored credentials before prompting the user
     _getCredentials = GetCredentials;
     _newCredentials = getCredentials;
     _requiresManualIntervention = false;
 }
Exemplo n.º 4
0
        private void Load()
        {
            Game = new Game(GameContents.GetFile(Resources.GameConfig));
            ErrorCollection.AddRange(Game.ErrorCollection);

            if (GameContents.GetFile(Resources.UpdateConfig) != null)
            {
                Update = new Update(Game,GameContents.GetFile(Resources.UpdateConfig));
                ErrorCollection.AddRange(Update.ErrorCollection);
            }
        }
 public static void AddToInstalledPrograms(Game game)
 {
     var key = Registry.Current.CreateSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF" + Resources.InterfaceVersion + "_" + game.Uid);
     key.CreateValue("DisplayIcon", Resources.GameSystemIconFile());
     key.CreateValue("DisplayName", game.Name);
     key.CreateValue("URLInfoAbout", game.Homepage);
     key.CreateDWordValue("NoModify", 1);
     key.CreateDWordValue("NoRepair", 1);
     key.CreateValue("Publisher", game.DeveloperName);
     key.CreateValue("InstallLocation", Resources.GameBaseDir);
     key.CreateValue("DisplayVersion", game.Version.ToString());
 }
Exemplo n.º 6
0
        public Update(Game upgadeTarget, IArchiveFile updateFile)
            : base(updateFile)
        {
            _updateTarget = upgadeTarget;

            if (UpdateMinVersion >= upgadeTarget.Version || UpdateMaxVersion >= upgadeTarget.Version)
            {
                ErrorCollection.Add("UpdateMinVersion and UpdateMaxVersion must be less than the upgraded game version");
            }
            else if (UpdateMinVersion > UpdateMaxVersion)
            {
                ErrorCollection.Add("UpdateMinVersion must be less than or equal to UpdateMaxVersion");
            }
        }
Exemplo n.º 7
0
 public void LoadGame()
 {
     MockDirectory gameDirectory = ((MockDirectory)MockFileSystem.GetDirectory(EnvironmentSettings.Current.AppDirectory + "\\game"));
     gameDirectory.AddFile("game.json", ReadTextFile("console.json"));
     Game game = new Game(Path.Combine(EnvironmentSettings.Current.AppDirectory,"game\\game.json"));
     Assert.AreEqual("Console",game.Uid);
     Assert.AreEqual("Lua Console", game.Name);
     Assert.AreEqual(new Version(0,1), game.Version);
     Assert.AreEqual("http://www.junkship.org", game.Homepage);
     Assert.AreEqual(1, game.InterfaceVersion);
     Assert.AreEqual("no8 interactive",game.DeveloperName);
     Assert.AreEqual(true, game.IsValid);
     Assert.AreEqual("http://games.junkship.org/gamesource.asmx", game.UpdateService);
     Assert.AreEqual("http://statistics.junkship.org/statisticsservice.asmx", game.StatisticsService);
 }
Exemplo n.º 8
0
        public void TestCanSendStatisticsDeniedNoPrivacyPolicy()
        {
            const string gameContent = @"{
              ""gameuid"":""Console"",
              ""gamename"":""Lua Console"",
              ""description"":""A Lua command console for interacting with the MGDF system"",
              ""version"":""0.1"",
              ""interfaceversion"":""1"",
              ""developeruid"":""no-8"",
              ""developername"":""no8 interactive"",
              ""homepage"":""http://www.junkship.org"",
              ""gamesourceservice"":""http://games.junkship.org/gamesource.asmx"",
              ""statisticsservice"":""http://statistics.junkship.org/statisticsservice.asmx"",
              ""supportemail"":""*****@*****.**""
            }";

            MockDirectory gameDirectory = ((MockDirectory)MockFileSystem.GetDirectory(EnvironmentSettings.Current.AppDirectory + "\\game"));
            gameDirectory.AddFile("game.json", gameContent);
            Game game = new Game(Path.Combine(EnvironmentSettings.Current.AppDirectory, "game\\game.json"));

            Assert.IsFalse(StatisticsSession.CanSendStatistics(game));
        }
Exemplo n.º 9
0
        public void LoadInvalidGameInvalidVersion()
        {
            const string InvalidVersion = @"{
              ""gameuid"":""Console"",
              ""gamename"":""Lua Console"",
              ""description"":""A Lua command console for interacting with the MGDF system"",
              ""version"":""1.0 Beta 2"",
              ""interfaceversion"":""1"",
              ""developeruid"":""no-8"",
              ""developername"":""no8 interactive"",
              ""homepage"":""http://www.junkship.org"",
              ""gamesourceservice"":""http://games.junkship.org/gamesource.asmx"",
              ""statisticsservice"":""http://statistics.junkship.org/statisticsservice.asmx"",
              ""statisticsprivacypolicy"":""We wont use ur informationz"",
              ""supportemail"":""*****@*****.**""
            }";

            MockDirectory gameDirectory = ((MockDirectory)MockFileSystem.GetDirectory(EnvironmentSettings.Current.AppDirectory + "\\game"));
            gameDirectory.AddFile("game.json", InvalidVersion);
            Game game = new Game(Path.Combine(EnvironmentSettings.Current.AppDirectory, "game\\game.json"));
            Assert.AreEqual(false, game.IsValid);
            Assert.AreEqual(1, game.ErrorCollection.Count);
        }
Exemplo n.º 10
0
        public void TestCheckForUpdateAndDownloadUpdate()
        {
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));

            MockFile gamesManagerFile = (MockFile)FileSystem.Current.GetFile("C:\\program files\\MGDF\\GamesManager.exe");
            gamesManagerFile.WriteText("EXECUTABLE");
            gamesManagerFile.AssemblyVersion = new Version(1, 0, 0, 0);

            var newFrameworkData = GenerateDataBlock(65536);
            var frameworkMd5 = GenerateMd5Hash(newFrameworkData);

            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://www.matchstickframework.org/downloads/1/MGDF.zip",newFrameworkData);
            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://games.junkship.org/gamesource.asmx", @"{""Framework"":{
            ""Version"":""1.1.2.4"",
            ""Url"":""http://www.matchstickframework.org/downloads/1/MGDF.zip"",
            ""MD5"":""" + frameworkMd5 + @"""
            }}");

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            AvailableUpdates update = UpdateChecker.CheckForUpdate(game);

            Assert.IsNotNull(update);
            Assert.IsNotNull(update.Framework);
            Assert.AreEqual("http://www.matchstickframework.org/downloads/1/MGDF.zip",update.Framework.Url);
            Assert.AreEqual(frameworkMd5, update.Framework.MD5);
            Assert.AreEqual("1.1.2.4", update.Framework.Version);

            Assert.IsFalse(FileSystem.Current.GetFile("c:\\temp.zip").Exists);

            //now download the actual update.
            FileDownloader downloader = new FileDownloader("http://www.matchstickframework.org/downloads/1/MGDF.zip","c:\\temp.zip",frameworkMd5,null);
            downloader.Start();

            Assert.IsTrue(FileSystem.Current.GetFile("c:\\temp.zip").Exists);
            Assert.AreEqual(65536,FileSystem.Current.GetFile("c:\\temp.zip").Length);
        }
Exemplo n.º 11
0
        public void TestCheckForUpdateAndDownloadUpdateNoAuth()
        {
            //lets pretend that this game is already installed.
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));

            var newGameData = GenerateDataBlock(65536);
            var gameMd5 = GenerateMd5Hash(newGameData);

            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://www.junkship.net/downloads/console.zip", newGameData);
            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://games.junkship.org/gamesource.asmx", @"{
            ""Latest"":{
            ""Version"":""1.1.2.4"",
            ""Url"":""http://www.junkship.net/downloads/console.zip"",
            ""MD5"":""" + gameMd5 + @"""
            }
            }");

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            var update = UpdateChecker.CheckForUpdate(game);

            Assert.IsNotNull(update);
            Assert.IsNotNull(update.Game);
            Assert.AreEqual("http://www.junkship.net/downloads/console.zip", update.Game.Url);
            Assert.AreEqual(gameMd5, update.Game.MD5);
            Assert.AreEqual("1.1.2.4", update.Game.Version);

            Assert.IsFalse(FileSystem.Current.GetFile("c:\\temp.zip").Exists);

            //now download the actual update.
            GameDownloader downloader = new GameDownloader(game,"http://www.junkship.net/downloads/console.zip", "c:\\temp.zip", gameMd5, null);
            downloader.Start();

            Assert.IsTrue(FileSystem.Current.GetFile("c:\\temp.zip").Exists);
            Assert.AreEqual(65536, FileSystem.Current.GetFile("c:\\temp.zip").Length);
        }
Exemplo n.º 12
0
 public bool Equals(Game other)
 {
     return Uid == other.Uid && Version == other.Version;
 }
Exemplo n.º 13
0
 public GameRegistrar(bool register,Game game)
 {
     _register = register;
     _game = game;
 }
Exemplo n.º 14
0
        static int RunMain()
        {
            var commandLine = new CommandLineParser(Environment.GetCommandLineArgs());
             			Resources.InitGameDirectory(commandLine[Resources.GamesManagerArguments.GameDirOverrideArgument]);

            Application.ThreadException += Application_ThreadException;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Game game = new Game(FileSystem.Combine(Resources.GameBaseDir,Resources.GameConfig));
            if (game.ErrorCollection.Count>0)
            {
                ViewFactory.Current.CreateView<IMessage>().Show("Game configuration invalid " + game.ErrorCollection[0], "Game configuration invalid");
                return -1;
            }
            Game.Current = game;

            Resources.InitUserDirectory(Game.Current.Uid, commandLine[Resources.GamesManagerArguments.UserDirOverrideArgument]!=null);
            Logger.Current = new Logger(Path.Combine(Resources.GameUserDir, "GamesManagerLog.txt"));

            if (commandLine[Resources.GamesManagerArguments.RegisterArgument] != null)
            {
                Logger.Current.Write(LogInfoLevel.Info,"Registering game...");
                if (!UACControl.IsAdmin())
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Registering requires administrator access");
                    ViewFactory.Current.CreateView<IMessage>().Show("Registering requires administrator access", "Administrator access required");
                    return -1;
                }

                var installer = new GameRegistrar(true, Game.Current);
                return installer.Start()==LongRunningTaskResult.Completed ? 0: -1;
            }
            else if (commandLine[Resources.GamesManagerArguments.DeregisterArgument] != null)
            {
                Logger.Current.Write(LogInfoLevel.Info, "Deregistering game...");
                if (!UACControl.IsAdmin())
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Deregistering requires administrator access");
                    ViewFactory.Current.CreateView<IMessage>().Show("Deregistering requires administrator access", "Administrator access required");
                    return -1;
                }

                var uninstaller = new GameRegistrar(false, Game.Current);
                return uninstaller.Start() == LongRunningTaskResult.Completed ? 0 : -1;
            }
            else if (commandLine[Resources.GamesManagerArguments.UpdateFrameworkArgument] != null || commandLine[Resources.GamesManagerArguments.UpdateGameArgument] != null)
            {
                Logger.Current.Write(LogInfoLevel.Info, "Updating game/framework...");

                if (commandLine[Resources.GamesManagerArguments.UpdateFrameworkArgument] != null &&
                    commandLine[Resources.GamesManagerArguments.FrameworkUpdateHashArgument]==null)
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Framework update MD5 hash argument missing");
                    ViewFactory.Current.CreateView<IMessage>().Show("Framework update MD5 hash argument missing", "Missing argument");
                    return -1;
                }

                if (commandLine[Resources.GamesManagerArguments.UpdateGameArgument] != null &&
                    commandLine[Resources.GamesManagerArguments.GameUpdateHashArgument] == null)
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Game update MD5 hash argument missing");
                    ViewFactory.Current.CreateView<IMessage>().Show("Game update MD5 hash argument missing", "Missing argument");
                    return -1;
                }

                if (!UACControl.IsAdmin())
                {
                    Logger.Current.Write(LogInfoLevel.Error, "Updating requires administrator access");
                    ViewFactory.Current.CreateView<IMessage>().Show("Updating requires administrator access", "Administrator access required");
                    return -1;
                }

                var presenter = new UpdateGamePresenter(
                    commandLine[Resources.GamesManagerArguments.UpdateGameArgument],
                    commandLine[Resources.GamesManagerArguments.GameUpdateHashArgument],
                    commandLine[Resources.GamesManagerArguments.UpdateFrameworkArgument],
                    commandLine[Resources.GamesManagerArguments.FrameworkUpdateHashArgument]);
                presenter.ShowView();
                Application.Run(presenter.View as Form);

                Process.Start(Resources.FrameworkUpdaterExecutable, Resources.GamesManagerBootArguments(string.Empty,string.Empty,string.Empty,string.Empty));
            }
            else
            {
                Logger.Current.Write(LogInfoLevel.Info, "Launching game...");
                var presenter = new LaunchGamePresenter(commandLine[Resources.GamesManagerArguments.NoUpdateCheckArgument] == null);
                presenter.ShowView();
                Application.Run(presenter.View as Form);
            }

            return 0;
        }
Exemplo n.º 15
0
        public void TestCheckForUpdateAndDownloadUpdateWithAuthCachedCredentials()
        {
            Resources.InitUserDirectory("Console", false);

            //lets pretend that this game is already installed.
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));

            SettingsManager.Instance.Settings = new GameSettings();
            SettingsManager.Instance.Settings.GameUid = "Console";
            SettingsManager.Instance.Settings.UserName = "******";
            SettingsManager.Instance.Settings.Password = "******";
            SettingsManager.Instance.Save();

            var newGameData = GenerateDataBlock(65536);
            var gameMd5 = GenerateMd5Hash(newGameData);

            ((MockHttpRequestManager)HttpRequestManager.Current).SetCredentials("http://www.junkship.net/downloads/console.zip", "user", "password1");
            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://www.junkship.net/downloads/console.zip", newGameData);
            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://games.junkship.org/gamesource.asmx", @"{
            ""Latest"":{
            ""Version"":""1.1.2.4"",
            ""Url"":""http://www.junkship.net/downloads/console.zip"",
            ""MD5"":""" + gameMd5 + @"""
            }
            }");

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            var update = UpdateChecker.CheckForUpdate(game);

            Assert.IsNotNull(update);
            Assert.IsNotNull(update.Game);
            Assert.AreEqual("http://www.junkship.net/downloads/console.zip", update.Game.Url);
            Assert.AreEqual(gameMd5, update.Game.MD5);
            Assert.AreEqual("1.1.2.4", update.Game.Version);

            Assert.IsFalse(FileSystem.Current.GetFile("c:\\temp.zip").Exists);

            //now download the actual update.
            GameDownloader downloader = new GameDownloader(game, "http://www.junkship.net/downloads/console.zip", "c:\\temp.zip", gameMd5, args=>
                                           {
                                               Assert.Fail("With correct cached credentials the credentials callback shouldn't be invoked.");
                                               return false;
                                           });
            downloader.Start();

            Assert.IsTrue(FileSystem.Current.GetFile("c:\\temp.zip").Exists);
            Assert.AreEqual(65536, FileSystem.Current.GetFile("c:\\temp.zip").Length);
        }
Exemplo n.º 16
0
        public void TestUpdateLocalGameWithFullInstaller(bool includeGdfDll)
        {
            MockArchiveFile archive = new MockArchiveFile(null, "C:\\Documents and Settings\\user\\desktop\\game.zip");
            new MockArchiveFile(archive, "game.json", ReadTextFile("console.json"));
            new MockArchiveFile(archive, "preferences.json", ReadTextFile("preferences.json"));
            if (includeGdfDll)
            {
                new MockArchiveFile(archive, "gdf.dll", "GAMES_EXPLORER_DEFINITION");
            }
            new MockArchiveFile(archive, "content");
            new MockArchiveFile(archive, "bin");
            ((MockArchiveFactory)ArchiveFactory.Current).VirtualArchives.Add("C:\\Documents and Settings\\user\\desktop\\game.zip", archive);

            var gameInstall = new GameInstall("C:\\Documents and Settings\\user\\desktop\\game.zip");
            Assert.IsTrue(gameInstall.IsValid);

            GameUpdater updater = new GameUpdater(gameInstall);
            updater.Start();

            //check that all the games content was copied across
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Exists);
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").Exists);
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\preferences.json").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game\\content").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game\\bin").Exists);

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            Assert.IsTrue(game.IsValid);

            var key = Registry.Current.CreateSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");

            GameRegistrar registrar = new GameRegistrar(true, game);
            registrar.Start();

            //assert the shortcuts are in the right place
            key = Registry.Current.OpenSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");
            Assert.IsNotNull(key);
            Assert.AreEqual("c:\\program files\\MGDF\\resources\\gamesystemicon.ico", key.GetValue("DisplayIcon"));
            Assert.AreEqual("Lua Console", key.GetValue("DisplayName"));
            Assert.AreEqual("http://www.junkship.org", key.GetValue("URLInfoAbout"));
            Assert.AreEqual(1, key.GetDwordValue("NoModify"));
            Assert.AreEqual(1, key.GetDwordValue("NoRepair"));
            Assert.AreEqual("no8 interactive", key.GetValue("Publisher"));
            Assert.AreEqual("c:\\program files\\MGDF\\game", key.GetValue("InstallLocation"));
            Assert.AreEqual("0.1", key.GetValue("DisplayVersion"));

            //assert the shortcuts are in the right place
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\desktop\\Lua Console.lnk").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\Documents and Settings\\user\\start menu\\no8 interactive").Exists);
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\start menu\\no8 interactive\\Lua Console.lnk").Exists);

            //assert the the game has been added to the games explorer
            Assert.AreEqual(includeGdfDll, GameExplorer.Current.IsInstalled("c:\\program files\\MGDF\\game\\gdf.dll"));

            //deregister the game
            registrar = new GameRegistrar(false, game);
            registrar.Start();

            //assert the shortcut has been removed
            key = Registry.Current.OpenSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");
            Assert.IsNull(key);

            //shortcuts should have been removed
            Assert.IsFalse(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\desktop\\Lua Console.lnk").Exists);
            Assert.IsFalse(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\start menu\\no8 interactive\\Lua Console.lnk").Exists);

            if (includeGdfDll)
            {
                //assert the the game has been removed from the games explorer
                Assert.IsTrue(!GameExplorer.Current.IsInstalled("c:\\program files\\MGDF\\game\\gdf.dll"));
            }
        }
Exemplo n.º 17
0
        public void TestInstallLocalUpdateToInstalledGame()
        {
            //lets pretend that this game is already installed.
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game\\content").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\content\\test.json").WriteText("blah");
            Registry.Current.CreateSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");

            MockArchiveFile archive = new MockArchiveFile(null, "C:\\Documents and Settings\\user\\desktop\\game.zip");
            new MockArchiveFile(archive, "game.json", @"{
              ""gameuid"":""Console"",
              ""gamename"":""Lua Console"",
              ""description"":""A Lua command console for interacting with the MGDF system"",
              ""version"":""1.0.0.0"",
              ""interfaceversion"":""1"",
              ""developeruid"":""no-8"",
              ""developername"":""no8 interactive"",
              ""homepage"":""http://www.junkship.org"",
              ""gamesourceservice"":""http://games.junkship.org/gamesource.asmx"",
              ""statisticsservice"":""http://statistics.junkship.org/statisticsservice.asmx"",
              ""statisticsprivacypolicy"":""We wont use ur informationz"",
              ""supportemail"":""*****@*****.**""
            }");
            new MockArchiveFile(archive, "update.json", ReadTextFile("update.json"));
            new MockArchiveFile(archive, "content");
            new MockArchiveFile(archive, "bin");
            ((MockArchiveFactory)ArchiveFactory.Current).VirtualArchives.Add("C:\\Documents and Settings\\user\\desktop\\game.zip", archive);

            GameInstall install = new GameInstall("C:\\Documents and Settings\\user\\desktop\\game.zip");
            Assert.IsTrue(install.IsValid);

            GameUpdater updater = new GameUpdater(install);
            updater.Start();

            //check that all the games content was copied across
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Exists);
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game\\content").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game\\bin").Exists);
            //did the update remove the file specified
            Assert.IsFalse(FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\content\\test.json").Exists);

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            Assert.IsTrue(game.IsValid);

            GameRegistrar registrar = new GameRegistrar(true, game);
            registrar.Start();

            //assert the shortcuts are in the right place
            var key = Registry.Current.OpenSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");
            Assert.IsNotNull(key);
            Assert.AreEqual("c:\\program files\\MGDF\\resources\\gamesystemicon.ico", key.GetValue("DisplayIcon"));
            Assert.AreEqual("Lua Console", key.GetValue("DisplayName"));
            Assert.AreEqual("http://www.junkship.org", key.GetValue("URLInfoAbout"));
            Assert.AreEqual(1, key.GetDwordValue("NoModify"));
            Assert.AreEqual(1, key.GetDwordValue("NoRepair"));
            Assert.AreEqual("no8 interactive", key.GetValue("Publisher"));
            Assert.AreEqual("c:\\program files\\MGDF\\game", key.GetValue("InstallLocation"));
            Assert.AreEqual("1.0.0.0", key.GetValue("DisplayVersion"));

            //assert the shortcuts are in the right place
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\desktop\\Lua Console.lnk").Exists);
            Assert.IsTrue(FileSystem.Current.GetDirectory("c:\\Documents and Settings\\user\\start menu\\no8 interactive").Exists);
            Assert.IsTrue(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\start menu\\no8 interactive\\Lua Console.lnk").Exists);

            registrar = new GameRegistrar(false, game);
            registrar.Start();

            //assert the registry key has been removed
            key = Registry.Current.OpenSubKey(BaseRegistryKey.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MGDF1_Console");
            Assert.IsNull(key);

            //shortcuts should have been removed
            Assert.IsFalse(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\desktop\\Lua Console.lnk").Exists);
            Assert.IsFalse(FileSystem.Current.GetFile("c:\\Documents and Settings\\user\\start menu\\no8 interactive\\Lua Console.lnk").Exists);
        }
Exemplo n.º 18
0
        public void TestCheckForUpdatePartialUpdatesAvailable()
        {
            //lets pretend that this game is already installed.
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));

            var newGameData = GenerateDataBlock(65536);
            var gameMd5 = GenerateMd5Hash(newGameData);

            ((MockHttpRequestManager)HttpRequestManager.Current).ExpectResponse("http://games.junkship.org/gamesource.asmx", @"{
            ""Latest"":{
            ""Version"":""1.1.2.4"",
            ""Url"":""http://www.junkship.net/downloads/console.zip"",
            ""MD5"":""" + gameMd5 + @"""
            },
            ""UpdateOlderVersions"":[
            {
            ""Url"":""http://www.junkship.net/downloads/console-update.zip"",
            ""MD5"":""" + gameMd5 + @""",
            ""FromVersion"":""0.1""
            },
            {
            ""Url"":""http://www.junkship.net/downloads/console-update1.zip"",
            ""MD5"":""" + gameMd5 + @""",
            ""FromVersion"":""0.1.1.1""
            }
            ]
            }");

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            var update = UpdateChecker.CheckForUpdate(game);

            Assert.IsNotNull(update);
            Assert.IsNotNull(update.Game);
            Assert.AreEqual("http://www.junkship.net/downloads/console-update.zip", update.Game.Url);
            Assert.AreEqual(gameMd5, update.Game.MD5);
            Assert.AreEqual("1.1.2.4", update.Game.Version);
        }
Exemplo n.º 19
0
        public void TestCheckForUpdateNoUpdatesAvailable()
        {
            //lets pretend that this game is already installed.
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            var update = UpdateChecker.CheckForUpdate(game);

            Assert.IsNotNull(update);
            Assert.IsNull(update.Game);
        }
Exemplo n.º 20
0
        public void TestCheckForUpdateNoUpdateAvailable()
        {
            FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create();
            FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json"));

            MockFile gamesManagerFile = (MockFile)FileSystem.Current.GetFile("C:\\program files\\MGDF\\GamesManager.exe");
            gamesManagerFile.WriteText("EXECUTABLE");
            gamesManagerFile.AssemblyVersion = new Version(1, 0, 0, 0);

            Game game = new Game("c:\\program files\\MGDF\\game\\game.json");
            AvailableUpdates update = UpdateChecker.CheckForUpdate(game);

            Assert.IsNotNull(update);
            Assert.IsNull(update.Framework);
        }
Exemplo n.º 21
0
        public void TestGetStatisticsPermissionNoCachedPermission(bool allow)
        {
            const string gmeContent = @"{
              ""gameuid"":""Console"",
              ""gamename"":""Lua Console"",
              ""description"":""A Lua command console for interacting with the MGDF system"",
              ""version"":""0.1"",
              ""interfaceversion"":""1"",
              ""developeruid"":""no-8"",
              ""developername"":""no8 interactive"",
              ""homepage"":""http://www.junkship.org"",
              ""gamesourceservice"":""http://games.junkship.org/gamesource.asmx"",
              ""statisticsservice"":""http://statistics.junkship.org/statisticsservice.asmx"",
              ""statisticsprivacypolicy"":""http://www.junkship.org/privacy"",
              ""supportemail"":""*****@*****.**""
            }";

            MockDirectory gameDirectory = ((MockDirectory)MockFileSystem.GetDirectory(EnvironmentSettings.Current.AppDirectory + "\\game"));
            gameDirectory.AddFile("game.json", gmeContent);
            Game game = new Game(Path.Combine(EnvironmentSettings.Current.AppDirectory, "game\\game.json"));

            Resources.InitUserDirectory("Console", false);

            Assert.AreEqual(allow,StatisticsSession.GetStatisticsPermission(game, args => allow));

            Assert.AreEqual(SettingsManager.Instance.Settings.GameUid,"Console");
            Assert.AreEqual(allow,SettingsManager.Instance.Settings.StatisticsServiceEnabled.Value);
        }
Exemplo n.º 22
0
        public void TestGetStatisticsPermissionCachedPermission()
        {
            const string gmeContent = @"{
              ""gameuid"":""Console"",
              ""gamename"":""Lua Console"",
              ""description"":""A Lua command console for interacting with the MGDF system"",
              ""version"":""0.1"",
              ""interfaceversion"":""1"",
              ""developeruid"":""no-8"",
              ""developername"":""no8 interactive"",
              ""homepage"":""http://www.junkship.org"",
              ""gamesourceservice"":""http://games.junkship.org/gamesource.asmx"",
              ""statisticsservice"":""http://statistics.junkship.org/statisticsservice.asmx"",
              ""statisticsprivacypolicy"":""http://www.junkship.org/privacy"",
              ""supportemail"":""*****@*****.**""
            }";

            MockDirectory gameDirectory = ((MockDirectory)MockFileSystem.GetDirectory(EnvironmentSettings.Current.AppDirectory + "\\game"));
            gameDirectory.AddFile("game.json", gmeContent);
            Game game = new Game(Path.Combine(EnvironmentSettings.Current.AppDirectory, "game\\game.json"));

            Resources.InitUserDirectory("Console", false);
            SettingsManager.Instance.Settings = new GameSettings();
            SettingsManager.Instance.Settings.GameUid = "Console";
            SettingsManager.Instance.Settings.StatisticsServiceEnabled = true;
            SettingsManager.Instance.Save();

            Assert.IsTrue(StatisticsSession.GetStatisticsPermission(game, args =>
                                                               {
                                                                   Assert.Fail("This get permission callback shouldn't be called when the permission has been cached");
                                                                   return false;
                                                               }));
        }