Code Monkey home page Code Monkey logo

Comments (3)

wintercooled avatar wintercooled commented on May 24, 2024

I've done this with a service in Windows and Linux (and Mac) so am happy to pick this up at some point. In Windows the folder location varies by which OS it is - so I've code I can re-use here to handle this.

from walletwasabi.

nopara73 avatar nopara73 commented on May 24, 2024

Sounds good. Just pay attention not to conflict with Electron's stuff. It messes into the appdata folder.

For reference, this is how Stratis and NTumbleBit is going it:

        /// <summary>
        /// Finds a location of the default data directory respecting different operating system specifics.
        /// </summary>
        /// <param name="appName">Name of the node, which will be reflected in the name of the data directory.</param>
        /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
        private void SetDefaultDataDir(string appName, Network network)
        {
            string directory = null;

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var home = Environment.GetEnvironmentVariable("HOME");
                if (!string.IsNullOrEmpty(home))
                {
                    this.Logger.LogInformation("Using HOME environment variable for initializing application data.");
                    directory = Path.Combine(home, "." + appName.ToLowerInvariant());
                }
                else
                {
                    throw new DirectoryNotFoundException("Could not find suitable datadir");
                }
            }
            else
            {
                var localAppData = Environment.GetEnvironmentVariable("APPDATA");
                if (!string.IsNullOrEmpty(localAppData))
                {
                    this.Logger.LogInformation("Using APPDATA environment variable for initializing application data.");
                    directory = Path.Combine(localAppData, appName);
                }
                else
                {
                    throw new DirectoryNotFoundException("Could not find suitable datadir");
                }
            }

            if (!Directory.Exists(directory))
                Directory.CreateDirectory(directory);

            directory = Path.Combine(directory, network.Name);
            if (!Directory.Exists(directory))
            {
                this.Logger.LogInformation("Creating data directory...");
                Directory.CreateDirectory(directory);
            }

            this.DataDir = directory;
        }

from walletwasabi.

nopara73 avatar nopara73 commented on May 24, 2024

Done.

from walletwasabi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.