Exemplo n.º 1
0
        private static void Main()
        {
            InitializeConsole();
            foreach (var arg in EnvironmentEx.CommandLineArgs(true, 1, false))
            {
                if (_active)
                {
                    Console.WriteLine();
                    Console.WriteLine();
                }
                var file = PathEx.Combine(arg);
                if (!File.Exists(file))
                {
                    WriteInnerLine($"Cannot find \'{file}\'", "Error", ErrorCaptionFgColor);
                    continue;
                }
                try
                {
                    var name = Path.GetFileName(file);
                    if (!string.IsNullOrWhiteSpace(name))
                    {
                        WriteInnerLine(name, "File", !name.EndsWithEx(".exe", ".dll") ? WarnCaptionFgColor : DefaultCaptionFgColor);
                    }

                    var version = FileEx.GetFileVersion(file)?.ToString();
                    if (!string.IsNullOrWhiteSpace(version) && !version.Equals("0.0.0.0"))
                    {
                        WriteInnerLine(version, "Version", DefaultCaptionFgColor);
                    }

                    var subject = FileEx.GetSignatureSubject(file);
                    if (!string.IsNullOrWhiteSpace(subject))
                    {
                        WriteInnerLine(subject, "Subject", DefaultCaptionFgColor);
                    }

                    var status = FileEx.GetSignatureStatus(file);
                    if (!string.IsNullOrWhiteSpace(status))
                    {
                        WriteInnerLine(status, "Status", status.ContainsEx("Unknown", "Error") ? ErrorCaptionFgColor : status.ContainsEx("NotSigned") ? WarnCaptionFgColor : DefaultCaptionFgColor);
                    }
                }
                catch (Exception ex) when(ex.IsCaught())
                {
                    WriteInnerLine(ex.Message, "Error", ErrorCaptionFgColor);
                }
            }
            ExitConsole();
        }
Exemplo n.º 2
0
        private static void Main()
        {
            Settings.Initialize();

            var instanceKey = PathEx.LocalPath.GetHashCode().ToString();

            using (new Mutex(true, instanceKey, out var newInstance))
            {
                Language.ResourcesNamespace = typeof(Program).Namespace;
                MessageBoxEx.TopMost        = true;

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (newInstance && Arguments.ValidPaths.Any() && !ActionGuid.IsDisallowInterface)
                {
                    Application.Run(new OpenWithForm().Plus());
                    return;
                }

                if (newInstance || ActionGuid.IsAllowNewInstance)
                {
                    Application.Run(new MenuViewForm().Plus());
                    return;
                }

                if (!EnvironmentEx.CommandLineArgs(false).Any())
                {
                    return;
                }

                switch (EnvironmentEx.CommandLineArgs(false).Count)
                {
                case 1:
                {
                    var first = EnvironmentEx.CommandLineArgs(false).First();
                    switch (first)
                    {
                    case ActionGuid.FileTypeAssociationAll:
                        foreach (var appData in CacheData.CurrentAppInfo)
                        {
                            var assocData = appData.Settings?.FileTypeAssoc;
                            assocData?.SystemRegistryAccess?.AssociateFileTypes(true);
                        }
                        return;

                    case ActionGuid.RepairAppsSuite:
                        Recovery.RepairAppsSuite();
                        return;

                    case ActionGuid.RepairDirs:
                        Recovery.RepairAppsSuiteDirs();
                        return;

                    case ActionGuid.RepairVariable:
                        Recovery.RepairEnvironmentVariable();
                        return;
                    }
                    break;
                }

                case 2:
                {
                    var first = EnvironmentEx.CommandLineArgs(false).First();
                    switch (first)
                    {
                    case ActionGuid.FileTypeAssociation:
                        FileTypeAssoc.Associate(EnvironmentEx.CommandLineArgs(false).SecondOrDefault());
                        return;

                    case ActionGuid.RestoreFileTypes:
                        FileTypeAssoc.Restore(EnvironmentEx.CommandLineArgs(false).SecondOrDefault());
                        return;

                    case ActionGuid.SystemIntegration:
                        SystemIntegration.Enable(EnvironmentEx.CommandLineArgs(false).SecondOrDefault().ToBoolean());
                        return;
                    }
                    break;
                }
                }

                if (!Arguments.ValidPaths.Any())
                {
                    return;
                }

                IntPtr hWnd;
                var    stopwatch = new Stopwatch();
                stopwatch.Start();
                do
                {
                    hWnd = Reg.Read(Settings.RegistryPath, "Handle", IntPtr.Zero);
                }while (hWnd == IntPtr.Zero && stopwatch.Elapsed.TotalSeconds <= 10);
                if (hWnd != IntPtr.Zero)
                {
                    WinApi.NativeHelper.SendArgs(hWnd, Arguments.ValidPathsStr);
                }
            }
        }
Exemplo n.º 3
0
        private static void Main()
        {
            Log.FileDir = Path.Combine(TmpDir, "logs");

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

            Log.AllowLogging(Ini.FilePath);

#if x86
            string appsLauncher64;
            if (Environment.Is64BitOperatingSystem && File.Exists(appsLauncher64 = PathEx.Combine(PathEx.LocalDir, $"{ProcessEx.CurrentName}64.exe")))
            {
                ProcessEx.Start(appsLauncher64, EnvironmentEx.CommandLine(false));
                return;
            }
#endif

            if (!RequirementsAvailable())
            {
                var updPath = PathEx.Combine(PathEx.LocalDir, "Binaries\\Updater.exe");
                if (File.Exists(updPath))
                {
                    ProcessEx.Start(updPath);
                }
                else
                {
                    Lang.ResourcesNamespace = typeof(Program).Namespace;
                    if (MessageBox.Show(Lang.GetText(nameof(en_US.RequirementsErrorMsg)), Resources.Titel, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                    {
                        Process.Start(PathEx.AltCombine(Resources.GitProfileUri, Resources.GitReleasesPath));
                    }
                }
                return;
            }

            if (Log.DebugMode < 2)
            {
                CheckEnvironmentVariable();
            }

            var instanceKey = PathEx.LocalPath.GetHashCode().ToString();
            using (new Mutex(true, instanceKey, out bool newInstance))
            {
                MessageBoxEx.TopMost = true;

                Lang.ResourcesNamespace = typeof(Program).Namespace;

                if (newInstance && ReceivedPathsArray.Count == 0 || ActionGuid.IsAllowNewInstance)
                {
                    SetInterfaceSettings();
                    Application.Run(new MenuViewForm().Plus());
                    return;
                }

                if (EnvironmentEx.CommandLineArgs(false).Count == 0)
                {
                    return;
                }

                if ((newInstance || ActionGuid.IsAllowNewInstance) && !ActionGuid.IsDisallowInterface)
                {
                    SetInterfaceSettings();
                    Application.Run(new OpenWithForm().Plus());
                    return;
                }

                if (ActionGuid.IsRepairDirs)
                {
                    return;
                }

                if (EnvironmentEx.CommandLineArgs(false).Count == 2)
                {
                    var first = EnvironmentEx.CommandLineArgs(false).First();
                    switch (first)
                    {
                    case ActionGuid.FileTypeAssociation:
                        SetInterfaceSettings();
                        AssociateFileTypesHandler(EnvironmentEx.CommandLineArgs(false).Skip(1).First());
                        return;

                    case ActionGuid.RestoreFileTypes:
                        SetInterfaceSettings();
                        RestoreFileTypesHandler(EnvironmentEx.CommandLineArgs(false).Skip(1).First());
                        return;

                    case ActionGuid.SystemIntegration:
                        SetInterfaceSettings();
                        SystemIntegrationHandler(EnvironmentEx.CommandLineArgs(false).Skip(1).First().ToBoolean());
                        return;
                    }
                }

                if (ReceivedPathsArray.Count == 0)
                {
                    return;
                }
                IntPtr hWnd;
                do
                {
                    hWnd = Reg.Read(RegPath, "Handle", IntPtr.Zero);
                }while (hWnd == IntPtr.Zero);
                WinApi.NativeHelper.SendArgs(hWnd, ReceivedPathsStr);
            }
        }