Skip to content

Commit

Permalink
fix: Create config.ini on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed May 10, 2024
1 parent 9f25bf0 commit a5c1fe0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
1 change: 1 addition & 0 deletions packages/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './utils/unzip';
export * from './utils/directories';
export * from './utils/json';
export * from './utils/sanitize';
export * from './utils/gosu';
3 changes: 3 additions & 0 deletions packages/common/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as dotenv from 'dotenv';
import fs from 'fs';
import path from 'path';

import { checkGameOverlayConfig } from './gosu';
import { wLogger } from './logger';

const configPath = path.join(
Expand Down Expand Up @@ -227,6 +228,8 @@ export const refreshConfig = (httpServer: any, refresh: boolean) => {
httpServer.restartWS();
}

checkGameOverlayConfig();

const osuInstances: any = Object.values(
httpServer.instanceManager.osuInstances || {}
);
Expand Down
20 changes: 20 additions & 0 deletions packages/common/utils/gosu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fs from 'fs';
import path from 'path';

export const checkGameOverlayConfig = () => {
const configPath = path.join(process.cwd(), 'config.ini');

if (fs.existsSync(configPath)) return;
fs.writeFileSync(
configPath,
`[GameOverlay]; https://github.com/l3lackShark/gosumemory/wiki/GameOverlay
gameWidth = 1920
gameHeight = 1080
overlayURL =
overlayWidth = 380
overlayHeight = 110
overlayOffsetX = 0
overlayOffsetY = 0
overlayScale = 10`
);
};
26 changes: 7 additions & 19 deletions packages/game-overlay/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import { downloadFile, unzip, wLogger } from '@tosu/common';
import {
checkGameOverlayConfig,
downloadFile,
unzip,
wLogger
} from '@tosu/common';
import { execFile } from 'node:child_process';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { existsSync, readFileSync } from 'node:fs';
import { mkdir, rm } from 'node:fs/promises';
import path from 'node:path';
import { Process } from 'tsprocess/dist/process';

const configPath = path.join(process.cwd(), 'config.ini');
const checkGameOverlayConfig = () => {
if (!existsSync(configPath)) {
writeFileSync(
configPath,
`[GameOverlay]; https://github.com/l3lackShark/gosumemory/wiki/GameOverlay
gameWidth = 1920
gameHeight = 1080
overlayURL =
overlayWidth = 380
overlayHeight = 110
overlayOffsetX = 0
overlayOffsetY = 0
overlayScale = 10`
);
}
};

const checkGosuConfig = (p: Process, checking?: boolean) => {
if (!existsSync(configPath)) return null;

Expand Down

0 comments on commit a5c1fe0

Please sign in to comment.