Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lehni committed Jul 29, 2018
0 parents commit f7862f2
Show file tree
Hide file tree
Showing 14 changed files with 290 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"browser": false,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn"
}
}
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Set default behavior to automatically normalize line endings.
* text=auto

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.vscode-test/
*.vsix
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
]
}
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// A launch configuration that launches the extension inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
]
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place your settings in this file to overwrite default and user settings.
{
}
4 changes: 4 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/**
.gitignore
jsconfig.json
.eslintrc.json
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Change Log

## Version 1.0.0

- Initial release.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# VSCode Extension to Fix Checksums

An extension to to adjust checksums after changes to core files.

## Installation

Follow the instructions in the
[Marketplace](https://marketplace.visualstudio.com/items?itemName=lehni.vscode-fix-checksums),
or run the following in the command palette:

```shell
ext install lehni.vscode-fix-checksums
```

Alternatively, you can run this command in the command line:

```sh
code --install-extension lehni.vscode-fix-checksums
```

## Usage

The extension adds 2 new commands to the command palette:

```js
Fix Checksums: Apply //
Fix Checksums: Restore //
```

After executing either of these commands, you need to fully restart VSCode in
order to see the extension's effect. Simply reloading the window is not enough.

See [Disclaimer / A Word of Caution](#disclaimer--a-word-of-caution) for
details.

## Installing on macOS 10.14 Mojave

Due to security restrictions on macOS 10.14, VSCode needs to run as root
in order to be able to apply the patches. To do so, open the `Terminal.app` and
run:

```sh
sudo "/Applications/Visual Studio Code.app/Contents/MacOS/Electron"
```

Or this if you're using VSCode Insiders:

```sh
sudo "/Applications/Visual Studio Code - Insiders.app/Contents/MacOS/Electron"
```

Once you ave applied the modifications by executing `Fix Checksums: Apply` as
root, quit VScode and start it normally without root privileges again.

## Disclaimer / A Word of Caution

This extension modifies files that are part of the core of VSCode, so use it at
your own risk.

This extension creates backup files before modifying the core files, and these
can be restored at any time using the `Fix Checksums: Restore` command.

If anything goes wrong, you can always reinstall VSCode from
[code.visualstudio.com](https://code.visualstudio.com/download) without loosing
any settings or installed extensions.

## License

MIT © Jürg Lehni, 2018
85 changes: 85 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const vscode = require('vscode')
const fs = require('fs')
const path = require('path')
const crypto = require('crypto')

const appDir = path.dirname(require.main.filename)
const rootDir = path.join(appDir, '..')

const productFile = path.join(rootDir, 'product.json')
const origFile = `${productFile}.orig.${vscode.version}`

exports.activate = function activate(context) {
context.subscriptions.push(
vscode.commands.registerCommand('fixChecksums.apply', apply),
vscode.commands.registerCommand('fixChecksums.restore', restore)
)
cleanupOrigFiles()
}

const messages = {
changed: verb => `Checksums ${verb}. Please restart VSCode to see effect.`,
unchanged: 'No changes to checksums were necessary.',
error: `An error occurred during execution.
Make sure you have write access rights to the VSCode files, see README`
}

function apply() {
const product = require(productFile)
let changed = false
let message = messages.unchanged
for (const [filePath, curChecksum] of Object.entries(product.checksums)) {
const checksum = computeChecksum(path.join(appDir, ...filePath.split('/')))
if (checksum !== curChecksum) {
product.checksums[filePath] = checksum
changed = true
}
}
if (changed) {
const json = JSON.stringify(product, null, '\t')
try {
fs.renameSync(productFile, origFile)
fs.writeFileSync(productFile, json, { encoding: 'utf8' })
message = messages.changed('applied')
} catch (err) {
console.error(err)
message = messages.error
}
}
vscode.window.showInformationMessage(message)
}

function restore() {
let message = messages.unchanged
try {
if (fs.existsSync(origFile)) {
fs.unlinkSync(productFile)
fs.renameSync(origFile, productFile)
message = messages.changed('restored')
}
} catch (err) {
console.error(err)
message = messages.error
}
vscode.window.showInformationMessage(message)
}

function computeChecksum(file) {
var contents = fs.readFileSync(file)
return crypto
.createHash('md5')
.update(contents)
.digest('base64')
.replace(/=+$/, '')
}

function cleanupOrigFiles() {
// Remove all old backup files that aren't related to the current version
// of VSCode anymore.
const oldOrigFiles = fs.readdirSync(rootDir)
.filter(file => /\.orig\./.test(file))
.filter(file => !file.endsWith(vscode.version))
for (const file of oldOrigFiles) {
fs.unlinkSync(path.join(rootDir, file))
}
}
13 changes: 13 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"checkJs": false,
"lib": [
"es6"
]
},
"exclude": [
"node_modules"
]
}
60 changes: 60 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "vscode-fix-checksums",
"displayName": "Fix VSCode Checksums",
"description": "An extension to adjust checksums after changes to core files",
"icon": "resources/logo.png",
"version": "1.3.1",
"license": "MIT",
"main": "./extension",
"publisher": "lehni",
"author": {
"name": "Jürg Lehni",
"email": "[email protected]"
},
"bugs": {
"url": "https://github.com/lehni/vscode-fix-checksums/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/lehni/vscode-fix-checksums"
},
"engines": {
"vscode": "^1.25.0"
},
"keywords": [
"vscode",
"vsc",
"extension",
"fix",
"checksum",
"checksums"
],
"categories": [
"Other"
],
"activationEvents": [
"onCommand:fixChecksums.apply",
"onCommand:fixChecksums.restore"
],
"contributes": {
"commands": [
{
"command": "fixChecksums.apply",
"title": "Fix Checksums: Apply"
},
{
"command": "fixChecksums.restore",
"title": "Fix Checksums: Restore"
}
]
},
"scripts": {
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"@types/node": "^7.0.43",
"@types/mocha": "^2.2.42",
"eslint": "^4.11.0",
"vscode": "^1.1.6"
}
}
Binary file added resources/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/logo.psd
Binary file not shown.

0 comments on commit f7862f2

Please sign in to comment.