internal static void Initialize()
        {
#if x86
            if (Environment.Is64BitOperatingSystem)
            {
                var appsDownloader64 = PathEx.Combine(PathEx.LocalDir, $"{ProcessEx.CurrentName}64.exe");
                if (File.Exists(appsDownloader64))
                {
                    ProcessEx.Start(appsDownloader64, EnvironmentEx.CommandLine(false));
                    Environment.ExitCode = 0;
                    Environment.Exit(Environment.ExitCode);
                }
            }
#endif

            Log.FileDir = Path.Combine(CorePaths.TempDir, "Logs");

            Ini.SetFile(PathEx.LocalDir, "..", "Settings.ini");
            Ini.SortBySections = new[]
            {
                Section,
                "Launcher"
            };

            Log.AllowLogging(Ini.FilePath, "DebugMode", Ini.GetRegex(false));

            if (Elevation.IsAdministrator)
            {
                var path = Path.Combine("HKCU\\Software\\Portable Apps Suite", CorePaths.HomeDir.Encrypt(ChecksumAlgorithms.Adler32), ProcessEx.CurrentId.ToString());
                if (Reg.CreateNewSubKey(path))
                {
                    AppDomain.CurrentDomain.ProcessExit += (s, e) => Reg.RemoveSubKey(path);
                }
            }

            if (Recovery.AppsSuiteIsHealthy())
            {
                return;
            }
            Environment.ExitCode = 1;
            Environment.Exit(Environment.ExitCode);
        }
Exemple #2
0
        /// <summary>
        ///     Enables/disables the registry key redirection.
        /// </summary>
        /// <param name="option">
        ///     The option that determines whether the redirect will be enabled or disabled.
        /// </param>
        /// <param name="keys">
        ///     The registry keys for redirecting.
        /// </param>
        public static void KeyRedirection(PortalizerActions option, params string[] keys)
        {
            if (keys == null || keys.Length == 0)
            {
                return;
            }
            var backup = PathEx.Combine(Attributes.DataDir, $"Temp\\backup-{{{EnvironmentEx.MachineId}}}.reg");

            switch (option)
            {
            case PortalizerActions.Disable:
                if (keys.Length > 0)
                {
                    Reg.ExportKeys(Attributes.RegFilePath, keys);
                    foreach (var key in keys)
                    {
                        Reg.RemoveSubKey(key);
                    }
                    Reg.RemoveEntry(Attributes.RegPath, nameof(Attributes.RegKeys));
                }
                if (!File.Exists(backup))
                {
                    return;
                }
                Reg.ImportFile(backup);
                FileEx.TryDelete(backup);
                break;

            default:
                if (!Reg.SubKeyExists(Attributes.RegPath))
                {
                    Reg.CreateNewSubKey(Attributes.RegPath);
                }
                if (!Reg.EntryExists(Attributes.RegPath, nameof(Attributes.RegKeys)) && keys.Any(Reg.SubKeyExists))
                {
                    try
                    {
                        var dir = Path.GetDirectoryName(backup);
                        if (string.IsNullOrEmpty(dir))
                        {
                            throw new ArgumentNullException(dir);
                        }
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }
                        FileEx.Delete(backup);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                    }
                    if (!File.Exists(backup))
                    {
                        Reg.ExportKeys(backup, keys);
                    }
                    foreach (var key in keys)
                    {
                        Reg.RemoveSubKey(key);
                    }
                }
                Reg.Write(Attributes.RegPath, nameof(Attributes.RegKeys), keys, RegistryValueKind.MultiString);
                if (File.Exists(Attributes.RegFilePath))
                {
                    Reg.ImportFile(Attributes.RegFilePath);
                }
                break;
            }
        }