Beispiel #1
0
        private void UpdatePartialGame(GameInstall installer)
        {
            IDirectory gameDir        = FileSystem.Current.GetDirectory(Resources.GameBaseDir);
            IDirectory gameContentDir = FileSystem.Current.GetDirectory(FileSystem.Combine(Resources.GameBaseDir, Resources.ContentDir));
            IDirectory gameModulesDir = FileSystem.Current.GetDirectory(FileSystem.Combine(Resources.GameBaseDir, Resources.BinDir));

            //only allow files/dirs inside the modules/content directories to be removed by the removal process.
            foreach (string s in installer.Update.RemoveFiles)
            {
                IFile file = FileSystem.Current.GetFile(FileSystem.Combine(gameDir.FullName, s));
                if (file.Exists && (ExistsInsideGameDirectory(file, gameContentDir) || ExistsInsideGameDirectory(file, gameModulesDir)))
                {
                    file.DeleteWithTimeout();
                    continue;
                }

                IDirectory dir = FileSystem.Current.GetDirectory(FileSystem.Combine(gameDir.FullName, s));
                if (dir.Exists && (ExistsInsideGameDirectory(dir, gameContentDir) || ExistsInsideGameDirectory(dir, gameModulesDir)))
                {
                    dir.DeleteWithTimeout();
                }
            }

            UpdateFullGame(installer);
        }
Beispiel #2
0
 private bool ValidateInstaller(GameInstall install)
 {
     if (!install.IsValid)
     {
         foreach (var error in _installer.ErrorCollection)
         {
             Logger.Current.Write(LogInfoLevel.Error, "Unable to install Game - " + error);
         }
         return(false);
     }
     return(true);
 }
Beispiel #3
0
 private static bool ValidateInstaller(string installerFile, PackageMetadata data)
 {
     Console.WriteLine("Validating installer package " + installerFile);
     using (GameInstall install = new GameInstall(installerFile))
     {
         using (Stream stream = new FileStream(installerFile, FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             data.MD5 = stream.ComputeMD5();
         }
         return(ValidateInstaller(install, data));
     }
 }
Beispiel #4
0
        public void TestLoadInvalidGame()
        {
            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"));
            new MockArchiveFile(archive, "bin");
            //missing content
            ((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.IsFalse(install.IsValid);
        }
Beispiel #5
0
 private static bool ValidateInstaller(GameInstall install, PackageMetadata data)
 {
     if (install.ErrorCollection.Count > 0)
     {
         foreach (var error in install.ErrorCollection)
         {
             Console.WriteLine("Error: " + error);
         }
         Console.WriteLine("Error: Installer package creation failed.");
         return(false);
     }
     else if (data != null)
     {
         data.Version = install.Game.Version;
     }
     return(true);
 }
Beispiel #6
0
 private static bool ValidateNonUpdateInstaller(string installerFile, out GameInstall install)
 {
     Console.WriteLine("Validating installer package " + installerFile);
     install = new GameInstall(installerFile);
     if (ValidateInstaller(install, null))
     {
         if (install.IsUpdate)
         {
             Console.WriteLine("Error: Cannot use update installers as the basis for creating an update.");
             install.Dispose();
             return(false);
         }
         return(true);
     }
     install.Dispose();
     return(false);
 }
Beispiel #7
0
        public void LoadGameInstaller()
        {
            MockDirectory desktopDir = (MockDirectory)MockFileSystem.GetDirectory("C:\\Documents and Settings\\user\\desktop");

            desktopDir.AddFile("game.zip", "data");


            MockArchiveFile archive = new MockArchiveFile(null, "C:\\Documents and Settings\\user\\desktop\\game.mza");

            new MockArchiveFile(archive, "game.json", ReadTextFile("console.json"));
            new MockArchiveFile(archive, "preferences.json", ReadTextFile("preferences.json"));
            new MockArchiveFile(archive, "content");
            new MockArchiveFile(archive, "bin");
            ((MockArchiveFactory)ArchiveFactory.Current).VirtualArchives.Add("C:\\Documents and Settings\\user\\desktop\\game.mza", archive);

            GameInstall install = new GameInstall("C:\\Documents and Settings\\user\\desktop\\game.mza");

            Assert.IsNotNull(install);
            Assert.IsTrue(install.IsValid);

            Assert.AreEqual("http://games.junkship.org/gamesource.asmx", install.Game.UpdateService);
            Assert.AreEqual("http://www.junkship.org", install.Game.Homepage);
            Assert.AreEqual(1, install.Game.InterfaceVersion);
            Assert.IsFalse(install.IsUpdate);
            Assert.AreEqual("Lua Console", install.Game.Name);
            Assert.AreEqual("We wont use ur informationz", install.Game.StatisticsPrivacyPolicy);
            Assert.AreEqual("http://statistics.junkship.org/statisticsservice.asmx", install.Game.StatisticsService);
            Assert.AreEqual("*****@*****.**", install.Game.SupportEmail);
            Assert.AreEqual("Console", install.Game.Uid);
            Assert.AreEqual(new Version(0, 1), install.Game.Version);

            Assert.IsNull(install.Update);
            Assert.IsFalse(install.IsUpdate);

            Assert.AreEqual("C:\\Documents and Settings\\user\\desktop\\game.mza", install.InstallerFile);
        }
Beispiel #8
0
        private void UpdateFullGame(GameInstall installer)
        {
            IDirectory gameDir = FileSystem.Current.GetDirectory(Resources.GameBaseDir);

            if (!gameDir.Exists)
            {
                gameDir.Create();
            }

            IArchiveFile gameConfig = installer.GameContents.GetFile(Resources.GameConfig);
            IArchiveFile contentDir = installer.GameContents.GetFile(Resources.ContentDir);
            IArchiveFile binDir     = installer.GameContents.GetFile(Resources.BinDir);
            IArchiveFile imageFile  = null;

            if (installer.Game.GameIconData != null)
            {
                imageFile = installer.GameContents.GetFile(Resources.GameIcon);
            }
            IArchiveFile gdfFile         = installer.GameContents.GetFile(Resources.GameDefinitionFileBinary);
            IArchiveFile preferencesFile = installer.GameContents.GetFile(Resources.PreferencesConfig);

            var vfsUtils = new ArchiveFileHelper();

            var total = ArchiveFileHelper.GetSubTreeData(gameConfig).BytesCount;

            total += ArchiveFileHelper.GetSubTreeData(contentDir).BytesCount;
            total += ArchiveFileHelper.GetSubTreeData(binDir).BytesCount;
            total += ArchiveFileHelper.GetSubTreeData(imageFile).BytesCount;
            total += ArchiveFileHelper.GetSubTreeData(gdfFile).BytesCount;
            total += ArchiveFileHelper.GetSubTreeData(preferencesFile).BytesCount;

            uint uTotal = total > uint.MaxValue ? uint.MaxValue : (uint)total;

            Total = uTotal;

            vfsUtils.OnCopyProgress += (sender, e) => Progress += (uint)e.BytesCopied;

            vfsUtils.CopyVfsFile(gameConfig, FileSystem.Combine(Resources.GameBaseDir, Resources.GameConfig));

            if (contentDir != null)
            {
                vfsUtils.CopyVfsSubtree(contentDir, Resources.GameBaseDir, false);
            }

            if (binDir != null)
            {
                vfsUtils.CopyVfsSubtree(binDir, Resources.GameBaseDir, false);
            }

            if (imageFile != null)
            {
                vfsUtils.CopyVfsFile(imageFile, FileSystem.Combine(Resources.GameBaseDir, Resources.GameIcon));
                IconManager.Current.CreateIcon(installer.Game.Name, FileSystem.Combine(Resources.GameBaseDir, Resources.GameIcon), FileSystem.Combine(Resources.GameBaseDir, Resources.GameSystemIcon));
            }

            if (gdfFile != null)
            {
                vfsUtils.CopyVfsFile(gdfFile, FileSystem.Combine(Resources.GameBaseDir, Resources.GameDefinitionFileBinary));
            }

            if (preferencesFile != null)
            {
                vfsUtils.CopyVfsFile(preferencesFile, FileSystem.Combine(Resources.GameBaseDir, Resources.PreferencesConfig));
            }
        }
Beispiel #9
0
 public GameUpdater(GameInstall installer)
 {
     _installer = installer;
 }
Beispiel #10
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);
        }
Beispiel #11
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"));
            }
        }
Beispiel #12
0
        private void DoWork()
        {
            try
            {
                Resources.InitUpdaterDirectories();

                if (_frameworkUpdate != null)
                {
                    string frameworkFile = Path.Combine(Resources.DownloadsDir, "framework.zip");
                    try
                    {
                        lock (_lock)
                        {
                            Logger.Current.Write(LogInfoLevel.Info, "Downloading framework update...");
                            _currentDownloader = new FileDownloader(_frameworkUpdate, frameworkFile, _frameworkUpdateHash, null);
                            _currentTask       = _currentDownloader;
                            View.Invoke(() =>
                            {
                                View.Details     = "Downloading MGDF framework update...";
                                View.AllowCancel = true;
                            });
                        }
                        var result = _currentDownloader.Start();

                        lock (_lock)
                        {
                            _currentDownloader = null;
                            View.Invoke(() => View.AllowCancel = false);
                        }

                        if (result == LongRunningTaskResult.Cancelled)
                        {
                            _workerThread = null;
                            View.Invoke(CloseView);
                            return;
                        }
                        else if (result == LongRunningTaskResult.Error)
                        {
                            //show an error message, though we may still be able to download a game update, so don't bail out yet.
                            ShowError("Download failed", "Failed to download MGDF framework update");
                        }
                        else
                        {
                            lock (_lock)
                            {
                                Logger.Current.Write(LogInfoLevel.Info, "Installing framework update...");
                                //success, now try to install the downloaded update
                                View.Invoke(() => View.Details = "Installing MGDF framework update...");
                                _currentTask = new FrameworkUpdater(frameworkFile);
                            }
                            result = _currentTask.Start();

                            if (result == LongRunningTaskResult.Error)
                            {
                                //show an error message, though we may still be able to download a game update, so don't bail out yet.
                                ShowError("Install failed", "Failed to install MGDF framework update");
                            }
                            else
                            {
                                View.Invoke(() => View.Details = "Installing framework dependencies...");
                                DependencyInstaller.Install();
                            }
                        }
                    }
                    finally
                    {
                        var file = FileSystem.Current.GetFile(frameworkFile);
                        if (file.Exists)
                        {
                            file.DeleteWithTimeout();
                        }
                    }
                }

                if (_gameUpdate != null)
                {
                    string gameUpdateFile = Path.Combine(Resources.DownloadsDir, "update.zip");
                    try
                    {
                        lock (_lock)
                        {
                            Logger.Current.Write(LogInfoLevel.Info, "Downloading game update...");
                            _currentDownloader = new GameDownloader(Game.Current, _gameUpdate, gameUpdateFile, _gameUpdateHash, GetUpdateCredentials);
                            _currentTask       = _currentDownloader;
                            View.Invoke(() =>
                            {
                                View.Details     = "Downloading " + Game.Current.Name + " update...";
                                View.AllowCancel = true;
                            });
                        }
                        var result = _currentDownloader.Start();

                        lock (_lock)
                        {
                            _currentDownloader = null;
                            View.Invoke(() => View.AllowCancel = false);
                        }

                        if (result == LongRunningTaskResult.Cancelled)
                        {
                            _workerThread = null;
                            View.Invoke(CloseView);
                            return;
                        }
                        else if (result == LongRunningTaskResult.Error)
                        {
                            ShowError("Download failed", "Failed to download " + Game.Current.Name + " update");
                            _workerThread = null;
                            View.Invoke(CloseView);
                            return;
                        }
                        else
                        {
                            using (var gameInstall = new GameInstall(gameUpdateFile))
                            {
                                lock (_lock)
                                {
                                    Logger.Current.Write(LogInfoLevel.Info, "Installing " + Game.Current.Name + " update...");
                                    //success, now try to apply the downloaded update
                                    View.Invoke(() => View.Details = "Installing " + Game.Current.Name + " update...");
                                    _currentTask = new GameUpdater(gameInstall);
                                }
                                result = _currentTask.Start();

                                if (result == LongRunningTaskResult.Error)
                                {
                                    ShowError("Install failed", "Failed to install " + Game.Current.Name + " update");
                                }
                            }

                            //now if we're auto installing on update, update the registry/desktop icons etc..
                            if (Config.Current.AutoRegisterOnUpdate)
                            {
                                lock (_lock)
                                {
                                    Logger.Current.Write(LogInfoLevel.Info, "Registering game update...");
                                    _currentTask = new GameRegistrar(true, Game.Current);
                                }
                                result = _currentTask.Start();
                                if (result == LongRunningTaskResult.Error)
                                {
                                    ShowError("Registration failed", "Failed to register " + Game.Current.Name + " update");
                                }
                            }
                        }
                    }
                    finally
                    {
                        var file = FileSystem.Current.GetFile(gameUpdateFile);
                        if (file.Exists)
                        {
                            file.DeleteWithTimeout();
                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                View.Invoke(() => Program.ShowUnhandledError(ex));
            }

            _workerThread = null;
            View.Invoke(CloseView);
        }