Skip to content

Commit

Permalink
Merge pull request #6 from whatk233:v0.2.0
Browse files Browse the repository at this point in the history
V0.2.0
  • Loading branch information
whatk233 authored Feb 8, 2023
2 parents b62dbf6 + 3a5c186 commit 319e606
Show file tree
Hide file tree
Showing 75 changed files with 214 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
core-build:
runs-on: windows-latest
timeout-minutes: 5
timeout-minutes: 3
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
core-release:
runs-on: windows-latest
timeout-minutes: 5
timeout-minutes: 3
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
core-build-test:
runs-on: windows-latest
timeout-minutes: 10
timeout-minutes: 3
steps:
- uses: actions/checkout@v3

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ docs/out/
.DS_Store
*.pem
.env
.vercel
.vercel
tweaks_test/
2 changes: 1 addition & 1 deletion src/autoit/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AUTOIT3WRAPPER_PATH, TEMPDIR } from "../constants.ts";
import { resolve } from "path";
import { emptyDirSync } from "fs";
import { emptyDirSync } from "https://deno.land/std@0.160.0/fs/mod.ts";
import * as log from "../utils/log.ts";
import { log as l } from "../utils/log.ts";

Expand Down
4 changes: 4 additions & 0 deletions src/autoit/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ export function generateTweakFuncBlock(name: string, str: string) {
};
return ifBlock();
}

export function generateCustomCommand(name:string) {
return `${name}()`
}
6 changes: 5 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import "dotenvLoad";
import { resolve } from "path";

const TEMP_ENV = Deno.env.get("temp");
const TWEAK_RULE_PATH_ENV = Deno.env.get("TWEAK_RULE_PATH");
const AUTOIT3WRAPPER_PATH_ENV = Deno.env.get("AUTOIT3WRAPPER_PATH");

export const TIS_BUILDTIME = new Date().toISOString().toString();
export const TWEAK_RULE_PATH = "tweaks";
export const TWEAK_RULE_PATH = TWEAK_RULE_PATH_ENV
? TWEAK_RULE_PATH_ENV
: "tweaks";
export const TEMPDIR = TEMP_ENV
? resolve(TEMP_ENV, ".TIS_TEMP")
: resolve(".", ".TIS_TEMP");
Expand Down
2 changes: 2 additions & 0 deletions src/core/constants.au3
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ Global Const $G_CONFIG_PATH = @ScriptDir & "\" & $G_CONFIG_NAME

Global Const $G_NTUSER_MOUNT_ROOT = "HKLM\WIS_NTUSER"
Global Const $G_NTUSER_MOUNT_ROOT64 = $G_HKLM & "\WIS_NTUSER"

Global Const $G_IsSysprepEnv = _IsSysprepEnv()
49 changes: 49 additions & 0 deletions src/core/custom/RemoveShotcutArrowIcon.au3

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/core/custom/_include.au3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include-once
#include "RemoveShotcutArrowIcon.au3"
25 changes: 15 additions & 10 deletions src/core/include/config.au3
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ Func _Config_Exists()
EndIf
EndFunc ;==>_Config_Exists

Func _Config_Tweak_IsApply($key)
Return Number(IniRead($G_CONFIG_PATH, $key, "apply", 0))
Func _Config_Tweak_Read($name, $key)
Return IniRead($G_CONFIG_PATH, $name, $key, Null)
EndFunc ;==>_Config_Tweak

Func _Config_Tweak_IsApply($name)
Return Number(IniRead($G_CONFIG_PATH, $name, "apply", 0))
EndFunc ;==>_Config_Tweak_IsApply

Func _Config_Tweak_IsApplyDefaultUser($key)
Return Number(IniRead($G_CONFIG_PATH, $key, "applyDefaultUser", 0))
Func _Config_Tweak_IsApplyDefaultUser($name)
Return Number(IniRead($G_CONFIG_PATH, $name, "applyDefaultUser", 0))
EndFunc ;==>_Config_Tweak_IsApplyDefaultUser

Func _Config_Tweak_ShowWindow($key)
Return Number(IniRead($G_CONFIG_PATH, $key, "showWindow", 0))
EndFunc ;==>_Config_Tweak_IsApplyDefaultUser
Func _Config_Tweak_ShowWindow($name)
Return Number(IniRead($G_CONFIG_PATH, $name, "showWindow", 0))
EndFunc ;==>_Config_Tweak_ShowWindow

Func _Config_Tweak_ApplyMode($name)
Return IniRead($G_CONFIG_PATH, $name, "applyMode", Null)
EndFunc ;==>_Config_Tweak_ApplyMode

Func _Config_Tweak_ApplyMode($key)
Return IniRead($G_CONFIG_PATH, $key, "applyMode", Null)
EndFunc ;==>_Config_Tweak_IsApplyDefaultUser
2 changes: 2 additions & 0 deletions src/core/include/tweak.au3
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Func _T_Run($sName, $sCommand, $sAction = "cmd", $bShowWindow = False, $sDefault
$sDefaultApplyMode = "desktop"
ElseIf $Config_Tweak_ApplyMode = "all" Then
$sDefaultApplyMode = "all"
Else
$sDefaultApplyMode = "sysprep"
EndIf

If $Config_Tweak_ShowWindow Then
Expand Down
41 changes: 41 additions & 0 deletions src/core/include/utils.au3
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include-once
#include "..\constants.au3"
#include "config.au3"

Func _msg($sText)
MsgBox(64, $G_NAME, $sText)
Expand Down Expand Up @@ -96,3 +97,43 @@ Func _RunCmd($sCommand, $bShowWindow = False)
Return RunWait(@ComSpec & " /c " & $sCommand, "", @SW_HIDE)
EndIf
EndFunc ;==>_RunCmd

;~ Check tweak apply requirements
Func _CheckRequireMents($sName, $sMode = "all")
;~ tweak is apply?
If _Config_Tweak_IsApply($sName) <> True Then
Return False
EndIf ;==>_CheckRequireMents

Const $Config_Tweak_ApplyMode = _Config_Tweak_ApplyMode($sName)
If $Config_Tweak_ApplyMode = "sysprep" Then
$sMode = "sysprep"
ElseIf $Config_Tweak_ApplyMode = "desktop" Then
$sMode = "desktop"
ElseIf $Config_Tweak_ApplyMode = "all" Then
$sMode = "all"
Else
$sMode = "all"
EndIf

If $sMode <> "all" Then
;~ Requires apply in sysprep, but is not currently a sysprep environment
If $sMode = "sysprep" Then
If $G_IsSysprepEnv <> True Then
Return False
EndIf
ElseIf $sMode = "desktop" Then
If $G_IsSysprepEnv Then
Return False
EndIf
EndIf
EndIf

Return True

EndFunc ;==>_CheckRequireMents

Func _Restart_Explorer()
ProcessClose("explorer.exe")
Run("%SystemDrive%\Windows\Explorer.EXE", "%SystemDrive%\Windows\Explorer.EXE")
EndFunc ;==>_Restart_Explorer
2 changes: 2 additions & 0 deletions src/core/tis.au3
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "include\utils.au3"
#include "include\tweak.au3"
#include "include\config.au3"
#include "custom\_include.au3"

If @OSArch = 'x64' Then
_WinAPI_Wow64EnableWow64FsRedirection(True)
Expand Down Expand Up @@ -48,5 +49,6 @@ EndFunc ;==>_Tweak

Func _Exit()
_UnMount_NTUSER_Reg()
If $G_IsSysprepEnv = False Then _Restart_Explorer()
EndFunc ;==>_Exit

56 changes: 45 additions & 11 deletions src/tweakRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { extname, resolve } from "path";
import { parse as yamlParse } from "yaml";
import { stringify as iniStringify } from "ini";
import {
generateCustomCommand,
generateRegDelete,
generateRegWrite,
generateRunCommand,
generateTweakFuncBlock,
} from "./autoit/generate.ts";
import { yamlOrYml } from "./utils/file.ts";

interface TweakConfig {
meta: {
Expand Down Expand Up @@ -40,26 +42,52 @@ interface TweakConfig {
defaultApplyMode: "sysprep" | "desktop" | "all" | undefined | null;
}[]
| undefined;
custom:
| {
name: string;
}[]
| undefined;
};
}

export function getRuleList() {
const result = [];
const tweaksRuleDir = Deno.readDirSync(resolve(TWEAK_RULE_PATH));
for (const dirEntry of tweaksRuleDir) {
if (dirEntry.isFile && extname(dirEntry.name) == ".yaml") {
const tweakFileObj = {
name: dirEntry.name.replace(".yaml", ""),
fileName: dirEntry.name,
};
result.push(tweakFileObj);
const extNameRegex = /\.yaml|\.yml/;
const result: { name: string; fileName: string }[] = [];
const nestedDir = (path: string) => {
const dirPath = resolve(
TWEAK_RULE_PATH,
path[0] == "/" ? path.substring(1) : path
);
const nested_dir = Deno.readDirSync(dirPath);
for (const dirEntry of nested_dir) {
if (
dirEntry.isFile &&
(extname(dirEntry.name) == ".yaml" || extname(dirEntry.name) == ".yml")
) {
// Remove the "/" before the beginning of the path
const fileName =
path == ""
? dirEntry.name
: path[0] == "/"
? `${path.substring(1)}/${dirEntry.name}`
: `${path}/${dirEntry.name}`;
const name = fileName.replace(extNameRegex, "");
const tweakFileObj = {
name,
fileName,
};
result.push(tweakFileObj);
} else if (dirEntry.isDirectory) {
nestedDir(`${path}/${dirEntry.name}`);
}
}
}
};
nestedDir("");
return result;
}

export function parse(name: string) {
const file = Deno.readTextFileSync(resolve(TWEAK_RULE_PATH, `${name}.yaml`));
const file = Deno.readTextFileSync(resolve(TWEAK_RULE_PATH, yamlOrYml(name)));
const result = yamlParse(file);
return result;
}
Expand All @@ -69,6 +97,7 @@ export function generateTweakFunc(name: string) {
const tweakParse = parse(name) as TweakConfig;
const registryTweak = tweakParse.tweaks.registry;
const runTweak = tweakParse.tweaks.run;
const customTweak = tweakParse.tweaks.custom;
if (registryTweak && registryTweak.length > 0) {
registryTweak.map((reg) => {
const { key, type, valueName, value, action } = reg;
Expand Down Expand Up @@ -104,6 +133,11 @@ export function generateTweakFunc(name: string) {
);
});
}
if (customTweak && customTweak.length > 0) {
customTweak.map((item) => {
tweakCode.push(generateCustomCommand(item.name));
});
}
return generateTweakFuncBlock(name, tweakCode.join("\n"));
}

Expand Down
37 changes: 31 additions & 6 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { TEMPDIR, TIS_BUILDTIME, TWEAK_INCLUDE_NAME } from "../constants.ts";
import { copySync, emptyDirSync, ensureFileSync } from "fs";
import {
TEMPDIR,
TIS_BUILDTIME,
TWEAK_INCLUDE_NAME,
TWEAK_RULE_PATH,
} from "../constants.ts";
import {
copySync,
emptyDirSync,
ensureFileSync,
} from "https://deno.land/std@0.160.0/fs/mod.ts";
import { resolve } from "path";
import { getShortCommit } from "./git.ts";
import getVersion from "./version.ts";
Expand All @@ -16,12 +25,12 @@ export function cpCore() {
if (file.isDirectory) {
copySync(
resolve(".", "src", "core", file.name),
resolve(TEMPDIR, file.name),
resolve(TEMPDIR, file.name)
);
} else if (file.isFile) {
Deno.copyFileSync(
resolve(".", "src", "core", file.name),
resolve(TEMPDIR, file.name),
resolve(TEMPDIR, file.name)
);
}
}
Expand Down Expand Up @@ -68,7 +77,7 @@ export const writeAutoitFile = {
done() {
writeTextToFile(
resolve(TEMPDIR, TWEAK_INCLUDE_NAME),
this.codes.join("\n").trim(),
this.codes.join("\n").trim()
);
},
};
Expand All @@ -83,7 +92,23 @@ export const writeConfigFile = {
this.config.unshift(`; TIS https://tis.whatk.me`);
writeTextToFile(
resolve(TEMPDIR, "build", "config.ini"),
this.config.join("\n").trim(),
this.config.join("\n").trim()
);
},
};

export const yamlOrYml = (name: string, path = TWEAK_RULE_PATH) => {
const yamlName = `${name}.yaml`;
const ymlName = `${name}.yml`;
try {
Deno.statSync(resolve(path, yamlName)).isFile;
return yamlName;
} catch {
try {
Deno.statSync(resolve(path, ymlName)).isFile;
return ymlName;
} catch {
throw new Error("File does not exists!");
}
}
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions tweaks/Shell/Explorer/DismPP_RemoveShotcutArrowIcon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
meta:
en:
name: Remove Shotcut Arrow Icon
zh:
name: 隐藏快捷方式图标上的小箭头
restartExplorer: true
tweaks:
custom:
- name: "_Custom_RemoveShotcutArrowIcon"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.1.1"
"version": "0.2.0"
}

1 comment on commit 319e606

@vercel
Copy link

@vercel vercel bot commented on 319e606 Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tis-docs – ./

tis-docs-whatk.vercel.app
tis.whatk.me
tis-docs-git-main-whatk.vercel.app
tis-nu.vercel.app

Please sign in to comment.