/// <summary>
    /// Synchronizes the texture info for the selected game data directory
    /// </summary>
    /// <returns>The task</returns>
    public async Task SyncTextureInfoAsync()
    {
        OpenSpaceGameModeInfoAttribute attr = GameModeSelection.SelectedValue.GetAttribute <OpenSpaceGameModeInfoAttribute>();

        DirectoryBrowserResult result = await Services.BrowseUI.BrowseDirectoryAsync(new DirectoryBrowserViewModel()
        {
            Title            = Resources.Utilities_SyncTextureInfo_SelectDirHeader,
            DefaultDirectory = attr.Game?.GetInstallDir(false) ?? FileSystemPath.EmptyPath
        });

        if (result.CanceledByUser)
        {
            return;
        }

        try
        {
            IsLoading = true;

            TextureInfoEditResult syncResult = await Task.Run(() =>
            {
                // Get the settings
                OpenSpaceSettings gameSettings = attr.GetSettings();

                // Get the file extension for the level data files
                var fileExt = GetLevelFileExtension(gameSettings);

                // Get the level data files
                var dataFiles = Directory.GetFiles(result.SelectedDirectory, $"*{fileExt}", SearchOption.AllDirectories).Select(x => new FileSystemPath(x));

                // Get the .cnt file names
                var fileNames = GetCntFileNames(gameSettings);

                // Get the full paths and only keep the ones which exist
                var cntFiles = fileNames.Select(x => result.SelectedDirectory + x).Where(x => x.FileExists);

                // Sync the texture info
                return(EditTextureInfo(gameSettings, dataFiles, cntFiles));
            });

            await Services.MessageUI.DisplaySuccessfulActionMessageAsync(String.Format(Resources.Utilities_SyncTextureInfo_Success, syncResult.EditedTextures, syncResult.TotalTextures));
        }
        catch (Exception ex)
        {
            Logger.Error(ex, "Syncing texture info");

            await Services.MessageUI.DisplayExceptionMessageAsync(ex, Resources.Utilities_SyncTextureInfo_Error);
        }
        finally
        {
            IsLoading = false;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Synchronizes the texture info for the selected game data directory
    /// </summary>
    /// <returns>The task</returns>
    public async Task SyncTextureInfoAsync()
    {
        try
        {
            IsLoading = true;

            TextureInfoEditResult syncResult = await Task.Run(() =>
            {
                // Get the game install directory
                FileSystemPath installDir = Game.GetInstallDir();

                // Get the settings
                OpenSpaceGameModeInfoAttribute attr = GameMode.GetAttribute <OpenSpaceGameModeInfoAttribute>();
                OpenSpaceSettings gameSettings      = attr.GetSettings();

                // Get the file extension for the level data files
                string fileExt = GetLevelFileExtension(gameSettings);

                // Get the level data files
                IEnumerable <FileSystemPath> dataFiles = GameDataDirNames.
                                                         Select(x => Directory.GetFiles(installDir + x, $"*{fileExt}", SearchOption.AllDirectories).
                                                                Select(y => new FileSystemPath(y))).
                                                         SelectMany(x => x);

                // Get the .cnt file names
                string[] fileNames = GetCntFileNames(gameSettings);

                // Get the full paths and only keep the ones which exist
                IEnumerable <FileSystemPath> cntFiles = GameDataDirNames.
                                                        Select(dataDir => fileNames.
                                                               Select(cnt => installDir + dataDir + cnt).
                                                               Where(cntPath => cntPath.FileExists)).
                                                        SelectMany(x => x);

                // Sync the texture info
                return(EditTextureInfo(gameSettings, dataFiles, cntFiles));
            });

            await Services.MessageUI.DisplaySuccessfulActionMessageAsync(String.Format(Resources.Utilities_SyncTextureInfo_Success, syncResult.EditedTextures, syncResult.TotalTextures));
        }
        catch (Exception ex)
        {
            Logger.Error(ex, "Syncing texture info");

            await Services.MessageUI.DisplayExceptionMessageAsync(ex, Resources.Utilities_SyncTextureInfo_Error);
        }
        finally
        {
            IsLoading = false;
        }
    }