1

I'm building a barebones Notepad-styled project (console-based, does not have a GUI as of now) and I'd like to track, display (and later use it in some ways) the number of times the console application has been launched. I don't know if this helps, but I'm building my console application on Windows 10, but I'd like it to run on Windows 7+ as well as on Linux distros such as Ubuntu and the like.

I prefer not storing the details in a file and then subsequently reading from it to maintain count. Please suggest a way or any other resource that details how to do this.

I'd put a strikethrough on my quote above, but SO doesn't have it apparently.

Note that this is my first time building such a project so I may not be familiar with advanced stuff... So, when you're answering please try to explain as is required for a not-so-experienced software developer.

Thanks & Have a great one!

Edit: It seems that the general advice is to use text files to protect portability and to account for the fact that if down-the-line, I need to store some extra info, the text file will come in super handy. In light of this, I'll focus my efforts on the text file.

Thanks to all for keeping my efforts from de-railing!

gourabix
  • 99
  • 1
  • 5
  • 22
  • 2
    If you want to be portable, text-files is the only way to do it. Especially on Linux where you don't have anything like the Windows registry. Why don't you want to use files? And why do you want this start-counter? What problem is it supposed to solve? – Some programmer dude Jul 16 '19 at 09:43
  • 2
    If you don't want to create the text-files yourself, you could perhaps use a library for that. One really big library, that supports something like that is Qt: https://doc.qt.io/qt-5/qsettings.html. If you use the native format there, then the settings will be stored in the registry on Windows systems and in text files on Linux. – Benjamin Bihler Jul 16 '19 at 09:44
  • @Someprogrammerdude I think having a text file just to maintain count of how many times the application has been launched seems a bit of an overkill. I can always include more details about its usage but as someone who is vocal about privacy, that goes against my ideologies. – gourabix Jul 16 '19 at 09:52
  • @Someprogrammerdude To answer your second question, the most primary requirement is to onboard an user on the application's first run. Say that the user decides to "reset" all data from the application, then the user is already aware of how the application runs and does not need to be re-onboarded. The secondary requirement is that I'll use it as part of the usage statistics if the user feels the need to see it. It's local and is never transmitted anywhere. It's for the user's eyes only. – gourabix Jul 16 '19 at 09:55
  • 1
    If you are already using some sort of settings, which are persistent, make a *read-only* setting `runCount`, which user can't modify and update it accordingly – Zereges Jul 16 '19 at 09:57
  • @BenjaminBihler If I'd have to use text-files then my console application should create it. The fact that the library is huge (and will definitely impact space & time complexity) is another reason why I'll try to avoid something like that. – gourabix Jul 16 '19 at 09:58
  • @Zereges As of now I don't have _persistent settings_ on my application. I'm not even aware such a thing exists! Checking that out now... Maybe you could help with some awesome resources? – gourabix Jul 16 '19 at 10:02
  • 2
    "I think having a text file just to maintain count of how many times the application has been launched seems a bit of an overkill" well given that the only persistent memory on a PC is the bios, I would suggest your other methods are somewhat limited. Since requirements change with time; what not call it just generic run statistics and save it in a format that will allow you to add more information as and when – UKMonkey Jul 16 '19 at 10:08
  • @UKMonkey Since the general consensus is to use text-files in favor of portability, I'll probably end up using them. And yes, using text-files to add info as & when required is a definite advantage over anything else, not to mention portability. – gourabix Jul 16 '19 at 10:13
  • @GourabIX It doesn't necessarily have to be a text file. A binary file would work as well. You can even encrypt it if you don't want the user to see it (though that's obviously just a hiccup for a determined attacker). – Bartek Banachewicz Jul 16 '19 at 10:23

1 Answers1

1

I prefer not storing the details in a file

In the comments, you wrote that the reason is security and you consider using a file as "over-kill" in this case.

Security can be solved easily - just encrypt the file. You can use a library like this to get it done.

In addition, since you are writing and reading to/from the file only once each time the application is opened/closed, and the file should take only small number of bytes to store such data, I think it's the right, portable solution.

If you still don't want to use a file, you can use windows registry to store the data, but this solution is not portable

SubMachine
  • 487
  • 3
  • 11