public bool TryGetFile(ContentStorage loc, GameDirectory gameDir, string filename, out FileInfo file, string ext = null) { Contract.Requires(!string.IsNullOrEmpty(filename)); file = null; return(loc == ContentStorage.UpdateOrGame ? TryGetFileFromUpdateOrGame(gameDir, filename, out file, ext) : TryGetFileImpl(loc, gameDir, filename, out file, ext)); }
public void SerializeAndDeserializeJsonFromGameDirectory() { // given var gameDirectory = new GameDirectory(); // when var json = Serializer.SerializeJson(gameDirectory); var gameDirectory2 = Serializer.DeserializeJson <GameDirectory>(json); // then Assert.AreEqual(gameDirectory, gameDirectory2); }
public void FindNewGamesWithoutNewGames() { // given var appDataPathExtended = SetUp(TestContext.CurrentContext.Test.Name); var gameDirectory = new GameDirectory(appDataPathExtended); // when var newGames = DirectorySearchHelper.FindNewGames(gameDirectory); // then CollectionAssert.IsEmpty(newGames); }
public static List <Game> FindNotExistingGames(GameDirectory gameDirectory) { List <Game> notExistingGameList = new List <Game>(); foreach (Game g in gameDirectory.GetGames()) { if (!Directory.Exists(g.DirectoryPath)) { notExistingGameList.Add(g); } } return(notExistingGameList); }
/// <summary> /// Refresh file list to catch all changes /// </summary> /// <summary xml:lang="ru"> /// Обновить окно файлов /// </summary> private void RefreshFileList() { if (mode == FileBrowserWindowMode.FILE_BROWSER) { GameDirectory curDir = currentDir; OpenRootDir(rootDir); OpenDir(curDir); } else { OpenArchive(archiveFile); } }
public void FindNotExistingGamesWithNoMissingGame() { // given var appDataPathExtended = SetUp(TestContext.CurrentContext.Test.Name); // when var gameDirectory = new GameDirectory(appDataPathExtended); var games = DirectorySearchHelper.FindNotExistingGames(gameDirectory); // then Assert.AreEqual(0, games.Count); Assert.AreEqual(2, gameDirectory.GetGames().Count); }
public static List <Game> FindNewGames(GameDirectory gameDirectory) { List <Game> gameList = new List <Game>(); foreach (Game g in GetAllGamesFromPath(gameDirectory.Directory)) { if (!gameDirectory.GetGames().Contains(g)) { gameList.Add(g); } } return(gameList); }
public void SaveAndLoadFromGameDirectory() { // given var gameDirectory = new GameDirectory(); var path = Path.Combine(appDataPath, "gameDirectory.bin"); // when Serializer.Save(path, gameDirectory); var gameDirectory2 = Serializer.Load <GameDirectory>(path); // then Assert.AreEqual(gameDirectory, gameDirectory2); }
/// <summary> /// Open directory in the file browser window /// </summary> /// <summary xml:lang="ru"> /// Открыть каталог в файловом менеджере /// </summary> /// <param name="dir">Directory to be opened</param> /// <param name="dir" xml:lang="ru">Каталог который необходимо открыть</param> public void OpenDir(GameDirectory dir, bool expand = false) { this.currentDir = dir; archiveFile = null; SwitchToDirMode(); if (expand) { ExpandDirectoryNode(dir); } SetFileListView(dir.GetContent()); Text = string.Format("OpenIII - [{0}]", currentDir.FullPath); }
public IEnumerable <string> GetFiles(ContentStorage loc, GameDirectory gameDir, string searchPattern) { Contract.Requires(loc != ContentStorage.UpdateOrGame, "Must iterate storages separately"); Contract.Requires(!string.IsNullOrEmpty(searchPattern)); string dir = GetAbsoluteDirectory(loc, gameDir); if (!Directory.Exists(dir)) { throw new DirectoryNotFoundException(dir); } return(Directory.EnumerateFiles(dir, searchPattern)); }
public virtual Task WriteHeader(SourceBufferWriter buf) { buf.Write(HeaderId); buf.Write(Protocol); buf.Write(NetworkProtocol); buf.WriteString(ServerName.AsSpan(), 260); buf.WriteString(ClientName.AsSpan(), 260); buf.WriteString(MapName.AsSpan(), 260); buf.WriteString(GameDirectory.AsSpan(), 260); buf.Write(PlaybackTime); buf.Write(PlaybackTicks); buf.Write(PlaybackFrames); buf.Write(SignOnLength); return(Task.CompletedTask); }
bool TryGetFileImpl(ContentStorage loc, GameDirectory gameDir, string filename, out FileInfo file, string ext = null) { file = null; string root = GetContentLocation(loc); string dir = GetDirectory(gameDir); string file_path = Path.Combine(root, dir, filename); if (!string.IsNullOrEmpty(ext)) { file_path += ext; } return((file = new FileInfo(file_path)).Exists); }
/// <summary> /// File tree view expand event handler /// </summary> /// <summary xml:lang="ru"> /// Обработчик события раскрытия ветки в дереве каталогов /// </summary> /// <param name="sender">Component that emitted the event</param> /// <param name="e">Event arguments</param> /// <param name="sender" xml:lang="ru">Указатель на компонент, который отправил событие</param> /// <param name="e" xml:lang="ru">Аргументы события</param> private void OnFileTreeViewExpand(object sender, TreeViewCancelEventArgs e) { GameDirectory dir = (GameDirectory)e.Node.Tag; UseWaitCursor = true; Application.DoEvents(); fileTreeView.BeginUpdate(); e.Node.Nodes.Clear(); e.Node.Nodes.AddRange(GetNodesList(dir.GetDirectories())); fileTreeView.EndUpdate(); UseWaitCursor = false; Application.DoEvents(); }
public void FindNotExistingGamesSuccessful() { // given var appDataPathExtended = SetUp(TestContext.CurrentContext.Test.Name); // when var gameDirectory = new GameDirectory(appDataPathExtended); Directory.Delete(Path.Combine(appDataPathExtended, "Test1"), true); var games = DirectorySearchHelper.FindNotExistingGames(gameDirectory); // then Assert.AreEqual(1, games.Count); Assert.AreEqual(2, gameDirectory.GetGames().Count); Assert.AreEqual(new Game(Path.Combine(appDataPathExtended, "Test1")), games[0]); }
/// <summary> /// Gets <see cref="TreeNode"/> from the <see cref="GameDirectory"/> object to apply /// it to the child hives of the directory tree /// </summary> /// <summary xml:lang="ru"> /// Получение <see cref="TreeNode"/> из <see cref="GameDirectory"/> для /// последующего использования в дочерних ветках дерева каталогов /// </summary> /// <param name="dir">Directory</param> /// <param name="dir" xml:lang="ru">Каталог</param> /// <returns>Tree node</returns> /// <returns xml:lang="ru">Элемент дерева</returns> public TreeNode CreateNode(GameDirectory dir) { TreeNode item = new TreeNode(dir.Name); item.Tag = dir; item.ImageKey = "dir"; if (dir.GetDirectories().Count != 0) { // To make node expandable we're adding an empty element. // When user expands it, we're removing this and query the actual child dir list item.Nodes.Add(""); } return(item); }
public void ReadDataFilesAsync(ContentStorage loc, GameDirectory gameDir, string searchPattern, Action <KSoft.IO.XmlElementStream, FA> streamProc, out System.Threading.Tasks.ParallelLoopResult result) { Contract.Requires(!string.IsNullOrEmpty(searchPattern)); result = System.Threading.Tasks.Parallel.ForEach(Directories.GetFiles(loc, gameDir, searchPattern), (filename) => { const FA k_mode = FA.Read; using (var s = new KSoft.IO.XmlElementStream(filename, k_mode, this)) { SetupStream(s); streamProc(s, k_mode); } }); }
/// <summary> /// Sets the new directory tree on the form /// </summary> /// <summary xml:lang="ru"> /// Показать новое дерево каталогов на форме /// </summary> /// <param name="rootdir">Root directory</param> /// <param name="rootdir" xml:lang="ru">Корневой каталог</param> public void SetDirListView(GameDirectory rootdir) { UseWaitCursor = true; Application.DoEvents(); fileTreeView.BeginUpdate(); fileTreeView.Nodes.Clear(); fileTreeView.ImageList = new ImageList(); fileTreeView.ImageList.Images.Add("dir", rootDir.SmallIcon); fileTreeView.Nodes.Add(CreateNode(rootDir)); fileTreeView.Nodes[0].Expand(); fileTreeView.EndUpdate(); UseWaitCursor = false; Application.DoEvents(); }
public void FindNewGamesSuccessful() { // given var appDataPathExtended = SetUp(TestContext.CurrentContext.Test.Name); var gameDirectory = new GameDirectory(appDataPathExtended); Directory.CreateDirectory(Path.Combine(appDataPathExtended, "Test3", "Test31")); using FileStream fs1 = File.Create(Path.Combine(appDataPathExtended, "Test3", "Test31", "test3.exe")); // when var newGames = DirectorySearchHelper.FindNewGames(gameDirectory); // then CollectionAssert.IsNotEmpty(newGames); CollectionAssert.Contains(newGames, new Game(Path.Combine(appDataPathExtended, "Test3"))); Assert.AreEqual(newGames.Count, 1); }
protected override void OnUpdate(TickEventArgs args) { base.OnUpdate(args); //Grab local player LocalPlayer.Reset(); ViewMatrix.Reset(); //GameRules.Reset(); PlayerResources.Reset(); ClientState.Reset(); GameDirectory.Reset(); BaseEntitites.Clear(); PlayersOld.Clear(); PlayersOld.CopyFrom(Players); Players.Clear(); Weapons.Clear(); //Load map if (ClientState.Value != null && ClientState.Value.Map.Value != null) { if (ClientState.Value.Map.Value != lastMap) { var path = Path.Combine(GameDirectory.Value, ClientState.Value.Map.Value); //try //{ lastMap = ClientState.Value.Map.Value; if (File.Exists(path)) { using (var str = new FileStream(path, FileMode.Open, FileAccess.Read)) { var bsp = new BSPFile(str); Map = bsp; } //}catch(Exception ex) //{ // Program.Logger.Error("Failed to parse map \"{0}\": {1}", path, ex.Message); //} } } } }
bool TryGetFileFromUpdateOrGame(GameDirectory gameDir, string filename, out FileInfo file, string ext = null) { file = null; if (!UseTitleUpdates) { return(TryGetFileImpl(ContentStorage.Game, gameDir, filename, out file, ext)); } ////////////////////////////////////////////////////////////////////////// // Try to get the file from the TU storage first string dir = GetDirectory(gameDir); string file_path = Path.Combine(dir, filename.ToLowerInvariant()); if (!string.IsNullOrEmpty(ext)) { file_path += ext; } string full_path; if (UpdateDirectoryIsValid) { full_path = Path.Combine(UpdateDirectory, file_path); file = new FileInfo(full_path); } ////////////////////////////////////////////////////////////////////////// // No update file exists, fall back to regular game storage if (file == null || !file.Exists) { full_path = Path.Combine(RootDirectory, file_path); file = new FileInfo(full_path); return(file.Exists); } return(true); }
/// <summary> /// Expand the <see cref="TreeNode"/> that is attached to the specified <see cref="GameDirectory"/> /// </summary> /// <summary xml:lang="ru"> /// Раскрыть <see cref="TreeNode"/>, которая закреплена за указанным каталогом <see cref="GameDirectory"/> /// </summary> /// <remarks> /// <see cref="ExpandDirectoryNode"/> calls itself to expand parent directory too, so it returns the <see cref="TreeNode"/> /// that was expanded. Then it searches for the <see cref="TreeNode"/> attached to the <see cref="GameDirectory"/> /// in children of the returned <see cref="TreeNode"/>, expands and selects it. /// </remarks> /// <remarks> /// <see cref="ExpandDirectoryNode"/> вызывает саму себя для того, чтобы также раскрыть родительский каталог. После раскрытия /// функция возвращает раскрытую <see cref="TreeNode"/>. После получения раскрытой ветки функция ищет в ней дочернюю ветку /// <see cref="TreeNode"/>, которая закреплена за <see cref="GameDirectory"/>, после чего раскрывает и выделяет её. /// </remarks> /// <param name="dir">Directory</param> /// <param name="dir" xml:lang="ru">Каталог</param> /// <returns>Opened tree node</returns> /// <returns xml:lang="ru">Раскрытая ветвь дерева</returns> public TreeNode ExpandDirectoryNode(GameDirectory dir) { DirectoryInfo info = new DirectoryInfo(dir.FullPath); if (dir.FullPath != rootDir.FullPath) { // If current dir is not root game dir, expand parent dir first TreeNode openedNode = ExpandDirectoryNode(new GameDirectory(info.Parent.FullName)); // Find associated tree node and expand it foreach (TreeNode node in openedNode.Nodes) { GameDirectory dirNode = (GameDirectory)node.Tag; if (dirNode.FullPath == dir.FullPath) { // AfterSelect is a temporary solution. We need some other more appropriate solution node.Expand(); fileTreeView.AfterSelect -= OnFileTreeViewDirSelect; fileTreeView.SelectedNode = node; fileTreeView.AfterSelect += OnFileTreeViewDirSelect; return(node); } } return(null); } else { // If this is root dir, expand and select it fileTreeView.Nodes[0].Expand(); fileTreeView.AfterSelect -= OnFileTreeViewDirSelect; fileTreeView.SelectedNode = fileTreeView.Nodes[0]; fileTreeView.AfterSelect += OnFileTreeViewDirSelect; return(fileTreeView.Nodes[0]); } }
// -------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Returns the filepath of the translation file (Language from settings) /// </summary> /// <returns></returns> public string GetTranslationFile() { string resFile = GameDirectory.GetTranslationFile(PAPIApplication.GetLanguage()); return(resFile); }
public DirectoryInfo GetGameDirectoryInfo(GameDirectory dir) { return(new DirectoryInfo(GetGameDirectory(dir))); }
public void RemoveGameDirectory(GameDirectory gameDirectory) { Device.RemoveGameDirectory(gameDirectory); }
// -------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Puts all saved games to the table /// </summary> private void ShowSavedGamesTranslation(ResXResourceSet resSet) { // Show all saved Games int rowNr = 1; foreach (PAPIGame game in _savedGames) { if (_shownGames.Contains(game)) { continue; } WfLogger.Log(this, LogLevel.DEBUG, "Added game to list of saved games: " + game._genre + ", " + game._dateOfLastSession.ToString()); // Add Genre gameTable.Controls.Add(new Label() { Text = TranslatedString(resSet, "genre_" + _savedGames[rowNr - 1]._genre.ToString().ToLower()), Anchor = AnchorStyles.Left | AnchorStyles.Top, Width = 250 }, 0, rowNr); // Date of creation label gameTable.Controls.Add(new Label() { Text = game._dateOfCreation.ToShortDateString(), Anchor = AnchorStyles.Left | AnchorStyles.Top, }, 1, rowNr); // Date of last save label gameTable.Controls.Add(new Label() { Text = game._dateOfLastSession.ToShortDateString(), Anchor = AnchorStyles.Left | AnchorStyles.Top, }, 2, rowNr); // Add show Game Button to current row Button showGameBtn = new Button() { Text = "", FlatStyle = FlatStyle.Flat, Anchor = AnchorStyles.Right | AnchorStyles.Top, Size = new Size(40, 40), Name = "load_game_button_" + rowNr }; string imagePath = GameDirectory.GetFilePath_Images(PAPIApplication.GetDesign()) + "\\show.bmp"; Image image = Image.FromFile(imagePath); showGameBtn.Image = (Image)(new Bitmap(image, new Size(40, 40))); _gameButtons.Add(game, showGameBtn); gameTable.Controls.Add(showGameBtn, 2, rowNr++); _buttons.Add(showGameBtn); _shownGames.Add(game); } // Set size of each row to same foreach (RowStyle rowStyle in gameTable.RowStyles) { rowStyle.SizeType = SizeType.Absolute; rowStyle.Height = 44; } _buttons.Add(return_button); _buttons.Add(game_creator_button); SetButtonDesign(); // Add eventhandler for click on every show game button foreach (KeyValuePair <PAPIGame, Button> button in _gameButtons) { button.Value.Click += Load_Game_Button_Click; } }
/// <summary> /// Set root directory in the file browser window /// </summary> /// <summary xml:lang="ru"> /// Установить новый корневой каталог в файловом менеджере /// </summary> /// <param name="rootDir">Directory to be opened</param> /// <param name="rootDir" xml:lang="ru">Каталог который необходимо открыть</param> public void OpenRootDir(GameDirectory rootDir) { this.rootDir = rootDir; SetDirListView(rootDir); OpenDir(rootDir); }