[英]Electron modify file store in .asar
I would like, from the Electron index.html file, to modify a config file present in the.asar of my application.我想从 Electron index.html 文件中修改我的应用程序的 .asar 中存在的配置文件。 In my case I need to change, if necessary, my application database config in order to work.
就我而言,如有必要,我需要更改我的应用程序数据库配置才能工作。
I understood that .asar is in readOnly and I wanted to know if there is a way to modify this config file from electron without changing its position in my application?我知道 .asar 是只读的,我想知道是否有办法从电子修改这个配置文件而不改变它在我的应用程序中的位置?
I see the extraResources option but I did not understand how its work.我看到了 extraResources 选项,但我不明白它是如何工作的。
It's also important that the config file stay in myapp/config folder.配置文件保留在 myapp/config 文件夹中也很重要。
Thanks for your help :)谢谢你的帮助 :)
asar is in readonly
asar 处于只读状态
as you mentioned asar intended to be readonly package.正如你提到的 asar 打算成为只读包。 For runtime-changing config, you should place it outside of asar and change values accordingly.
对于运行时更改配置,您应该将其放在 asar 之外并相应地更改值。
I was able to edit the read-only file by first changing the file permissions programmatically and then editing it.我能够通过首先以编程方式更改文件权限然后编辑它来编辑只读文件。
fs.chmod(filename, 0666, (error) => {
console.log('Changed file permissions');
});
...
code to modify file
...
To manage settings you should use a node package that's specifically designed for this, like electron-settings
or preferences
.要管理设置,您应该使用专门为此设计的节点包,例如
electron-settings
或preferences
。
As an alternative one may manually read an write config files that you place in the platform's native config directory.作为替代方案,您可以手动读取放置在平台本机配置目录中的写入配置文件。
Mutable application settings shouldn't be stored in the asar file.可变应用程序设置不应存储在 asar 文件中。 If it's required to replace a file in an asar archive for any other reason, use the the
asar
program to extract the entire archive to a temporary directory, replace the file(s) you want, then create a new asar file, replacing the original asar file.如果由于任何其他原因需要替换 asar 存档中的文件,请使用
asar
程序将整个存档解压缩到临时目录,替换所需的文件,然后创建一个新的 asar 文件,替换原始文件asar 文件。
To unpack .asar files -> asar extract electron.asar app
解压 .asar 文件 ->
asar extract electron.asar app
modify as per your needs根据您的需要修改
To pack .asar files -> asar pack . electron.asar
打包 .asar 文件 ->
asar pack . electron.asar
asar pack . electron.asar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.