Stall.Program.InstallMain C# (CSharp) Method

InstallMain() static private method

static private InstallMain ( Options opts ) : int
opts Options
return int
        static int InstallMain(Options opts)
        {
            if (opts.Target == null)
                return RaiseError(Errors.NoTargets, Constants.Usage);

            string root = Path.Combine(Cache.LocalAppData, opts.AppName);
            var directory = new DirectoryInfo(root);

            if (directory.Exists)
            {
                if (!opts.Overwrite)
                    return RaiseError(Errors.ExistingFolder, $"Directory {root} already exists! Exiting...");

                // rm -rf that directory
                Directory.Delete(root, true); // TODO: This fails when the app is still running?
                // TODO: What if the user specifies a folder in AppData\Local?
            }

            // Copy the folder into AppData
            Folder.RecursiveCopy(opts.Target.FullName, root);

            if (opts.IsScript | opts.AddToPath)
                directory.AddToPath(); // $PATH env var

            if (!opts.IsScript)
            {
                int error = ShortcutMain(opts);
                if (error != 0)
                    return error;

                return RegMain(opts);
            }

            return 0;
        }