Merge pull request #319 from Zagrios/chore/change-default-contents-path

[chore] Change default contents path to avoid OneDrive issues
This commit is contained in:
MathieuG-P
2023-09-11 22:08:17 +02:00
committed by GitHub
8 changed files with 45 additions and 35 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ ipc.on("is-dotnet-6-installed", (_, reply) => {
ipc.on("bs-download.installation-folder", (_, reply) => {
const installLocation = InstallationLocationService.getInstance();
reply(of(installLocation.installationDirectory));
reply(from(installLocation.installationDirectory()));
});
ipc.on<string>("bs-download.set-installation-folder", (req, reply) => {
@@ -75,7 +75,7 @@ export class LocalMapsManagerService {
if (version) {
return path.join(await this.localVersion.getVersionPath(version), LocalMapsManagerService.LEVELS_ROOT_FOLDER, LocalMapsManagerService.CUSTOM_LEVELS_FOLDER);
}
const sharedMapsPath = path.join(this.installLocation.sharedContentPath, LocalMapsManagerService.SHARED_MAPS_FOLDER, LocalMapsManagerService.CUSTOM_LEVELS_FOLDER);
const sharedMapsPath = path.join(await this.installLocation.sharedContentPath(), LocalMapsManagerService.SHARED_MAPS_FOLDER, LocalMapsManagerService.CUSTOM_LEVELS_FOLDER);
if (!(await pathExist(sharedMapsPath))) {
await ensureFolderExist(sharedMapsPath);
}
@@ -73,7 +73,7 @@ export class LocalModelsManagerService {
}
private async getModelFolderPath(type: MSModelType, version?: BSVersion): Promise<string> {
const rootPath = version ? await this.localVersion.getVersionPath(version) : this.installPaths.sharedContentPath;
const rootPath = await (version ? this.localVersion.getVersionPath(version) : this.installPaths.sharedContentPath());
const modelFolderPath = path.join(rootPath, MODEL_TYPE_FOLDERS[type]);
await ensureFolderExist(modelFolderPath);
+2 -2
View File
@@ -79,7 +79,7 @@ export class BSInstallerService {
qr
}
await ensureDir(this.installLocationService.versionsDirectory);
await ensureDir(await this.installLocationService.versionsDirectory());
const isLinux = process.platform === 'linux';
const exePath = this.getDepotDownloaderExePath();
@@ -88,7 +88,7 @@ export class BSInstallerService {
return new DepotDownloader({
command: isLinux ? 'dotnet' : exePath,
args: isLinux ? [exePath, ...args] : args,
options: { cwd: this.installLocationService.versionsDirectory },
options: { cwd: await this.installLocationService.versionsDirectory() },
echoStartData: downloadVersion
}, log);
}
@@ -142,7 +142,7 @@ export class BSLocalVersionService {
if(version.oculus){ return this.oculusService.getGameFolder(OCULUS_BS_DIR); }
return path.join(
this.installLocationService.versionsDirectory,
await this.installLocationService.versionsDirectory(),
this.getVersionFolder(version)
);
}
@@ -156,7 +156,7 @@ export class BSLocalVersionService {
const versionPath = await this.getVersionPath(version);
if(await pathExist(versionPath)){ return versionPath; }
const versionFolders = await getFoldersInFolder(this.installLocationService.versionsDirectory);
const versionFolders = await getFoldersInFolder(await this.installLocationService.versionsDirectory());
for(const folder of versionFolders){
const stats = await lstat(folder);
@@ -215,11 +215,11 @@ export class BSLocalVersionService {
versions.push(oculusVersion);
}
if (!(await pathExist(this.installLocationService.versionsDirectory))) {
if (!(await pathExist(await this.installLocationService.versionsDirectory()))) {
return versions;
}
const folderInInstallation = await getFoldersInFolder(this.installLocationService.versionsDirectory);
const folderInInstallation = await getFoldersInFolder(await this.installLocationService.versionsDirectory());
for (const f of folderInInstallation) {
log.info("try get version from folder", f);
+3 -3
View File
@@ -19,11 +19,11 @@ export class ConfigurationService {
this.locations = InstallationLocationService.getInstance();
this.initStore();
this.locations.onInstallLocationUpdate(() => this.initStore());
this.locations.onInstallLocationUpdate(() => { this.initStore() });
}
private initStore() {
const contentPath = this.locations.installationDirectory;
private async initStore() {
const contentPath = await this.locations.installationDirectory();
this.store = new ElectronStore({
cwd: contentPath,
name: "config",
+6 -6
View File
@@ -21,12 +21,12 @@ export class FolderLinkerService {
this.installLocationService = InstallationLocationService.getInstance();
}
private get sharedFolder(): string {
return this.installLocationService.sharedContentPath;
private async sharedFolder(): Promise<string> {
return this.installLocationService.sharedContentPath();
}
private getSharedFolder(folderPath: string, intermediateFolder?: string): string {
return path.join(this.sharedFolder, intermediateFolder ?? "", path.basename(folderPath));
private async getSharedFolder(folderPath: string, intermediateFolder?: string): Promise<string> {
return path.join(await this.sharedFolder(), intermediateFolder ?? "", path.basename(folderPath));
}
private getBackupFolder(folderPath: string): string {
@@ -50,7 +50,7 @@ export class FolderLinkerService {
}
public async linkFolder(folderPath: string, options?: LinkOptions): Promise<void> {
const sharedPath = this.getSharedFolder(folderPath, options?.intermediateFolder);
const sharedPath = await this.getSharedFolder(folderPath, options?.intermediateFolder);
if (await this.isFolderSymlink(folderPath)) {
const isTargetedToSharedPath = await readlink(folderPath)
@@ -86,7 +86,7 @@ export class FolderLinkerService {
}
await unlinkPath(folderPath);
const sharedPath = this.getSharedFolder(folderPath, options?.intermediateFolder);
const sharedPath = await this.getSharedFolder(folderPath, options?.intermediateFolder);
await ensureFolderExist(folderPath);
@@ -1,7 +1,7 @@
import path from "path";
import { app } from "electron";
import ElectronStore from "electron-store";
import { copyDirectoryWithJunctions, deleteFolder, ensureFolderExist } from "../helpers/fs.helpers";
import { copyDirectoryWithJunctions, deleteFolder, ensureFolderExist, pathExist } from "../helpers/fs.helpers";
export class InstallationLocationService {
private static instance: InstallationLocationService;
@@ -27,51 +27,61 @@ export class InstallationLocationService {
private constructor() {
this.installPathConfig = new ElectronStore({ watch: true });
this.initInstallationLocation();
this.installPathConfig.onDidChange(this.STORE_INSTALLATION_PATH_KEY, () => {
this.triggerListeners();
});
}
private initInstallationLocation(): void {
this._installationDirectory = (this.installPathConfig.get<string>(this.STORE_INSTALLATION_PATH_KEY) as string) || app.getPath("documents");
}
private triggerListeners(): void {
this.updateListeners.forEach(listener => listener());
}
public async setInstallationDirectory(newDir: string): Promise<string> {
const oldDir = this.installationDirectory;
const newDest = path.join(newDir, this.INSTALLATION_FOLDER);
newDir = path.basename(newDir) === this.INSTALLATION_FOLDER ? newDir : path.join(newDir, this.INSTALLATION_FOLDER);
const oldDir = await this.installationDirectory();
await ensureFolderExist(oldDir);
await copyDirectoryWithJunctions(oldDir, newDest, { overwrite: true });
await copyDirectoryWithJunctions(oldDir, newDir, { overwrite: true });
this._installationDirectory = newDir;
this.installPathConfig.set(this.STORE_INSTALLATION_PATH_KEY, newDir);
deleteFolder(oldDir);
return this.installationDirectory;
return this.installationDirectory();
}
public onInstallLocationUpdate(fn: Listener) {
this.updateListeners.add(fn);
}
public get installationDirectory(): string {
return path.join(this._installationDirectory, this.INSTALLATION_FOLDER);
public async installationDirectory(): Promise<string> {
if(this._installationDirectory) {
return this._installationDirectory;
}
if(this.installPathConfig.has(this.STORE_INSTALLATION_PATH_KEY)) {
this._installationDirectory = this.installPathConfig.get(this.STORE_INSTALLATION_PATH_KEY) as string;
return this._installationDirectory;
}
const oldPath = path.join(app.getPath("documents"), this.INSTALLATION_FOLDER);
if(await pathExist(oldPath)){
this._installationDirectory = oldPath;
return this._installationDirectory;
}
this._installationDirectory = path.join(app.getPath("home"), this.INSTALLATION_FOLDER);
return this._installationDirectory;
}
public get versionsDirectory(): string {
return path.join(this.installationDirectory, this.VERSIONS_FOLDER);
public async versionsDirectory(): Promise<string> {
return path.join(await this.installationDirectory(), this.VERSIONS_FOLDER);
}
public get sharedContentPath(): string {
return path.join(this.installationDirectory, this.SHARED_CONTENT_FOLDER);
public async sharedContentPath(): Promise<string> {
return path.join(await this.installationDirectory(), this.SHARED_CONTENT_FOLDER);
}
}