Skip to content

Commit

Permalink
feat: win10_init.py file read
Browse files Browse the repository at this point in the history
fix: win10_init.ps1 misspell
  • Loading branch information
empty-233 committed Jul 28, 2023
1 parent 16a9c5b commit 1cf33fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 130 deletions.
4 changes: 2 additions & 2 deletions win10_init.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
$file_path = "Tencent.wsb"
$relative_dir_identifer = ".\"
$relative_dir_identifier = ".\"

$file_content = Get-Content -Path $file_path -Encoding UTF8

$relative_dir = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$relative_dir = $relative_dir + '\'
Write-Host ("gathered relative dir: " + $relative_dir)

$wsb_content = $file_content -replace [regex]::Escape($relative_dir_identifer), $relative_dir
$wsb_content = $file_content -replace [regex]::Escape($relative_dir_identifier), $relative_dir

Copy-Item "Tencent.wsb" "Tencent.wsb.bak" -Force
Write-Host "backup old wsb as Tencent.wsb.bak"
Expand Down
144 changes: 16 additions & 128 deletions win10_init.py
Original file line number Diff line number Diff line change
@@ -1,140 +1,28 @@
import os
import shutil

wsb_template = r'''<Configuration>
<MappedFolders>
<!-- 桌面 -->
<MappedFolder>
<HostFolder>|NOW_DIR|\Desktop</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\Desktop</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<!-- App -->
<MappedFolder>
<HostFolder>|NOW_DIR|\App\WeChat</HostFolder>
<SandboxFolder>C:\Program Files\Tencent\WeChat</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\App\QQ</HostFolder>
<SandboxFolder>C:\Program Files (x86)\Tencent\QQ</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\App\TIM</HostFolder>
<SandboxFolder>C:\Program Files (x86)\Tencent\TIM</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\App\QQNT</HostFolder>
<SandboxFolder>C:\Program Files\Tencent\QQNT</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\App\WXWork</HostFolder>
<SandboxFolder>C:\Program Files (x86)\WXWork</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<!-- Roaming -->
<MappedFolder>
<HostFolder>|NOW_DIR|\Data\Roaming\WeChat</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\AppData\Roaming\Tencent\WeChat</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\Data\Roaming\Tencent</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\AppData\Roaming\Tencent\Tencent</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\Data\Roaming\TencentDocs</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\AppData\Roaming\TDAppDesktop</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\Data\Roaming\WeMeet</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\AppData\Roaming\Tencent\WeMeet</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<!-- Documents -->
<MappedFolder>
<HostFolder>|NOW_DIR|\Data\Documents\WeChat</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\Documents\WeChat Files</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\Data\Documents\Tencent</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\Documents\Tencent Files</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\Data\Documents\WXWork</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\Documents\WXWork</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\App\Meeting</HostFolder>
<SandboxFolder>C:\Program Files (x86)\Tencent\WeMeet</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>|NOW_DIR|\App\TencentDocs</HostFolder>
<SandboxFolder>C:\Program Files\TencentDocs</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<!-- Common Files -->
<MappedFolder>
<HostFolder>|NOW_DIR|\Data\Common Files</HostFolder>
<SandboxFolder>C:\Program Files (x86)\Common Files</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<!-- ProgramData -->
<MappedFolder>
<HostFolder>|NOW_DIR|\Data\ProgramData\Tencent</HostFolder>
<SandboxFolder>C:\ProgramData\Tencent</SandboxFolder>
<ReadOnly>false</ReadOnly>
</MappedFolder>
<!-- 脚本 -->
<MappedFolder>
<HostFolder>|NOW_DIR|\Scripts</HostFolder>
<SandboxFolder>C:\Scripts</SandboxFolder>
<ReadOnly>true</ReadOnly>
</MappedFolder>
<!-- SysWOW64 -->
<MappedFolder>
<HostFolder>|NOW_DIR|\Data\SysWOW64</HostFolder>
<SandboxFolder>C:\Windows\SysWOW64</SandboxFolder>
<ReadOnly>true</ReadOnly>
</MappedFolder>
</MappedFolders>
<!-- 音频 -->
<AudioInput>Enable</AudioInput>
<!-- 视频 -->
<VideoInput>Disable</VideoInput>
<!-- 内存限制 -->
<MemoryInMB>2048</MemoryInMB>
<!-- 开机运行脚本 -->
<LogonCommand>
<Command>C:\Scripts\sandbox-setup.cmd</Command>
</LogonCommand>
<!-- vGpu -->
<vGPU>Enable</vGPU>
</Configuration>
'''
file_path = "Tencent.wsb"
relative_dir_identifier = ".\\"

relative_dir_identifer = "|NOW_DIR|"
relative_dir = os.path.dirname(os.path.abspath(__file__))
try:
with open(file_path, "r", encoding="utf-8") as file:
file_content = file.read()
except FileNotFoundError:
print(f"文件 '{file_path}' 未找到。")
except IOError:
print(f"无法打开文件 '{file_path}'。")

relative_dir = os.path.dirname(os.path.abspath(__file__)) + "\\"
print ("获取到的相对路径: " + relative_dir)

# replace relative dir
wsb_template = wsb_template.replace(relative_dir_identifer, relative_dir)
wsb_template = file_content.replace(relative_dir_identifier, relative_dir)

# backup old wsb by copying
if os.path.exists("Tencent.wsb"):
shutil.copyfile("Tencent.wsb", "Tencent.wsb.bak")
print("备份原有wsb文件为Tencent.wsb.bak")
shutil.copyfile("Tencent.wsb", "Tencent.wsb.bak")
print("备份原有wsb文件为Tencent.wsb.bak")

# generate new wsb in utf-8
with open("Tencent.wsb", "w", encoding="utf-8") as f:
f.write(wsb_template)
with open("Tencent.wsb", "w", encoding="utf-8") as file:
file.write(wsb_template)
print("生成新的wsb文件")

0 comments on commit 1cf33fa

Please sign in to comment.