Skip to content

Commit

Permalink
Fix Add Local Images
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartondock committed Oct 27, 2024
1 parent dc237a3 commit cbf7518
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 75 deletions.
35 changes: 0 additions & 35 deletions src/lib/file-selector.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ export * from "./vdf-added-items-file";
export * from "./artwork-cache";
export * from "./vdf-error";
export * from "./acceptable-error";
export * from "./file-selector";
export * from "./category-manager";
export * from "./controller-manager";
70 changes: 31 additions & 39 deletions src/renderer/components/preview.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
SteamList,
} from "../../models";
import { APP } from "../../variables";
import { FileSelector } from "../../lib";
import {
artworkTypes,
artworkViewTypes,
Expand All @@ -58,7 +57,8 @@ import {
sgdbIdRegex,
} from "../../lib/image-providers/available-providers";
import { DomSanitizer } from "@angular/platform-browser";

import { OpenDialogReturnValue } from "electron";
import { dialog } from "@electron/remote";
@Component({
selector: "preview",
templateUrl: "../templates/preview.component.html",
Expand All @@ -83,7 +83,6 @@ export class PreviewComponent implements OnDestroy {
artworkSelectTypes: SelectItem[];
sortBySelectTypes: SelectItem[];
scrollingEntries: boolean = false;
fileSelector: FileSelector = new FileSelector();
CLI_MESSAGE: BehaviorSubject<string> = new BehaviorSubject("");
currentApp: {
app: PreviewDataApp;
Expand Down Expand Up @@ -420,52 +419,45 @@ export class PreviewComponent implements OnDestroy {
return this.previewService.getTotalLengthOfImages(app, artworkType);
}

updateListImageRanges() {
if (this.currentApp) {
updateListImageRanges(app?: PreviewDataApp) {
if (this.currentApp || app) {
const rangesApp = app ? app : this.currentApp.app;
this.listImagesRanges = this.previewService.getRanges(
this.currentApp.app,
rangesApp,
this.listImagesArtworkType,
);
this.changeDetectionRef.detectChanges();
}
}

addLocalImages(app: PreviewDataApp, artworkType?: ArtworkType) {
this.fileSelector.multiple = true;
this.fileSelector.accept = ".png, .jpeg, .jpg, .tga, .webp";
async addLocalImages(app: PreviewDataApp, artworkType?: ArtworkType) {
const options: Electron.OpenDialogSyncOptions = {
properties: ["multiSelections","openFile"],
title: "Choose selections folder location.",
filters: [{name: "Images", extensions: ["png","tga","jpg","jpeg","webp"]}]
};
const actualArtworkType = this.getActualArtworkType(artworkType);
this.fileSelector.onChange = (target) => {
if (target.files) {
let extRegex = /png|tga|jpg|jpeg|webp/i;
for (let i = 0; i < target.files.length; i++) {
if (extRegex.test(path.extname(target.files[i].path))) {
let imageUrl = url.encodeFile(target.files[i].path);
this.previewService.addUniqueLocalImage(
app.images[actualArtworkType].imagePool,
{
imageProvider: imageProviderNames.manual,
imageUrl: imageUrl,
loadStatus: "done",
},
actualArtworkType,
"manual",
);
this.previewService.setImageIndex(
app,
this.previewService.getTotalLengthOfImages(
app,
actualArtworkType,
true,
) - 1,
actualArtworkType,
true,
);
this.updateListImageRanges();
}
const {filePaths}: OpenDialogReturnValue = await dialog.showOpenDialog(options);
if(filePaths!==undefined) {
let extRegex = /png|tga|jpg|jpeg|webp/i;
for (let i = 0; i < filePaths.length; i++) {
if (extRegex.test(path.extname(filePaths[i]))) {
let imageUrl = url.encodeFile(filePaths[i]);
this.previewService.addUniqueLocalImage(
app.images[actualArtworkType].imagePool,
{
imageProvider: imageProviderNames.manual,
imageUrl: imageUrl,
loadStatus: "done",
},
actualArtworkType,
"manual",
);
this.updateListImageRanges(app);
this.previewService.setImageIndex(app, this.listImagesRanges["manual"].end - 1,actualArtworkType,true)
}
}
};
this.fileSelector.trigger();
}
}

stopImageRetrieving() {
Expand Down

0 comments on commit cbf7518

Please sign in to comment.