Skip to content

Commit

Permalink
Merge pull request #427 from FlashpointProject/feat/testing
Browse files Browse the repository at this point in the history
feat: Testing Improvements
  • Loading branch information
colin969 authored Jun 8, 2024
2 parents c2d0000 + 26ec351 commit cba47b5
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 197 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "docs/api"]
path = docs/api
url = https://github.com/FlashpointProject/launcher_ApiDocs.git
[submodule "extensions/core-curation"]
path = extensions/core-curation
url = https://github.com/FlashpointProject/Sys-Extension-Core-Curation.git
1 change: 0 additions & 1 deletion extensions/core-curation
Submodule core-curation deleted from edb028
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@
"headerFileOperations": "File",
"headerEditCuration": "Edit",
"headerTest": "Test",
"headerFpfss": "FPFSS",
"importAll": "Import All",
"importAllDesc": "Import all curations that are currently loaded",
"deleteAll": "Delete All",
Expand Down Expand Up @@ -491,7 +492,8 @@
"contextCopyAsURL": "Copy File Path as URL",
"contextShowInExplorer": "Show File in Explorer",
"contextOpenFolderInExplorer": "Open Folder in Explorer",
"shortcuts": "Shortcuts"
"shortcuts": "Shortcuts",
"fpfssOpenSubmissionPage": "Open Submission Page"
},
"playlist": {
"enterDescriptionHere": "Enter a description here...",
Expand Down
89 changes: 51 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@fortawesome/free-solid-svg-icons": "5.15.4",
"@fortawesome/react-fontawesome": "0.1.18",
"@fparchive/flashpoint-archive": "0.7.13",
"@types/node-7z": "2.1.8",
"@types/react-virtualized": "^9.21.21",
"axios": "1.6.7",
"connected-react-router": "6.9.2",
Expand All @@ -46,7 +47,7 @@
"lodash": "^4.17.21",
"mime": "2.4.4",
"minimist": "^1.2.7",
"node-7z": "1.1.1",
"node-7z": "3.0.0",
"open": "^10.1.0",
"ps-tree": "1.2.0",
"react": "17.0.2",
Expand Down
34 changes: 34 additions & 0 deletions src/back/curate/fpfss.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FPFSS_INFO_FILENAME } from '@shared/curate/fpfss';
import { str } from '@shared/utils/Coerce';
import { ObjectParser } from '@shared/utils/ObjectParser';
import { CurationFpfssInfo } from 'flashpoint-launcher';
import * as fs from 'fs';
import * as path from 'path';

export async function getCurationFpfssInfo(folder: string): Promise<CurationFpfssInfo | null> {
return fs.promises.readFile(path.join(folder, FPFSS_INFO_FILENAME), { encoding: 'utf-8' })
.then((dataStr) => {
return parseCurationFpfssInfo(JSON.parse(dataStr));
})
.catch(() => {
return null;
});
}

export async function saveCurationFpfssInfo(folder: string, info: CurationFpfssInfo) {
const data = parseCurationFpfssInfo(info);
return fs.promises.writeFile(path.join(folder, FPFSS_INFO_FILENAME), JSON.stringify(data, undefined, 2));
}

export function parseCurationFpfssInfo(data: any): CurationFpfssInfo {
const info: CurationFpfssInfo = {
id: ''
};

const parser = new ObjectParser({
input: data
});
parser.prop('id', v => info.id = str(v));

return info;
}
12 changes: 8 additions & 4 deletions src/back/curate/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { uuid } from '@back/util/uuid';
import { fixSlashes } from '@shared/Util';
import { BackOut } from '@shared/back/types';
import { CURATIONS_FOLDER_WORKING } from '@shared/constants';
import { LoadedCuration } from '@shared/curate/types';
import { getContentFolderByKey } from '@shared/curate/util';
import { GamePropSuggestions } from '@shared/interfaces';
import { LangContainer } from '@shared/lang';
import axios from 'axios';
import { AddAppCuration, CurationState, CurationWarnings } from 'flashpoint-launcher';
import { AddAppCuration, CurationFpfssInfo, CurationState, CurationWarnings, LoadedCuration } from 'flashpoint-launcher';
import * as fs from 'fs-extra';
import * as http from 'http';
import { Progress } from 'node-7z';
Expand All @@ -20,6 +19,7 @@ import { checkAndDownloadGameData, extractFullPromise, fpDatabase } from '..';
import { loadCurationIndexImage } from './parse';
import { readCurationMeta } from './read';
import { saveCuration } from './write';
import { getCurationFpfssInfo } from './fpfss';

const whitelistedBaseFiles = ['logo.png', 'ss.png'];

Expand All @@ -30,7 +30,7 @@ export type UpdateCurationFileFunc = (folder: string, relativePath: string, data
export type RemoveCurationFileFunc = (folder: string, relativePath: string) => Promise<void>;

export const onFileServerRequestPostCuration =
async (pathname: string, url: URL, req: http.IncomingMessage, res: http.ServerResponse, tempCurationsPath: string, onNewCuration: (filePath: string, onProgress?: (progress: Progress) => void) => Promise<CurationState>) => {
async (pathname: string, url: URL, req: http.IncomingMessage, res: http.ServerResponse, tempCurationsPath: string, onNewCuration: (filePath: string, fpfssInfo: CurationFpfssInfo | null, onProgress?: (progress: Progress) => void) => Promise<CurationState>) => {
if (req.method === 'POST') {
const chunks: any[] = [];
req.on('data', (chunk) => {
Expand All @@ -46,7 +46,7 @@ export const onFileServerRequestPostCuration =
const randomFilePath = path.join(tempCurationsPath, `${uuid()}.7z`);
await fs.promises.mkdir(path.dirname(randomFilePath), { recursive: true });
await fs.promises.writeFile(randomFilePath, data);
await onNewCuration(randomFilePath)
await onNewCuration(randomFilePath, null)
.then(() => {
res.writeHead(200);
res.end();
Expand Down Expand Up @@ -213,6 +213,7 @@ export async function loadCurationFolder(rootPath: string, folderName: string, s
group: parsedMeta.group,
game: parsedMeta.game,
addApps: parsedMeta.addApps,
fpfssInfo: null,
thumbnail: await loadCurationIndexImage(path.join(rootPath, folderName, 'logo.png')),
screenshot: await loadCurationIndexImage(path.join(rootPath, folderName, 'ss.png'))
};
Expand All @@ -222,6 +223,8 @@ export async function loadCurationFolder(rootPath: string, folderName: string, s
alreadyImported,
warnings: await genCurationWarnings(loadedCuration, state.config.flashpointPath, state.suggestions, state.languageContainer.curate, state.apiEmitters.curations.onWillGenCurationWarnings)
};
// Try and load fpfss data
curation.fpfssInfo = await getCurationFpfssInfo(path.join(rootPath, folderName));
state.loadedCurations.push(curation);
genContentTree(getContentFolderByKey(folderName, state.config.flashpointPath)).then((contentTree) => {
const curationIdx = state.loadedCurations.findIndex((c) => c.folder === folderName);
Expand Down Expand Up @@ -358,6 +361,7 @@ export async function makeCurationFromGame(state: BackState, gameId: string, ski
folder,
uuid: game.id,
group: '',
fpfssInfo: null,
game: {
...game,
tags: game.detailedTags,
Expand Down
9 changes: 8 additions & 1 deletion src/back/curate/write.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { LoadedCuration } from '@shared/curate/types';
import * as fs from 'fs';
import * as path from 'path';
import * as YAML from 'yaml';
import { saveCurationFpfssInfo } from './fpfss';
import { LoadedCuration } from 'flashpoint-launcher';

type CurationMetaFile = {
'Application Path'?: string;
Expand Down Expand Up @@ -47,9 +48,15 @@ type CurationFormatAddApp = {


export async function saveCuration(fullCurationPath: string, curation: LoadedCuration): Promise<void> {
// Save Meta
const metaPath = path.join(fullCurationPath, 'meta.yaml');
const meta = YAML.stringify(convertEditToCurationMetaFile(curation));
await fs.promises.writeFile(metaPath, meta);

// Save FPFSS info
if (curation.fpfssInfo) {
await saveCurationFpfssInfo(fullCurationPath, curation.fpfssInfo);
}
}

function convertEditToCurationMetaFile(curation: LoadedCuration): CurationMetaFile {
Expand Down
7 changes: 4 additions & 3 deletions src/back/extensions/ApiImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { BrowsePageLayout, ScreenshotPreviewMode } from '@shared/BrowsePageLayou
import { ILogEntry, LogLevel } from '@shared/Log/interface';
import { BackOut } from '@shared/back/types';
import { CURATIONS_FOLDER_WORKING } from '@shared/constants';
import { CurationMeta, LoadedCuration } from '@shared/curate/types';
import { CurationMeta } from '@shared/curate/types';
import { getContentFolderByKey } from '@shared/curate/util';
import { CurationTemplate, IExtensionManifest } from '@shared/extensions/interfaces';
import { ProcessState, Task } from '@shared/interfaces';
Expand Down Expand Up @@ -410,7 +410,7 @@ export function createApiFactory(extId: string, extManifest: IExtensionManifest,
status: `Loading ${filePath}`
});
}
const curState = await loadCurationArchive(filePath)
const curState = await loadCurationArchive(filePath, null)
.catch((error) => {
log.error('Curate', `Failed to load curation archive! ${error.toString()}`);
state.socketServer.broadcast(BackOut.OPEN_ALERT, formatString(state.languageContainer['dialog'].failedToLoadCuration, error.toString()) as string);
Expand Down Expand Up @@ -517,12 +517,13 @@ export function createApiFactory(extId: string, extManifest: IExtensionManifest,
const contentFolder = path.join(curPath, 'content');
await fs.promises.mkdir(contentFolder, { recursive: true });

const data: LoadedCuration = {
const data: flashpoint.LoadedCuration = {
folder,
uuid: uuid(),
group: '',
game: meta || {},
addApps: [],
fpfssInfo: null,
thumbnail: await loadCurationIndexImage(path.join(curPath, 'logo.png')),
screenshot: await loadCurationIndexImage(path.join(curPath, 'ss.png'))
};
Expand Down
Loading

0 comments on commit cba47b5

Please sign in to comment.