-
-
Notifications
You must be signed in to change notification settings - Fork 207
Description
I am writing to report an issue I encountered while developing a custom right-click menu feature for Nilesoft Shell:
I implemented functions to add remove (to block right-click menu items) and modifyde (to modify menu items) by popping up an input box in the right-click menu. Users input Chinese keywords into this input box, and the script writes these keywords to a text file in the format of remove(find="Chinese keywords") or modifyde(...).
However, the Chinese characters stored in the text file appear garbled. After checking the file properties, I found that:
The text file saved by Nilesoft Shell uses Unix (LF) line breaks and ANSI encoding by default;
This encoding/line break combination causes Chinese characters to display abnormally (garbled) when the file is opened with common editors (e.g., Notepad, Notepad++).
Could you please help confirm:
Whether Nilesoft Shell supports specifying file encoding (e.g., UTF-8 with BOM) when writing text files via io.file.write/io.file.append?
Is there a way to set the line break format to Windows (CRLF) instead of Unix (LF) to avoid encoding conflicts with Chinese characters?
Thank you for your assistance.
Best regards,
[TiAmo]
`// ===================== 全局可配置变量 =====================
$Menu_Management_file = path.combine(path.parent(app.cfg), 'imports', '右键菜单管理.nss') // 配置文件默认路径
$Menu_Management_title = '右键菜单管理器' // 自定义菜单显示标题
// ===================== 核心菜单定义 =====================
menu(title=Menu_Management_title type='*' vis=if(this.level!=1, 'disabled') image=[\uE249, image.color2]) {
// ===================== 用户可自定义变量 =====================
$create_backup = 1 // 创建备份开关(1=启用,0=禁用)
// ===================== 自动生成的内部变量 =====================
$mm_dir = eval(path.parent(Menu_Management_file)) // 配置目录路径
$mm_file = eval(path.name(Menu_Management_file)) // 配置文件名
$mm_path = eval(path.combine(mm_dir, mm_file)) // 配置文件完整路径
$msg_title = eval(if(len(Menu_Management_title)>5, Menu_Management_title, '右键菜单管理器')) // 消息框标题
// ===================== 菜单项定义 =====================
// 创建配置文件菜单项
item(image=\uE108 title='创建菜单管理配置文件' tip='创建右键菜单管理配置文件' vis=if(path.exists(mm_path), 2)
cmd={io.dir.create(mm_dir) $content = "/*屏蔽修改菜单*/" io.file.create(mm_path, $content)}
)
// ===================== 核心函数定义 =====================
// 函数:添加屏蔽关键词
$cmd_add_remove = {
// 弹出输入框,获取要屏蔽的菜单关键词
input("屏蔽菜单", "请输入要屏蔽的菜单关键词")
// 将输入内容存入目标变量
$target_keyword = input.result
// 检查输入是否为空
if(str.empty(target_keyword), {
msg("请输入有效的菜单关键词", msg_title, msg.warning)
return
})
// 读取Menu_Management_file内容,存入源变量
$source_content = io.file.read(mm_path)
// 查找相同关键词
if(str.contains(source_content, "remove(find=\"" + target_keyword + "\")"), {
// 如果找到相同关键词,提示是否覆盖
if(msg("关键词 '" + target_keyword + "' 已存在,是否覆盖?", msg_title, msg.question|msg.yesno)==msg.idyes, {
// 移除旧的关键词
$new_content = str.replace(source_content, "remove(find=\"" + target_keyword + "\")", "")
// 在新的一行写入新的关键词
io.file.write(mm_path, new_content + "\nremove(find=\"" + target_keyword + "\")")
// 显示成功消息
msg("已成功更新屏蔽关键词: " + target_keyword, msg_title, msg.info)
})
}, {
// 如果没有找到相同关键词,直接写入
io.file.append(mm_path, "\nremove(find=\"" + target_keyword + "\")")
// 显示成功消息
msg("已成功添加屏蔽关键词: " + target_keyword, msg_title, msg.info)
})
target_keyword= null
}
// 屏蔽菜单项
item(image=\uE74D title='屏蔽菜单'
tip='通过关键词屏蔽菜单项'
vis=if(path.exists(mm_path), 1, 2)
cmd=cmd_add_remove)
// 恢复配置文件菜单项
item(image=\uE7A0 title='恢复配置文件'
tip='从备份恢复配置文件'
vis=if(path.exists(mm_path), 1, 2)
)
// 分隔线
separator()
// 重置配置文件菜单项
item(image=\uE778 title='重置配置文件'
tip='重置为默认配置'
vis=if(path.exists(mm_path), 1, 2)
)
// 删除配置文件菜单项
item(image=\uE74D title='删除配置文件'
tip='删除右键菜单管理配置文件'
vis=if(path.exists(mm_path), 1, 2)
cmd={
// 确认删除操作
if(msg('确定要删除配置文件吗?', msg_title, msg.warning|msg.yesno)==msg.idyes, {
// 创建备份(如果启用)
if(create_backup, {
$backup_path = path.rename_extension(mm_path, '.bak')
io.copy(mm_path, backup_path)
})
// 删除文件
io.delete(mm_path)
// 显示删除成功消息
msg('配置文件已删除' + if(create_backup, '\n备份已保存为: ' + path.name(backup_path), ''), msg_title, msg.info)
}
)
}
)
}`