Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"theme": "dark"
},
"publisher": "Katsute",
"version": "1.0.11",
"version": "2.0.0",
"private": true,
"engines": {
"vscode": "^1.95.0"
Expand Down
18 changes: 15 additions & 3 deletions src/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export class Distribution {
public readonly keybindings: string;
public readonly locale: string;
public readonly settings: string;
public readonly Snippets: string;
public readonly snippets: string;
public readonly storage: string;
public readonly profiles: string;
public readonly dotVscode?: string;
public readonly Extensions?: string;
public readonly ExtensionsObsolete?: string;
Expand All @@ -52,7 +54,9 @@ export class Distribution {
this.keybindings = path.join(this.User, "keybindings.json");
this.locale = path.join(this.User, "locale.json");
this.settings = path.join(this.User, "settings.json");
this.Snippets = path.join(this.User, "snippets");
this.snippets = path.join(this.User, "snippets");
this.storage = path.join(this.User, "globalStorage", "storage.json");
this.profiles = path.join(this.User, "profiles");

const exts: vscode.Extension<any>[] = vscode.extensions.all.filter(e => !e.packageJSON.isBuiltin);

Expand All @@ -69,7 +73,9 @@ export class Distribution {
├ keybindings: ${this.keybindings}
├ locale: ${this.locale}
├ settings: ${this.settings}
└ Snippets: ${this.Snippets}
├ snippets: ${this.snippets}
├ storage: ${this.storage}
└ profiles: ${this.profiles}
.vscode: ${this.dotVscode}
├ Extensions: ${this.Extensions}
├ ExtensionsObsolete: ${this.ExtensionsObsolete}
Expand Down Expand Up @@ -191,6 +197,12 @@ ${json.slice(0, -2)}
: undefined;
}

public getStorage(): string | undefined {
return files.isFile(this.storage)
? fs.readFileSync(this.storage, "utf-8").trim()
: undefined;
}

private static readonly ctrl: RegExp = /(?<=^\s*"key"\s*:\s*".*)\bctrl\b(?=.*",?$)/gmi; // ⌃ ctrl
private static readonly cmd: RegExp = /(?<=^\s*"key"\s*:\s*".*)\bcmd\b(?=.*",?$)/gmi; // ⌘ cmd

Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const deactivate: () => Promise<void> = async () => {

export const notify: () => void = () => {
const select: string = "Reload";
vscode.window.showWarningMessage("Settings have been modified, a reload is required to see changes. Some changes require a full restart.", select, "Ignore").then((value?: string) => {
vscode.window.showWarningMessage("Settings have been modified, a reload is required to see changes. Profile changes require a full restart.", select, "Ignore").then((value?: string) => {
if(value === select)
vscode.commands.executeCommand("workbench.action.reloadWindow");
});
Expand Down
62 changes: 55 additions & 7 deletions src/sync/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,27 @@ export const pull: (repo: string, skipNotify?: boolean) => void = async (repo: s
/* snippets */ {
const snippets: string = path.join(temp, "snippets");

if(files.isDirectory(snippets)){
// remove local, use remote copy
fs.rmSync(dist.Snippets, {recursive: true, force: true});
if(files.isDirectory(snippets))
files.copyRecursiveSync(snippets, dist.snippets);
else
logger.warn("Snippets not found");
}

files.copyRecursiveSync(snippets, dist.Snippets);
}else
/* storage */ {
const storage: string = path.join(temp, "storage.json");

if(files.isFile(storage))
fs.copyFileSync(storage, dist.settings);
else
logger.warn("Storage not found");
}

/* profiles */ {
const profiles: string = path.join(temp, "profiles");

if(files.isDirectory(profiles))
files.copyRecursiveSync(profiles, dist.profiles);
else
logger.warn("Snippets not found");
}

Expand Down Expand Up @@ -247,11 +262,44 @@ export const push: (repo: string, ignoreBadAuth?: boolean) => Promise<void> = as
// remove remote, use local copy
fs.rmSync(snippets, {recursive: true, force: true});

if(files.isDirectory(dist.Snippets))
files.copyRecursiveSync(dist.Snippets, snippets);
if(files.isDirectory(dist.snippets))
files.copyRecursiveSync(dist.snippets, snippets);
else
logger.warn("Snippets not found");
}

/* storage */ {
const storage: string | undefined = dist.getStorage();

if(storage)
fs.writeFileSync(path.join(temp, "storage.json"), storage, "utf-8");
else
logger.warn("Storage not found");
}

/* profiles */ {
const profiles: string = path.join(temp, "profiles");

// remove remote, use local copy
fs.rmSync(profiles, {recursive: true, force: true});

if(files.isDirectory(dist.profiles)){
for(const dir of fs.readdirSync(dist.profiles)){
const profile: string = path.join(dist.profiles, dir);
if(files.isDirectory(profile)){
for(const f of ["extensions.json", "keybindings.json", "settings.json"]){
const file = path.join(profile, f);
files.isFile(file) && fs.copyFileSync(file, path.join(profiles, dir, f))
}
const snippets: string = path.join(profile, "snippets");
if(files.isDirectory(snippets)){
files.copyRecursiveSync(snippets, path.join(profiles, dir, "snippets"));
}
}
}
}else
logger.warn("Profiles not found");
}
}catch(error: any){
if(error){
logger.error(`Push failed: ${auth.mask(error, cred)}`, true);
Expand Down
55 changes: 53 additions & 2 deletions src/sync/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import AdmZip from "adm-zip";

import * as fs from "fs";
import * as path from "path";

import * as logger from "../logger";
import * as files from "../lib/files";
import * as extension from "../extension";
Expand Down Expand Up @@ -89,6 +92,26 @@ export const inport: (fsPath: string) => void = (fsPath: string) => {
logger.warn("Snippets not found");
}

/* storage */ {
const storage: AdmZip.IZipEntry | null = zip.getEntry("storage.json");

if(storage && !storage.isDirectory)
zip.extractEntryTo("storage.json", path.join(dist.User, "globalStorage"), undefined, true);
else
logger.warn("Storage not found");
}

/* profiles */ {
let hasProfiles: boolean = false;
for(const entry of zip.getEntries().filter(f => f.entryName.toLowerCase().startsWith("profiles/")).map(f => f.entryName)){
hasProfiles = true;
zip.extractEntryTo(entry, dist.User, undefined, true);
}

if(!hasProfiles)
logger.warn("Profiles not found");
}

logger.info(`Imported settings from ${fsPath}`, true);

extension.notify();
Expand Down Expand Up @@ -142,12 +165,40 @@ export const xport: (fsPath: string) => void = (fsPath: string) => {
}

/* snippets */ {
if(files.isDirectory(dist.Snippets))
zip.addLocalFolder(dist.Snippets, "snippets");
if(files.isDirectory(dist.snippets))
zip.addLocalFolder(dist.snippets, "snippets");
else
logger.warn("Snippets not found");
}

/* storage */ {
const storage: string | undefined = dist.getStorage();

if(storage)
zip.addFile("storage.json", Buffer.from(storage, "utf-8"));
else
logger.warn("Storage not found");
}

/* profiles */ {
if(files.isDirectory(dist.profiles)){
for(const dir of fs.readdirSync(dist.profiles)){
const profile: string = path.join(dist.profiles, dir);
if(files.isDirectory(profile)){
for(const f of ["extensions.json", "keybindings.json", "settings.json"]){
const file = path.join(profile, f);
files.isFile(file) && zip.addLocalFile(file, `profiles/${dir}`);
}
const snippets: string = path.join(profile, "snippets");
if(files.isDirectory(snippets)){
zip.addLocalFolder(snippets, `profiles/${dir}/snippets`);
}
}
}
}else
logger.warn("Profiles not found");
}

zip.writeZip(fsPath, (error: Error | null) => {
if(error)
logger.error(`Failed to export settings: ${error}`, true);
Expand Down