Skip to content

Commit

Permalink
Merge pull request #319 from Zagrios/chore/change-default-contents-path
Browse files Browse the repository at this point in the history
[chore] Change default contents path to avoid OneDrive issues
  • Loading branch information
Zagrios authored Sep 11, 2023
2 parents c9bcdc8 + 2e376b0 commit e01fe02
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/main/ipcs/bs-download-ipcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/services/bs-installer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/services/bs-local-version.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/main/services/configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/main/services/folder-linker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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);

Expand Down
44 changes: 27 additions & 17 deletions src/main/services/installation-location.service.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}

Expand Down

0 comments on commit e01fe02

Please sign in to comment.