简体   繁体   English

电子修改文件存储在 .asar

[英]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 :)谢谢你的帮助 :)

What build tool do you use?你使用什么构建工具? If you are using electron builder, you can check out asarUnpack in configuration file here or extraFiles here如果您使用的电子制造商,你可以检查出asarUnpack配置文件在这里extraFiles这里

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-settingspreferences

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.

相关问题 电子如何在ASAR之外存储文件? - electron how to store files outside of ASAR? 使用electron-builder时如何修改app.asar的文件夹结构? - How to modify the folder structure of app.asar when using electron-builder? 如何更改 electron 中的路径,以便将文件保存到未打包在 app.asar 文件中的不同目录? - How to change the path in electron so it saves files to different directory not packed in app.asar file? 在 Electron 应用程序中仅使用 asar 打包某些目录 - Package only certain directories with asar in an Electron application 当电子应用程序包装在asar中时使用require - Using require when electron app is packaged in an asar 使用 electron 在 app.asar 中包含额外的文件 - Include extra files inside app.asar using electron 使用--asar提取电子封装时,Chrome驱动程序无法正常工作 - Chrome driver not working when extracting electron package using --asar Electron:将用户可编辑数据存储在.txt文件中 - Electron: Store user editable data in .txt file 如何修改电子浏览器窗口中使用的 HTML 文件? - How to modify the HTML file used in an Electron's BrowserWindow? Electron:无法加载预加载脚本:Resources/app.asar/src/preload.js - Electron: Unable to load preload script: Resources/app.asar/src/preload.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM