Skip to content

Commit

Permalink
added exception filter and details title override
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartondock committed May 28, 2024
1 parent 700d22b commit 1d989e6
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 74 deletions.
2 changes: 2 additions & 0 deletions src/lib/image-providers/available-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ export const providerInfo: ProviderInfo = {
export const providersSelect = onlineProviders.map((provider)=>{
return {value: provider, displayValue: imageProviderNames[provider]}
})

export const sgdbIdRegex: RegExp = /^\$\{gameid\:([0-9]*?)\}$/;
9 changes: 5 additions & 4 deletions src/lib/image-providers/steamcdn.worker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { GenericProvider, GenericProviderManager, ProviderProxy } from "./generic-provider";
import {apiKey, idRegex} from "./steamgriddb.worker";
import {apiKey} from "./steamgriddb.worker";
import { xRequestWrapper } from "./x-request-wrapper";
import SGDB from "steamgriddb";
import { artworkTypes, steamArtworkDict } from '../artwork-types'
import { imageProviderNames } from "./available-providers";
import { imageProviderNames, sgdbIdRegex } from "./available-providers";

export class SteamCDNProvider extends GenericProvider {
private xrw: xRequestWrapper<SteamCDNProvider>;
private client: any;
Expand All @@ -18,8 +19,8 @@ export class SteamCDNProvider extends GenericProvider {
let self = this;
this.xrw.promise = new Promise<void>((resolve) => {
let idPromise: Promise<number> = null;
if(idRegex.test(self.proxy.title)) {
idPromise = Promise.resolve(parseInt(self.proxy.title.match(idRegex)[1]))
if(sgdbIdRegex.test(self.proxy.title)) {
idPromise = Promise.resolve(parseInt(self.proxy.title.match(sgdbIdRegex)[1]))
} else {
idPromise = self.client.searchGame(self.proxy.title).then((res: any) => (res[0]||{}).id);
}
Expand Down
11 changes: 5 additions & 6 deletions src/lib/image-providers/steamgriddb.worker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { GenericProvider, GenericProviderManager, ProviderProxy } from "./generic-provider";
import { xRequestWrapper } from "./x-request-wrapper";
import SGDB from "steamgriddb";
import { imageProviderNames } from "./available-providers";
import { imageProviderNames, sgdbIdRegex } from "./available-providers";


export const idRegex: RegExp = /^\$\{gameid\:([0-9]*?)\}$/;

// TODO make the user input this
export const apiKey = "f80f92019254471cca9d62ff91c21eee";
Expand All @@ -21,8 +20,8 @@ export class SteamGridDbProvider extends GenericProvider {

static async retrieveIdsFromTitle(title: string): Promise<number[]> {
const client = new SGDB({key: apiKey});
if(idRegex.test(title)) {
return [parseInt(title.match(idRegex)[1])];
if(sgdbIdRegex.test(title)) {
return [parseInt(title.match(sgdbIdRegex)[1])];
} else {
const games = await client.searchGame(title);
return games.map((game: any)=> game.id)
Expand All @@ -48,8 +47,8 @@ export class SteamGridDbProvider extends GenericProvider {
let imageGameId: string;
this.xrw.promise = new Promise<void>((resolve) => {
let idPromise: Promise<number> = null;
if(idRegex.test(self.proxy.title)) {
idPromise = Promise.resolve(parseInt(self.proxy.title.match(idRegex)[1]))
if(sgdbIdRegex.test(self.proxy.title)) {
idPromise = Promise.resolve(parseInt(self.proxy.title.match(sgdbIdRegex)[1]))
} else {
idPromise = self.client.searchGame(self.proxy.title).then((res: any) => (res[0]||{}).id);
}
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/components/parsers.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { VariableParser } from '../../lib';
import { clipboard } from 'electron';
import { Component, AfterViewInit, OnDestroy, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { FormGroup, AbstractControl } from '@angular/forms';
import { ActivatedRoute, Router, RouterLinkActive } from '@angular/router';
import { ParsersService, LoggerService, ImageProviderService, SettingsService, ConfigurationPresetsService, ShellScriptsService, IpcService } from '../services';
import { ActivatedRoute, Router } from '@angular/router';
import { ParsersService, LoggerService, ImageProviderService, SettingsService, ConfigurationPresetsService, ShellScriptsService, IpcService, UserExceptionsService } from '../services';
import * as parserInfo from '../../lib/parsers/available-parsers';
import * as steam from '../../lib/helpers/steam';
import { controllerTypes, controllerNames } from '../../lib/controller-manager';
Expand Down Expand Up @@ -45,6 +45,7 @@ export class ParsersComponent implements AfterViewInit, OnDestroy {
private loggerService: LoggerService,
private settingsService: SettingsService,
private imageProviderService: ImageProviderService,
private userExceptionsService: UserExceptionsService,
private router: Router,
private activatedRoute: ActivatedRoute,
private changeRef: ChangeDetectorRef,
Expand Down Expand Up @@ -801,16 +802,15 @@ export class ParsersComponent implements AfterViewInit, OnDestroy {
success('');
const executableLocation = data.files[i].modifiedExecutableLocation;
const title = data.files[i].finalTitle;
let shortAppId; let appId; let exceptionKey;
let shortAppId;
if(parserInfo.superTypesMap[config.parserType] !== parserInfo.ArtworkOnlyType) {
shortAppId = steam.generateShortAppId(executableLocation, title);
appId = steam.lengthenAppId(shortAppId);
exceptionKey = steam.generateShortAppId(executableLocation, data.files[i].extractedTitle);
} else {
shortAppId = executableLocation.replace(/\"/g,"");
appId = steam.lengthenAppId(shortAppId);
exceptionKey = shortAppId;
}
const appId = steam.lengthenAppId(shortAppId);
const exceptionKey = this.userExceptionsService.makeExceptionId(executableLocation, data.files[i].extractedTitle, config.parserType)

success(this.lang.success.exceptionKey__i.interpolate({
index: i + 1,
total: totalLength,
Expand Down
111 changes: 74 additions & 37 deletions src/renderer/components/preview.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as FileSaver from 'file-saver';
import * as steam from '../../lib/helpers/steam';
import * as _ from 'lodash';
import * as path from 'path';
import { allProviders, imageProviderNames, multiLocalProviders, onlineProviders, providerCategories, singleLocalProviders } from '../../lib/image-providers/available-providers';
import { allProviders, imageProviderNames, providerCategories, sgdbIdRegex } from '../../lib/image-providers/available-providers';

@Component({
selector: 'preview',
Expand All @@ -27,6 +27,7 @@ export class PreviewComponent implements OnDestroy {
subscriptions: Subscription = new Subscription();
previewVariables: PreviewVariables;
missingArtFilter: boolean = false;
exceptionFilter: boolean = false;
showFilters: boolean = false;
filterValue: string = '';
categoryFilter: string[] = [];
Expand Down Expand Up @@ -60,6 +61,7 @@ export class PreviewComponent implements OnDestroy {
detailsLoading: boolean = true;
showDetails: boolean = false;
detailsSearchText: string = '';
detailsDisplayTitle: string = '';

showExcludes: boolean = false;
excludedAppIds: {
Expand Down Expand Up @@ -361,6 +363,11 @@ export class PreviewComponent implements OnDestroy {
this.changeDetectionRef.detectChanges();
}

setExceptionFilter(exceptionFilter: boolean) {
this.exceptionFilter = exceptionFilter;
this.changeDetectionRef.detectChanges();
}

searchMatches(searchTitle: string) {
this.previewService.getMatchFixes(searchTitle).then((games: any[])=>{
this.matchFixDict = Object.fromEntries(games.map((x: any)=>[x.id.toString(), {name: x.name, posterUrl: x.posterUrl}]));
Expand All @@ -375,11 +382,11 @@ export class PreviewComponent implements OnDestroy {
}
}
changeAppDetails(app: PreviewDataApp, steamDirectory: string, userId: string, appId: string) {
this.clearDetails();
this.cancelExcludes();
this.closeListImages();
this.detailsLoading = true;
this.showDetails= true;
this.matchFix = '';
this.renderer.setStyle(this.elementRef.nativeElement, '--details-width', '50%', RendererStyleFlags2.DashCase);
this.changeDetectionRef.detectChanges()
this.detailsApp = {
Expand All @@ -394,13 +401,19 @@ export class PreviewComponent implements OnDestroy {
fixMatch(sgdbId: string) {
this.matchFix = sgdbId;
}
closeDetails() {

clearDetails() {
this.detailsSearchText = '';
this.detailsDisplayTitle = '';
this.matchFix = '';
this.detailsApp = undefined;
}
closeDetails() {
this.clearDetails();
this.showDetails = false;
this.renderer.setStyle(this.elementRef.nativeElement, '--details-width','0%', RendererStyleFlags2.DashCase);
this.detailsLoading = false;
this.changeDetectionRef.detectChanges();
}

getImageRanges(app: PreviewDataApp, artworkType?: ArtworkType) {
Expand All @@ -427,45 +440,64 @@ export class PreviewComponent implements OnDestroy {
this.renderer.setStyle(this.elementRef.nativeElement, '--list-images-width','0%',RendererStyleFlags2.DashCase);
}

deleteExceptionDetails() {
console.log("deyeeting")
if(this.detailsApp) {
console.log("crodie")
const {steamDirectory, userId, appId, app} = this.detailsApp;
const exceptionId = this.userExceptionsService.makeExceptionId(app.executableLocation, app.extractedTitle, app.parserType)
this.userExceptionsService.deleteExceptionById(exceptionId);
this.refreshAfterSavingDetails(steamDirectory,userId,appId);
this.closeDetails();
this.generatePreviewData();

}
}

saveDetails() {
if(this.detailsApp && this.matchFix) {
if(this.detailsApp) {
const {steamDirectory, userId, appId, app} = this.detailsApp;
this.previewData[steamDirectory][userId].apps[appId].title = this.matchFixDict[this.matchFix].name;
if(superTypesMap[app.parserType] !== 'ArtworkOnly') {
const changedId = steam.generateAppId(app.executableLocation, this.matchFixDict[this.matchFix].name);
this.previewData[steamDirectory][userId].apps[appId].changedId = changedId;
}
const newPool = `\$\{gameid:${this.matchFix}\}`
for(const artworkType of artworkTypes) {
const oldPool = this.previewData[steamDirectory][userId].apps[appId].images[artworkType].imagePool;
this.previewData[steamDirectory][userId].apps[appId].images[artworkType].imagePool = newPool;
this.previewData[steamDirectory][userId].apps[appId].images[artworkType].singleProviders.steam = undefined;
this.previewService.updateAppImages(newPool, oldPool, artworkType)
const newTitle = this.detailsDisplayTitle || (this.matchFix ? this.matchFixDict[this.matchFix].name : "");
if(newTitle) {
this.previewData[steamDirectory][userId].apps[appId].title = newTitle;
if(superTypesMap[app.parserType] !== 'ArtworkOnly') {
const changedId = steam.generateAppId(app.executableLocation, newTitle);
this.previewData[steamDirectory][userId].apps[appId].changedId = changedId;
}
}
let exceptionId;
if(superTypes[ArtworkOnlyType].includes(app.parserType)) {
exceptionId = app.executableLocation.replace(/\"/g,"");
} else {
exceptionId = steam.generateShortAppId(app.executableLocation, app.extractedTitle)
const newPool = this.matchFix ? `\$\{gameid:${this.matchFix}\}` : "";
if(newPool) {
for(const artworkType of artworkTypes) {
const oldPool = this.previewData[steamDirectory][userId].apps[appId].images[artworkType].imagePool;
this.previewData[steamDirectory][userId].apps[appId].images[artworkType].imagePool = newPool;
this.previewData[steamDirectory][userId].apps[appId].images[artworkType].singleProviders.steam = undefined;
this.previewService.updateAppImages(newPool, oldPool, artworkType)
}
}

const exceptionId = this.userExceptionsService.makeExceptionId(app.executableLocation, app.extractedTitle, app.parserType);
this.userExceptionsService.addExceptionById(exceptionId, app.extractedTitle, {
newTitle: this.matchFixDict[this.matchFix].name,
newTitle: newTitle,
searchTitle: newPool,
commandLineArguments: '',
exclude: false,
excludeArtwork: false
})
if(!isArtworkType(this.previewService.getCurrentViewType())) {
for(const artworkType of artworkTypes) {
this.refreshImages(this.previewData[steamDirectory][userId].apps[appId], artworkType)
}
} else {
this.refreshImages(this.previewData[steamDirectory][userId].apps[appId]);
}
this.refreshAfterSavingDetails(steamDirectory,userId,appId);
this.closeDetails();
}
}

private refreshAfterSavingDetails(steamDirectory: string, userId: string, appId: string) {
if(!isArtworkType(this.previewService.getCurrentViewType())) {
for(const artworkType of artworkTypes) {
this.refreshImages(this.previewData[steamDirectory][userId].apps[appId], artworkType)
}
} else {
this.refreshImages(this.previewData[steamDirectory][userId].apps[appId]);
}
}

excludeAppId(steamDirectory: string, userId: string, appId: string, override?: boolean) {
if(this.showExcludes) {
if(!this.excludedAppIds[steamDirectory]) {
Expand Down Expand Up @@ -495,20 +527,28 @@ export class PreviewComponent implements OnDestroy {
const searchFilter = this.fuzzyTest.transform(app.title, this.filterValue);
const categoryFilter = this.intersectionTest.transform(app.steamCategories, this.actualCategoryFilter);
const configFilter = this.intersectionTest.transform([app.configurationTitle], this.actualParserFilter);
let missingArtFilter;
const currentViewType = this.previewService.getCurrentViewType();
if(!this.missingArtFilter) {
missingArtFilter = true;
} else {
let missingArtFilter = true;
if(this.missingArtFilter) {
const currentViewType = this.previewService.getCurrentViewType();
if(isArtworkType(currentViewType)) {
missingArtFilter = !this.previewService.getCurrentImage(app)
}
else {
missingArtFilter = artworkTypes.map(t => !this.previewService.getCurrentImage(app,t)).reduce((x,y)=>x||y);
}
}
let exceptionFilter = true;
if(this.exceptionFilter) {
const exceptionId = this.userExceptionsService.makeExceptionId(app.executableLocation, app.extractedTitle, app.parserType);
exceptionFilter = !!this.userExceptionsService.getExceptionById(exceptionId)
}
const excludesArtOnlyFilter = !this.showExcludes || superTypesMap[app.parserType]!=='ArtworkOnly'
return searchFilter && categoryFilter && configFilter && missingArtFilter && excludesArtOnlyFilter;
return searchFilter
&& categoryFilter
&& configFilter
&& missingArtFilter
&& exceptionFilter
&& excludesArtOnlyFilter;
}

excludeVisible() {
Expand Down Expand Up @@ -564,9 +604,6 @@ export class PreviewComponent implements OnDestroy {
return {exceptionId: exceptionId, extractedTitle: app.extractedTitle}
});
exceptionKeys = exceptionKeys.concat(newKeys)
this.previewData[steamDirectory][userId].apps = _.pickBy(this.previewData[steamDirectory][userId].apps, (value: PreviewDataApp, key: string) => {
return !this.excludedAppIds[steamDirectory][userId][key]
})
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/renderer/services/preview.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ export class PreviewService {
this.appSettings = appSettings;
});
this.onlineImages = initArtworkRecord<OnlineImages[ArtworkType]>({});
for(const artworkType of artworkTypes) {
this.onlineImages[artworkType] = {};
}

this.currentViewType = defaultArtworkType;
this.imageProviderService.instance.stopEvent.subscribe(() => {
for(const artworkType of artworkTypes) {
Expand Down
41 changes: 40 additions & 1 deletion src/renderer/services/user-exceptions.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { UserExceptions, UserExceptionData } from "../../models";
import { UserExceptions, UserExceptionData, PreviewDataApp, ParserType } from "../../models";
import { LoggerService } from './logger.service';
import { BehaviorSubject } from "rxjs";
import { APP } from '../../variables';
Expand All @@ -8,6 +8,8 @@ import * as paths from "../../paths";
import * as schemas from '../schemas';
import * as modifiers from '../modifiers';
import * as _ from "lodash";
import { superTypesMap } from '../../lib/parsers/available-parsers';
import * as steam from '../../lib/helpers/steam';

@Injectable()
export class UserExceptionsService {
Expand Down Expand Up @@ -80,6 +82,30 @@ export class UserExceptionsService {
this.saveUserExceptions();
}

makeExceptionId(executableLocation: string, extractedTitle: string, parserType: ParserType) {
if(superTypesMap[parserType]=='ArtworkOnly') {
return executableLocation.replace(/\"/g,"");
} else {
return steam.generateShortAppId(executableLocation, extractedTitle)
}
}

deleteExceptionById(exceptionId: string) {
let newData = this.data.saved;
const exceptionMatches = Object.keys(newData.titles).filter((exTitle: string) => {
if(UserExceptionsService.appIdRegex.test(exTitle)) {
return exTitle.match(UserExceptionsService.appIdRegex)[1] == exceptionId;
} else {
return false
}
})
if(exceptionMatches.length) {
delete newData.titles[exceptionMatches[0]];
}
this.variableData.next({current: newData, saved: this.data.saved});
this.saveUserExceptions();
}

addExceptionById(exceptionId: string, extractedTitle: string, newException: UserExceptionData) {
let newData = this.data.saved;
const exceptionMatches = Object.keys(newData.titles).filter((exTitle: string) => {
Expand All @@ -96,6 +122,19 @@ export class UserExceptionsService {
this.saveUserExceptions();
}

getExceptionById(exceptionId: string) {
const exceptionMatches = Object.keys(this.data.saved.titles).filter((exTitle: string) => {
if(UserExceptionsService.appIdRegex.test(exTitle)) {
return exTitle.match(UserExceptionsService.appIdRegex)[1] == exceptionId;
} else {
return false
}
})
if(exceptionMatches.length) {
return this.data.saved.titles[exceptionMatches[0]]
}
}

private duplicateKeys(data: UserExceptions) {
const replacedKeys = Object.keys(data.titles).map(exTitle => {
return UserExceptionsService.appIdRegex.test(exTitle) ? exTitle.match(UserExceptionsService.appIdRegex)[0] : exTitle
Expand Down
Loading

0 comments on commit 1d989e6

Please sign in to comment.