Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #83 from zzzz465/feature/configurable-paths
Browse files Browse the repository at this point in the history
feature: configurable paths
  • Loading branch information
zzzz465 authored Feb 19, 2022
2 parents 066387d + 8affc93 commit eb3a0a6
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 223 deletions.
43 changes: 43 additions & 0 deletions vsc-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,49 @@
"command": "rwxml:debug:printXMLDocumentObject",
"title": "RWXML: (debug) print current document's XMLDocument"
}
],
"configuration": [
{
"title": "RWXML Language Server",
"properties": {
"rwxml.paths.rimWorld": {
"type": "string",
"scope": "machine-overridable",
"default": "",
"markdownDescription": "path of `RimWorld/` directory."
},
"rwxml.paths.rimWorldData": {
"type": "string",
"scope": "machine-overridable",
"default": "",
"markdownDescription": "path of `RimWorld/Data/` directory, which includes `Core/`, `Ideology/`, etc.\noverrides `rwxml.paths.rimWorld`"
},
"rwxml.paths.rimWorldManaged": {
"type": "string",
"scope": "machine-overridable",
"default": "",
"markdownDescription": "directory path of `RimWorld/RimWorldXXX64_Data/Managed/`\noverrides `rwxml.paths.rimWorld`"
},
"rwxml.paths.localMods": {
"type": "string",
"scope": "machine-overridable",
"default": "",
"markdownDescription": "path of `RimWorld/Mods/` directory\noverrides `rwxml.paths.rimWorld`"
},
"rwxml.paths.workshopMods": {
"type": "string",
"scope": "machine-overridable",
"default": "",
"markdownDescription": "path of `workshop/contents/294100/`"
},
"rwxml.paths.externalMods": {
"type": "array",
"scope": "machine-overridable",
"default": [],
"markdownDescription": "additional paths to check mods."
}
}
}
]
},
"scripts": {
Expand Down
86 changes: 0 additions & 86 deletions vsc-extension/src/containerVars.ts

This file was deleted.

10 changes: 4 additions & 6 deletions vsc-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import * as path from 'path'
import { container } from 'tsyringe'
import * as features from './features'
import { checkTypeInfoAnalyzeAvailable } from './typeInfo'
import * as containerVars from './containerVars'
import * as commands from './commands'
import { ProjectWatcher } from './projectWatcher'
import * as resources from './resources'
import { ModManager } from './mod/modManager'
import { ModManager, PathStore } from './mod'
import { ExtensionVersionToken } from './version'
import { ExtensionContextToken } from './extension'
import { UpdateNotification } from './notification/updateNotification'
Expand All @@ -35,8 +34,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
updateNotification.checkFirstRunThisVersion()

// 2. initialize containers (set values)
console.log('initializing container variables...')
disposables.push(containerVars.initialize())
// automatically moved to pathStore

// 2-2. register commands
console.log('register commands...')
Expand Down Expand Up @@ -90,8 +88,8 @@ export function deactivate() {

async function createServer() {
const context = container.resolve<vscode.ExtensionContext>(ExtensionContextToken)
const serverModuleRelativePath = container.resolve(containerVars.languageServerModuleRelativePathKey) as string
const module = path.join(context.extensionPath, serverModuleRelativePath)
const pathStore = container.resolve<PathStore>(PathStore.token)
const module = path.join(context.extensionPath, pathStore.LanguageServerModulePath)
console.log(`server module absolute path: ${module}`)

const serverOptions: ServerOptions = {
Expand Down
3 changes: 0 additions & 3 deletions vsc-extension/src/insiderCheck.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { container } from 'tsyringe'
import { ExtensionContext } from 'vscode'
import { ExtensionContextToken } from './extension'
import * as vscode from 'vscode'

export default async function checkInsider() {
Expand Down
114 changes: 2 additions & 112 deletions vsc-extension/src/mod/index.ts
Original file line number Diff line number Diff line change
@@ -1,115 +1,5 @@
import { Uri } from 'vscode'
import process from 'process'
import os from 'os'
import path from 'path'

export * from './about'
export * from './mod'
export * from './modManager'
export * from './loadFolders'

export function getWorkshopModsDirectoryUri(): Uri {
// TODO: get from config or env or something else...

// default
return getDefaultWorkshopModsDirectoryUri()
}

function getDefaultWorkshopModsDirectoryUri(): Uri {
switch (process.platform) {
case 'win32':
return Uri.file('C:\\Program Files (x86)\\Steam\\steamapps\\workshop\\content\\294100')

case 'darwin': {
const homeDir = os.homedir()
const darwinDefaultSteamPath = 'Library/Application Support/Steam/Steamapps/workshop/content/294100'
const localModDirectoryPath = path.join(homeDir, darwinDefaultSteamPath)

return Uri.file(localModDirectoryPath)
}

case 'linux':
throw new Error('platform linux is not supported YET. please make an issue.')

default:
throw new Error(`current platform: ${process.platform} is not supported.`)
}
}

export function getCoreDirectoryUri(): Uri {
// TODO: add custom config

return getDefaultCoreDirectoryUri()
}

function getDefaultCoreDirectoryUri(): Uri {
switch (process.platform) {
case 'win32':
return Uri.file('C:\\Program Files (x86)\\Steam\\steamapps\\common\\RimWorld\\Data')

case 'darwin': {
const homeDir = os.homedir()
const darwinDefaultSteamPath = 'Library/Application Support/Steam/Steamapps/common/RimWorld/RimWorldMac.app/Data'
const coreModDirectoryPath = path.join(homeDir, darwinDefaultSteamPath)

return Uri.file(coreModDirectoryPath)
}

case 'linux':
throw new Error('platform linux is not supported YET. please make an issue.')

default:
throw new Error(`current platform: ${process.platform} is not supported.`)
}
}

export function getLocalModDirectoryUri(): Uri {
// TODO: add custom config

return getDefaultLocalModDirectoryUri()
}

function getDefaultLocalModDirectoryUri(): Uri {
switch (process.platform) {
case 'win32':
return Uri.file('C:\\Program Files (x86)\\Steam\\steamapps\\common\\RimWorld\\Mods')

case 'darwin': {
const homeDir = os.homedir()
const darwinDefaultSteamPath = 'Library/Application Support/Steam/Steamapps/common/RimWorld/RimWorldMac.app/Mods'
const localModDirectoryPath = path.join(homeDir, darwinDefaultSteamPath)

return Uri.file(localModDirectoryPath)
}

case 'linux':
throw new Error('platform linux is not supported YET. please make an issue.')

default:
throw new Error(`current platform: ${process.platform} is not supported.`)
}
}

export function getRimWorldDLLDirectoryUri(): Uri {
// TODO: add custom config

return getDefaultRimWorldDLLDirectoryUri()
}

function getDefaultRimWorldDLLDirectoryUri(): Uri {
switch (process.platform) {
case 'win32':
return Uri.file(String.raw`C:\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed`)

case 'darwin': {
const homeDir = os.homedir()
const darwinDefaultDLLPath =
'Library/Application Support/Steam/Steamapps/common/RimWorld/RimWorldMac.app/contents/Resources/Data/managed'
const localModDirectoryPath = path.join(homeDir, darwinDefaultDLLPath)

return Uri.file(localModDirectoryPath)
}

default:
throw new Error(`platform ${process.platform} is not supported.`)
}
}
export * from './pathStore'
12 changes: 8 additions & 4 deletions vsc-extension/src/mod/modManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Mod } from './mod'
import vscode from 'vscode'
import path from 'path'
import { AsEnumerable } from 'linq-es2015'
import { injectAll, singleton } from 'tsyringe'
import { DependencyDirectoriesKey as DependencyDirectoriesToken } from '../containerVars'
import { inject, singleton } from 'tsyringe'
import { PathStore } from './pathStore'

@singleton()
export class ModManager {
Expand All @@ -18,8 +18,12 @@ export class ModManager {
return this._initialized
}

constructor(@injectAll(DependencyDirectoriesToken) public readonly directoryUris: Uri[]) {
console.log(`ModManager watching directories: ${directoryUris}`)
get directoryUris(): vscode.Uri[] {
return this.pathStore.dependencyDirectories.map((fsPath) => vscode.Uri.file(fsPath))
}

constructor(@inject(PathStore.token) private readonly pathStore: PathStore) {
console.log(`ModManager watching directories: ${JSON.stringify(this.directoryUris, null, 4)}`)
}

async init() {
Expand Down
Loading

0 comments on commit eb3a0a6

Please sign in to comment.