JavaPackager icon indicating copy to clipboard operation
JavaPackager copied to clipboard

How to keep old data files when upgrading?

Open forqsg opened this issue 1 year ago • 8 comments

I want to know, when I package a new exe installation package version, I need to upgrade the software, but the previously installed version has some data needed by the new version, for example, I save some data using sqlite. How can I choose to retain the previously useful data when installing the new exe installation package? Or choose not to overwrite the old data?

forqsg avatar Jun 06 '24 09:06 forqsg

Hi @forqsg! I think that your app shouldn't store data in app's folder. There's another locations for this. What's your OS?

fvarrui avatar Jun 06 '24 09:06 fvarrui

Hi @forqsg! I think that your app shouldn't store data in app's folder. There's another locations for this. What's your OS?

Hi @fvarrui ! Your idea is correct; data storage should be decoupled from the application. However, I have a small desktop application that uses embedded sqlite.db for data storage. I want to package these files as <additionalResource> into the installation package exe. When the exe installation package is run, it will extract these resources to the specified installation directory, including the data/sqlite.db file (ignoring data storage security). This way, when the program runs, it can load and retrieve data from data/sqlite.db using relative paths.

Of course, sqlite.db will accumulate some historical data, so when I use the exe installation package for an update, I want to continue using the data in the old data/sqlite.db and not replace it. I'm not sure if this can be implemented in this way, or if there are any tags in the plugin that can be configured to specify paths for resources that do not need to be replaced. Currently, I manually back up the data, then copy it back after the upgrade. My OS is Windows 10 x64.

forqsg avatar Jun 07 '24 02:06 forqsg

Hi @forqsg! Sorry for my late reply.

Of course, sqlite.db will accumulate some historical data, so when I use the exe installation package for an update, I want to continue using the data in the old data/sqlite.db and not replace it. I'm not sure if this can be implemented in this way, or if there are any tags in the plugin that can be configured to specify paths for resources that do not need to be replaced. Currently, I manually back up the data, then copy it back after the upgrade. My OS is Windows 10 x64.

This is not supported by JP.

But I would approach it this way:

  • if data is user-specific, save their data to their profile (you can use this property: System.getProperty("user.home")). There you can create a folder with the name of your application (e.g. C:\Users\fvarrui\.myapp) and store your SQLite database inside. This is what I usually do, but not sure if it's what you want. This approach works for all platforms.
  • if data is shared by all users, then you should save it in C:\ProgramData\myapp (you can use this environment variable: System.getenv("ProgramData")) ... notice that this last approach would only work on Windows.

I hope it helps!

fvarrui avatar Jun 25 '24 15:06 fvarrui

Any news about your issue?

fvarrui avatar Jun 29 '24 19:06 fvarrui

Hi @fvarrui Sorry for my late reply.

But I would approach it this way:

  • if data is user-specific, save their data to their profile (you can use this property: System.getProperty("user.home")). There you can create a folder with the name of your application (e.g. C:\Users\fvarrui.myapp) and store your SQLite database inside. This is what I usually do, but not sure if it's what you want. This approach works for all platforms.
  • if data is shared by all users, then you should save it in C:\ProgramData\myapp (you can use this environment variable: System.getenv("ProgramData")) ... notice that this last approach would only work on Windows.

The folder with the name of the application (e.g. C:\Users\fvarrui.myapp), can it be automatically generated by configuration at installation time?

forqsg avatar Jul 02 '24 03:07 forqsg

It can be created by your app when it starts. Your app only has to check if it exists, and if not, it creates this folder and copy an empty pre-configured sqlite database file from your jar resources to this folder. Next time, when your app starts and checks, as this folder exists, do nothing.

fvarrui avatar Jul 02 '24 09:07 fvarrui

It can be created by your app when it starts. Your app only has to check if it exists, and if not, it creates this folder and copy an empty pre-configured sqlite database file from your jar resources to this folder. Next time, when your app starts and checks, as this folder exists, do nothing.

Yeah, I'm pretty much doing what you're thinking. I originally thought that I could choose the directory where the data was stored during installation. Ha ha, at present, according to your idea to deal with, thank you very much for your reply!

forqsg avatar Jul 02 '24 10:07 forqsg

JP just creates an installer to install your app easily, then your app has to do all the magic 😃

Happy to help!

fvarrui avatar Jul 02 '24 10:07 fvarrui

Could we close this issue?

fvarrui avatar Jul 04 '24 09:07 fvarrui

Could we close this issue?

Yes,I closed it

forqsg avatar Jul 04 '24 09:07 forqsg