0

I want to store gigabytes of media locally - and have them automatically removed when the app is uninstalled. I found this question, but it requires the qt library, and only stores app settings.

I'm guessing there's a convention followed across Windows, Mac and Linux. Are there any std helpers - or the like - for storing app data, cross-platform.

If not, is there a convention for the paths would I need to store these in, on each platform? I plan on creating an installer for each operating system, so it would be useful to know these paths so I can install my other data here.

Tobi Akinyemi
  • 804
  • 1
  • 8
  • 24
  • 1
    No, there is nothing in the C++ library for this. – Sam Varshavchik Jun 15 '20 at 12:21
  • 2
    It's more complex for Linux. You have different package managers like rpm, dnf, yum, apt, dpkg, pacman, yast, apm and many more. In addition there are crosslinux package managers like snap, flatpak and appimage. Even folder structure can be different on different distros even thought there is a [Filesystem Hierarchy Standard](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard) – Thomas Sablik Jun 15 '20 at 12:32
  • 1
    You have two cross-platform problems: (1) identifying the right place to store a big chunk of app data, and (2) how to hook the uninstall process to clean it up. Both of these will be system-specific. Frameworks like Qt have done the leg work to figure out what the right answer for each system is and do that when you call their generic interface. Qt also has an installer system, and CMake's CPack may help there too, but I've not tried them for your specific use case. So you can either adopt some helpers that help with such problems or roll your own, which will be tricky to test everywhere. – metal Jun 15 '20 at 12:34

2 Answers2

0

I want to store gigabytes of media locally - and have them automatically removed when the app is uninstalled.

The average but skilled user is capable of copying the media elsewhere and would backup his disk regularly.

However, most C++ programs have a main accepting program arguments, and you could conventionally provide program arguments to remove the data. Be sure to properly document your design.

See this answer. On Unix or POSIX systems (Linux, MacOSX, FreeBSD....), you might accept a --clean-all-the-mess program option.

I'm guessing there's a convention followed across Windows, Mac and Linux.

As far as I know, this guess is wrong. (things are much more complex)

More generally, read about package managers. There are many of them. See guix for an interesting example. Debian and Fedora have different ones. Look into GNU stow and autoconf.

You could want to use a database, perhaps SQLite or PostGreSQL.

On Linux, see also Advanced Linux Programming then syscalls(2) and more about systemd.

On Windows, read about the WinAPI.

Is there a convention for the paths would I need to store these

Linux has hier(7) but some Linux distributions (including Android) don't follow that.

My recommendation: study the C++ code of some open source software close to your goals. You could find some of them on github or gitlab or SoftwareHeritage. See also POCO.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
-1

"Application Uninstall" event is visible to the OS, so your best bet is on finding some OS-specific hooks to register your call-backs to remove your local files yourself.

EDIT: C++ STL is a piece of code (library) to write applications that run on top of some OS, so STL is not the place to look for application install/uninstall events, that are OS-level events. But nothing prevents you from writing an Uninstaller application for any OS. The question is who or how and when it will be executed.

Hack06
  • 963
  • 1
  • 12
  • 20
  • Where is this Application Uninstall event in Linux? – Thomas Sablik Jun 15 '20 at 12:28
  • I'm not a linux programmer, but if you're concerned about linux, imho it's managing all the apps as packages via its package-managers. So to provide such a functionality for your app you need to have your app listed by those package-managers. How? I have no idea, but try googling and reading about PPA (Personal Package Archive). – Hack06 Jun 15 '20 at 12:34
  • So this is a comment but not an answer – Thomas Sablik Jun 15 '20 at 12:36
  • @ThomasSablik, My answer is above comments. – Hack06 Jun 15 '20 at 12:36
  • _"Application Uninstall event is visible to the OS"_ is not true for all Linux distros. There are enough Linux distros without package manager. – Thomas Sablik Jun 15 '20 at 12:38
  • Visible doesn't mean that they necessarily do something with it. I was justifying the wrong direction of thoughts that OP was moving along. – Hack06 Jun 15 '20 at 12:43
  • @ThomasSablik, besides visibility, the original question was not particularly about linux OS. My comment about package-managers in linux was (indeed a comment as you noticed) a reply to your comment. – Hack06 Jun 15 '20 at 12:56
  • You don't even address _"Where do I store cross platform C++ app storage?"_ – Thomas Sablik Jun 15 '20 at 12:57
  • @ThomasSablik, I've explained the infeasibility of the question, why should I have even tried to answer it afterwards? – Hack06 Jun 15 '20 at 13:02
  • 1
    You have a usual filesystem hierarchy for the three mentioned OS (Windows, Linux, Mac). You could answer _"If not, is there a convention for the paths would I need to store these in, on each platform?"_ – Thomas Sablik Jun 15 '20 at 13:13
  • @ThomasSablik, I don't think that any of those 3 OS have a "usual filesystem", in sense that each of those is unique and is quite different from each other. Yes, I could answer to many other questions as well, but I chose not to. – Hack06 Jun 15 '20 at 13:30
  • That is what I meant with _"So this is a comment but not an answer"_. You didn't answer this question but you gave a helpful comment. – Thomas Sablik Jun 15 '20 at 13:31
  • 1
    @ThomasSablik, I already got your point that you dislike my answer, but I'm cool with it. Thank you. – Hack06 Jun 15 '20 at 13:33