ribbons / RadioDownloader

An easy to use application for managing podcast subscriptions and downloads.
https://nerdoftheherd.com/tools/radiodld/
GNU General Public License v3.0
15 stars 11 forks source link

Added option to change program database location in Radio Downloader.exe.config. #203

Closed Boris-Ockham closed 8 years ago

Boris-Ockham commented 8 years ago

Because store.db contains data that should be backed up, it would be helpful if this database could be placed in a different directory than the executable. A way to implement this might be to add a ConnectionString to Settings.settings. In Database.cs the definition of FetchDbConn could be changed as follows:

        protected internal static SQLiteConnection FetchDbConn()
        {
            if (dbConn == null)
            {
                dbConn = new SQLiteConnection(string.IsNullOrEmpty(Properties.Settings.Default.StoreConnectionString) ? "Data Source=" + Path.Combine(FileUtils.GetAppDataFolder(), "store.db") + ";Version=3;New=False" : Properties.Settings.Default.StoreConnectionString);
                dbConn.Open();
            }

            return dbConn;
        }
ribbons commented 8 years ago

I think you might have misunderstood where the user's database is stored - the file store.db in the same folder as the application is an empty template which is used as a starting point or to compare the schema of an existing user database to manage upgrades.

If you check the source of FileUtils.GetAppDataFolder() it gives a path under the user's roaming application data folder which is the recommended place for user specific settings or data.

Please do let me know if I've misunderstood your issue though.

Boris-Ockham commented 8 years ago

The user's roaming application data folder contains a lot of data I don't care about. For that reason I don't make a backup of that folder. To find C:\Users[User]\AppData\Roaming\NerdoftheHerd.com\Radio Downloader is not trivial in any case. For that reason I have placed store.db in My Documents (with a different, in that context more explaining, name). I made StoreConnectionString an application-scope property, so that I could add this without the need to create a GUI for that in RadioDownloader. It would be better though to make this a user scope property. For that setting I don't need a backup. :-)

ribbons commented 8 years ago

If you would like to submit a pull request with an implementation of this using the ConfigurationManager.AppSettings functionality to configure it instead of Properties.Settings.* then I'd be happy to accept it. The latter ended up being rather unreliable when I used it previously (which is why the settings are now stored in the database).

Boris-Ockham commented 8 years ago

User scope settings are stored in C:\Users(Username)\AppData\Roaming(company-name-if-exists)(app-name).exe(Url|StrongName)(hash)(app-version)\user.config (see stackoverflow.com). The problem you mention may have something to do with the hash, which might change for some reason. Beside that every time you change the version the config is stored in a different directory. I don't expect the previous settings to be automatically copied to the new location.

It doesn't matter if you use Properties.Setting or ConfigurationManager. What matters is if you use user or application scope.

The ConfigurationManager doesn't have a method to open an arbitrary file, to be able to put the config-file directly in the GetAppDataFolder. When I want to use "user.config" then I have to add a dummy file with the name "user" in that folder. I tried to make a program that tries first the user scope connection string, and when not available the application level string. But I'm not able to open user.config in an editor on Windows 8 in the user level location. So without a user interface this doesn't help.

When using Properties.Setting the names in config must be decorated:

  <connectionStrings>
    <add name="RadioDld.Properties.Settings.StoreConnectionString"
        connectionString="data source=C:\Users\[User]\Documents\RadioDownloaderStore.db;Version=3;New=False"
        providerName="System.Data.SQLite.EF6" />
  </connectionStrings>

This looks like a good idea. When using ConfigurationManager however the name can be chosen freely.

protected internal static SQLiteConnection FetchDbConn()
{
  if (dbConn == null)
  {
    dbConn = new SQLiteConnection(ConfigurationManager.ConnectionStrings["Store"] == null ? 
      "Data Source=" + Path.Combine(FileUtils.GetAppDataFolder(), "store.db") + ";Version=3;New=False" :
      ConfigurationManager.ConnectionStrings["Store"].ConnectionString);
    dbConn.Open();
  }

  return dbConn;
}
    <connectionStrings>
        <add name="Store"
            connectionString="data source=C:\Users\[User]\Documents\RadioDownloaderStore.db;Version=3;New=False"
            providerName="System.Data.SQLite.EF6" />
    </connectionStrings>

I have no experience with changing something in github.

ribbons commented 8 years ago

User scope settings are stored in C:\Users(Username)\AppData\Roaming(company-name-if-exists)(app-name).exe(Url|StrongName)(hash)(app-version)\user.config (see stackoverflow.com). The problem you mention may have something to do with the hash, which might change for some reason. Beside that every time you change the version the config is stored in a different directory. I don't expect the previous settings to be automatically copied to the new location.

Yep, I'm aware of how the settings framework works - wasn't either of those issues (the version change is easily handled with the Upgrade method), the issues encountered 'in the wild' were mostly due to corruption of the user settings file and broken permissions.

It doesn't matter if you use Properties.Setting or ConfigurationManager. What matters is if you use user or application scope.

For this: ConfigurationManager and application scope please.

I have no experience with changing something in github.

Now would be a perfect opportunity to gain some experience :smile: - to get you started, the process is:

  1. Fork this repository (button at the top right of the screen)
  2. Clone your fork to your machine
  3. Create a new branch on your machine
  4. Make the changes required and commit them to the branch
  5. Push the new branch to your fork
  6. Create a pull request with your changes

Then I can see exactly what your proposed changes are and it makes it much easier to discuss the nitty-gritty.

I realise that this sounds like a lot of work (is a little bit of a learning curve) but after the first couple it is pretty straight-forward. Google is most certainly your friend & GitHub have lots of help and tutorials. You may also like to use the GitHub for Windows client as this would simplify steps 2-5 if you aren't familiar with Git.

Let me know if you get stuck.