A design question for Windows applications, a better approach?

I am developing an application that will allow you to find pictures (screenshots) taken from certain programs. I will talk about the location of several programs in the application itself to launch it.

I was wondering how I should add new locations as time goes on, my first thought was to simply encode it in the application, but that would mean that the user had to reinstall it for the changes to take effect.

My second idea was to use an XML file to store all the locations, as well as other data, such as the name of the application. It also means that the user can add their own locations, if they so wish, and also share them via the Internet.

The second option turned out to be the best approach, but then I had to think about how it could be controlled on the user's computer. Ideally, I would like to use only one .exe, without relying on any external files such as XML, but this will return me to the first.

Would it be better to just use the ClickOnce deployment to create an entry in the Start menu and create a folder containing .exe files and file names?

Thanks for the feedback, I donโ€™t want to start implementing the application until the design is nailed.

+4
source share
3 answers

Actually, I wonโ€™t write anything hard to the application. This results in an inflexible design, as you correctly point out.

I usually store this type of configuration information in an XML file in the Local Application Data folder.

If your users are always (or often) connected to the Internet, you can consider an alternative (or additional) option to store this bookmark information in a web service.

EDIT:

Here is a piece of code that I have used over the years for this kind of thing

using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Xml.Serialization; namespace JTools.IO.Configuration { public static class ConfigManager<T> where T : new() { private const string FILENAME = "Config.xml"; public static T Load() { return Load(ConfigFile); } public static T Load(string fileName) { T ret = default(T); try { // Open file to read the data from using (FileStream fs = new FileStream(fileName, FileMode.Open)) { // Create an XmlSerializer object to perform the deserialization XmlSerializer xs = new XmlSerializer(typeof(T)); // Use the XmlSerializer object to deserialize the data from the file ret = (T)xs.Deserialize(fs); } } catch (System.IO.DirectoryNotFoundException) { throw new Exception("Could not find the data directory '" + fileName + "'"); } catch (System.IO.FileNotFoundException) { ret = new T(); } return ret; } public static void Save(T config) { Save(config, ConfigFile); } public static void Save(T config, string fileName) { // Create file to save the data to using (FileStream fs = new FileStream(fileName, FileMode.Create)) { // Create an XmlSerializer object to perform the serialization XmlSerializer xs = new XmlSerializer(typeof(T)); // Use the XmlSerializer object to serialize the data to the file xs.Serialize(fs, config); } } static private string configFile = null; static public string ConfigFile { get { if (configFile == null) { string appName = typeof(T).FullName; string baseFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string jFolder = Path.Combine(baseFolder, "JToolsConfig"); string dataPath = Path.Combine(jFolder, appName); if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } configFile = Path.Combine(dataPath, FILENAME); } return configFile; } } } } 
+3
source

The approach I would like to do is to have a Locations class (and a set) that I could serialize to an XML file (using XmlSerializer or DataContractSerializer ).

You can check for the existence of an XML file โ€” if it exists, deserialize it into your collection; if not, you can create a new collection with hard-coded default values.

+2
source

I suggest that you organize all your data in a user-readable way and ask the user where he wants him to be stored on his computer (using one or more XML files). Thus, the user can store XML files wherever he wants and understand what they are doing. He can use them to exchange his โ€œlibraryโ€ with others, he can apply changes to these XML files manually, he can even create his own program that uses the same file (some kind of add-in for your own program).

+1
source

Source: https://habr.com/ru/post/1309873/


All Articles