예제 #1
0
        public Task <ApplicationDetectionResult> DetectAsync()
        {
            using (var key = Registry.ClassesRoot.OpenSubKey(@"SOFTWARE\Deluge", false))
            {
                if (key == null)
                {
                    Trace.TraceInformation("Couldn't find Deluge key at HKCR\\SOFTWARE\\Deluge");
                    return(Task.FromResult(ApplicationDetectionResult.NotFound()));
                }

                var startMenuFolder = (string)key.GetValue("Start Menu Folder");
                if (string.IsNullOrWhiteSpace(startMenuFolder))
                {
                    Trace.TraceInformation("Couldn't find Deluge start menu location");
                    return(Task.FromResult(ApplicationDetectionResult.NotFound()));
                }

                // Get the link
                var linkPath = Path.Combine(Environment.ExpandEnvironmentVariables(@"%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs"), startMenuFolder);
                if (!Directory.Exists(linkPath))
                {
                    Trace.TraceInformation("Couldn't find Deluge shortcut folder: " + linkPath);
                    return(Task.FromResult(ApplicationDetectionResult.NotFound()));
                }

                var shortcut = Path.Combine(linkPath, "Deluge.lnk");
                if (!File.Exists(shortcut))
                {
                    Trace.TraceInformation("Couldn't find Deluge shortcut: " + shortcut);
                    return(Task.FromResult(ApplicationDetectionResult.NotFound()));
                }

                var path = ShellLinkHelper.ResolveShortcut(shortcut);
                Trace.TraceInformation("Deluge location is " + path);

                var result = ApplicationDetectionResult.Create(this, "Deluge", Path.GetDirectoryName(path));

                var exe = new FileInfo(path);
                if (!exe.Exists)
                {
                    Trace.TraceInformation("Deluge exe not found @ " + path);
                    result.IsPresent = false;
                }

                var version = FileVersionInfo.GetVersionInfo(exe.FullName);
                result.Description = version.ProductName;
                result.Version     = version.FileVersion;

                return(Task.FromResult(result));
            }

            // DisplayName: Deluge 1.3.15
            // UninstallString: C:\Program Files (x86)\Deluge\deluge-uninst.exe
            var uninstallKey  = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Deluge";
            var uinstallValue = @"";

            // Recent Apps GUID: {86B4A402-4897-48E8-8D82-0D19C33E1431}
            // AppId: {7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\Deluge\deluge.exe
            // AppPath: C:\Program Files (x86)\Deluge\deluge.exe
        }
예제 #2
0
        public void Shortcuts()
        {
            var path         = ShellLinkHelper.ResolveShortcut(@"C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessibility\Magnify.lnk");
            var expectedPath = Environment.ExpandEnvironmentVariables(@"%windir%\system32\magnify.exe");

            Assert.AreEqual(expectedPath, path);
        }
예제 #3
0
        private async void goToLocalItem()
        {
            SmartItem item = LocalList.SelectedItem();

            if (item == null)
            {
                return;
            }

            if (item.IsFile)
            {
                if (item.Extension == "lnk")
                {
                    string path = ShellLinkHelper.GetPath(item.FullName);
                    if ((path != null) && DirectoryHelper.Exists(path))
                    {
                        await setLocalList(path);
                    }
                    else
                    {
                        try { System.Diagnostics.Process.Start(item.FullName); }
                        catch (Exception exp) { ExceptionHelper.Log(exp); }
                    }
                }
            }
            else
            {
                await setLocalList(item.FullName);
            }
        }
        public override RdProjectTemplateContent CreateContent(DotNetProjectTemplateExpander expander, IDotNetTemplateContentFactory factory,
                                                               int index, IDictionary <string, string> context)
        {
            var content   = factory.CreateNextParameters(new[] { expander }, index + 1, context);
            var parameter = expander.TemplateInfo.GetParameter(Name);

            if (parameter == null)
            {
                return(content);
            }

            var defaultPath = "";

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.MacOSX:
                defaultPath = @"/Applications/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll";
                break;

            case PlatformID.Unix:
                defaultPath = @"/opt/Unity/Editor/Data/Managed/UnityEngine.dll";
                if (File.Exists(defaultPath))
                {
                    break;
                }

                var home = Environment.GetEnvironmentVariable("HOME");
                if (string.IsNullOrEmpty(home))
                {
                    break;
                }

                var path = new DirectoryInfo(home).GetDirectories("Unity*").Select(unityDir => Path.Combine(unityDir.FullName, @"Editor/Data/Managed/UnityEngine.dll")).FirstOrDefault(File.Exists);
                if (path == null)
                {
                    break;
                }
                defaultPath = path;
                break;

            default:
                defaultPath = @"C:\Program Files\Unity\Editor\Data\Managed\UnityEngine.dll";
                if (File.Exists(defaultPath))
                {
                    break;
                }

                var lnks    = FileSystemPath.Parse(@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs").GetChildDirectories("Unity*").SelectMany(a => a.GetChildFiles("Unity.lnk")).ToArray();
                var dllPath = lnks.Select(a => ShellLinkHelper.ResolveLinkTarget(a).Directory.Combine(@"Data\Managed\UnityEngine.dll")).Where(b => b.ExistsFile).OrderBy(c => new FileInfo(c.FullPath).CreationTime).LastOrDefault();
                if (dllPath != null)
                {
                    defaultPath = dllPath.FullPath;
                }

                break;
            }

            return(new RdProjectTemplateTextParameter(Name, defaultPath, Tooltip, RdTextParameterStyle.FileChooser, content));
        }
예제 #5
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs args)
        {
            if (!FinishEnabled && fromErrorDlgOption.IsSet)
            {
                switch (MessageBox.Show(
                            this,
                            Tx.T("msg.cancel before submit", "cmd", Path.GetFileNameWithoutExtension(Application.ExecutablePath)),
                            Text,
                            MessageBoxButtons.YesNoCancel,
                            MessageBoxIcon.Question))
                {
                case DialogResult.Yes:
                    // Create the desktop shortcut
                    string arguments = "/shortcut";
                    if (logPathOption.IsSet)
                    {
                        arguments += " /logpath \"" + logPathOption.Value + "\"";
                    }
                    arguments += " /endtime " + appStartTime.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'");
                    string desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                    string linkFile   = PathUtil.GetUniqueFileName(Path.Combine(desktopDir, Tx.T("shortcut.name") + ".lnk"));
                    ShellLinkHelper.CreateLink(linkFile, Application.ExecutablePath, arguments);
                    break;

                case DialogResult.No:
                    // Nothing to do, just quit
                    break;

                default:
                    // Do not quit (unless Windows shutdown)
                    args.Cancel = args.CloseReason != CloseReason.WindowsShutDown;
                    if (args.Cancel)
                    {
                        return;                                            // Don't clean up if we don't quit
                    }
                    break;
                }
            }

            Cleanup();
        }
예제 #6
0
        public SettingsWindowViewModel(HookService hookService)
        {
            this.Title        = "Settings";
            this._hookService = hookService;

            this.Libraries = ProductInfo.Libraries.Aggregate(
                new List <BindableTextViewModel>(),
                (list, lib) =>
            {
                list.Add(new BindableTextViewModel {
                    Text = list.Count == 0 ? "Build with " : ", "
                });
                list.Add(new HyperlinkViewModel {
                    Text = lib.Name.Replace(' ', Convert.ToChar(160)), Uri = lib.Url
                });
                return(list);
            });
            this._HasStartupLink = ShellLinkHelper.ExistsStartup();

            Disposable.Create(() => LocalSettingsProvider.Instance.SaveAsync().Wait())
            .AddTo(this);
        }
예제 #7
0
        private bool MessageReceived(string msg)
        {
            var split = msg.IndexOf('|');

            if (split == -1)
            {
                return(false);
            }

            if (_lastOperation != null && _lastOperation.Status == DispatcherOperationStatus.Pending)
            {
                _lastOperation.Abort();
                Debug.WriteLine("Dispatcher task canceled");
            }

            var wParam = msg.Substring(0, split);
            var lParam = msg.Substring(split + 1, msg.Length - split - 1);

            lParam = ShellLinkHelper.GetTarget(lParam);

            switch (wParam)
            {
            case PipeMessages.RunAndClose:
                Application.Current.Dispatcher.BeginInvoke(
                    new Action(() => ViewWindowManager.GetInstance().RunAndClosePreview()),
                    DispatcherPriority.ApplicationIdle);
                return(false);

            case PipeMessages.Invoke:
                _lastOperation = Application.Current.Dispatcher.BeginInvoke(
                    new Action(() => ViewWindowManager.GetInstance().InvokePreview(lParam)),
                    DispatcherPriority.ApplicationIdle);
                return(false);

            case PipeMessages.Switch:
                _lastOperation = Application.Current.Dispatcher.BeginInvoke(
                    new Action(() => ViewWindowManager.GetInstance().SwitchPreview(lParam)),
                    DispatcherPriority.ApplicationIdle);
                return(false);

            case PipeMessages.Toggle:
                _lastOperation = Application.Current.Dispatcher.BeginInvoke(
                    new Action(() => ViewWindowManager.GetInstance().TogglePreview(lParam)),
                    DispatcherPriority.ApplicationIdle);
                return(false);

            case PipeMessages.Forget:
                Application.Current.Dispatcher.BeginInvoke(
                    new Action(() => ViewWindowManager.GetInstance().ForgetCurrentWindow()),
                    DispatcherPriority.ApplicationIdle);
                return(false);

            case PipeMessages.Close:
                Application.Current.Dispatcher.BeginInvoke(
                    new Action(() => ViewWindowManager.GetInstance().ClosePreview()),
                    DispatcherPriority.ApplicationIdle);
                return(false);

            case PipeMessages.Quit:
                return(true);

            default:
                return(false);
            }
        }
        public List <FileSystemPath> GetPossibleMonoPaths()
        {
            switch (PlatformUtil.RuntimePlatform)
            {
            case PlatformUtil.Platform.MacOsX:
            {
                var monoFolders = new List <FileSystemPath>();
                var home        = FileSystemPath.Parse("/Applications");
                var unityDirs   = home.GetChildDirectories("Unity*");
                monoFolders.AddRange(unityDirs.Select(unityDir =>
                                                      unityDir.Combine(@"Unity.app/Contents/MonoBleedingEdge")));

                monoFolders.AddRange(unityDirs.Select(unityDir =>
                                                      unityDir.Combine(@"Unity.app/Contents/Frameworks/MonoBleedingEdge")));

                // /Applications/Unity/Hub/Editor/2018.1.0b4/Unity.app
                monoFolders.AddRange(home.Combine("Unity/Hub/Editor").GetChildDirectories().Select(unityDir =>
                                                                                                   unityDir.Combine(@"Unity.app/Contents/MonoBleedingEdge")));

                return(monoFolders);
            }

            case PlatformUtil.Platform.Linux:
            {
                var monoFolders = new List <FileSystemPath>();
                var home        = Environment.GetEnvironmentVariable("HOME");

                // ReSharper disable once UseObjectOrCollectionInitializer
                var homes = new List <FileSystemPath>();
                homes.Add(FileSystemPath.Parse("/opt"));
                if (!string.IsNullOrEmpty(home))
                {
                    homes.Add(FileSystemPath.Parse(home));
                }

                monoFolders.AddRange(
                    homes.SelectMany(a => a.GetChildDirectories("Unity*"))
                    .Select(unityDir => unityDir.Combine(@"Editor/Data/MonoBleedingEdge")));

                return(monoFolders);
            }

            case PlatformUtil.Platform.Windows:
            {
                var monoFolders  = new List <FileSystemPath>();
                var programFiles = FileSystemPath.Parse(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
                // ReSharper disable once UseObjectOrCollectionInitializer
                var homes = new List <FileSystemPath>();
                homes.Add(programFiles.Parent.Combine("Program Files"));
                homes.Add(programFiles.Parent.Combine("Program Files (x86)"));
                monoFolders.AddRange(
                    homes.SelectMany(a => a.GetChildDirectories("Unity*")).Select(unityDir => unityDir.Combine(@"Editor\Data\MonoBleedingEdge"))
                    );

                //"C:\Program Files\Unity\Hub\Editor\2018.1.0b4\Editor\Data\MonoBleedingEdge"
                monoFolders.AddRange(
                    homes.SelectMany(a => a.Combine(@"Unity\Hub\Editor").GetChildDirectories().Select(unityDir => unityDir.Combine(@"Editor\Data\MonoBleedingEdge")))
                    );

                var lnks = FileSystemPath.Parse(@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs")
                           .GetChildDirectories("Unity*").SelectMany(a => a.GetChildFiles("Unity.lnk")).ToArray();
                monoFolders.AddRange(lnks
                                     .Select(a => ShellLinkHelper.ResolveLinkTarget(a).Directory.Combine(@"Data\MonoBleedingEdge"))
                                     .OrderBy(c => new FileInfo(c.FullPath).CreationTime));

                return(monoFolders);
            }
            }
            myLogger.Error("Unknown runtime platfrom");
            return(new List <FileSystemPath>());
        }
예제 #9
0
        void update(object sender, DoWorkEventArgs e)
        {
            init();

            try
            {
#if Public
                ReleaseStream stream = ReleaseStream.Stable40;
#else
                ReleaseStream stream = ReleaseStream.CuttingEdge;
#endif

                bool          hasFramework = File.Exists(@"OpenTK.dll");
                List <string> files        = new List <string>(Directory.GetFiles(Environment.CurrentDirectory));

                bool useCurrentDirectory = File.Exists(@"osu!.cfg") || files.Count == 1;

                if (!hasFramework)
                {
retry_with_default:
                    if (!useCurrentDirectory)
                    {
                        installPath  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
                        label.Click += chooseFolder;

                        int seconds = 10;
                        while (seconds > 0)
                        {
                            setText(string.Format(LocalisationManager.GetString(OsuString.Maintenance_InstallationPath) + '\n' +
                                                  LocalisationManager.GetString(OsuString.Maintenance_InstallationPath2),
                                                  installPath, seconds), true);
                            Thread.Sleep(1000);
                            seconds--;

                            while (installPath == null)
                            {
                                Thread.Sleep(100);
                            }
                        }

                        label.Click -= chooseFolder;
                    }

retry:
                    if (installPath != Environment.CurrentDirectory)
                    {
                        string installExecutable = Path.Combine(installPath, @"osu!.exe");

                        try
                        {
                            if (!Directory.Exists(installPath))
                            {
                                Directory.CreateDirectory(installPath);
                            }

                            try
                            {
                                File.Delete(installExecutable);
                            }
                            catch (IOException)
                            {
                                //ignore IOExceptions for now
                            }

                            byte[] executable = File.ReadAllBytes(OsuMain.FullPath);
                            using (FileStream fs = File.Create(installExecutable))
                                fs.Write(executable, 0, executable.Length);
                        }
                        catch (UnauthorizedAccessException)
                        {
                            if (!OsuMain.IsElevated)
                            {
                                if (OsuMain.Elevate(@"-allowuserwrites " + installPath, true))
                                {
                                    goto retry;
                                }
                                else
                                {
                                    //error occurred while elevating. try again using the default path.
                                    goto retry_with_default;
                                }
                            }
                        }

                        Process.Start(installExecutable);
                        OsuMain.ExitImmediately();
                    }
                }

                try
                {
                    if (hasFramework)
                    {
                        stream = ConfigManager.sReleaseStream.Value;
                    }
                }
                catch (Exception ex)
                {
                    OsuMain.Repair(true, ex);
                }

                setText(string.Empty);

tryAgain:
                setProgress();

                if (hasFramework) //force a complete check.
                {
                    ConfigManager.ResetHashes();
                }

                CommonUpdater.Check(delegate(UpdateStates s) { }, stream);

                while (true)
                {
                    switch (CommonUpdater.State)
                    {
                    case UpdateStates.Checking:
                        setText(CommonUpdater.GetStatusString(), detailedTextImportant);
                        setProgress();
                        Thread.Sleep(20);
                        continue;

                    case UpdateStates.Updating:
                        setText(CommonUpdater.GetStatusString());
                        setProgress(CommonUpdater.Percentage);
                        Thread.Sleep(20);
                        continue;

                    case UpdateStates.Completed:
                    case UpdateStates.NeedsRestart:
                        setText(LocalisationManager.GetString(OsuString.CommonUpdater_Updated));
                        break;

                    case UpdateStates.NoUpdate:
                        setText(LocalisationManager.GetString(OsuString.CommonUpdater_Updated), true);
                        Thread.Sleep(1000);
                        break;

                    case UpdateStates.Error:
                        CommonUpdater.Reset();

                        setProgress();
                        setText(LocalisationManager.GetString(OsuString.Maintenance_ErrorOccurred), true);
                        Thread.Sleep(5000);

                        goto tryAgain;

                    default:
                        break;
                    }

                    break;
                }

                if (!OsuMain.IsWine && !hasFramework)
                {
                    //create desktop/start menu shortcuts only once per install
                    ShellLinkHelper.Create(icon_path_desktop, Path.Combine(Environment.CurrentDirectory, @"osu!.exe"), @"osu!");
                    ShellLinkHelper.Create(icon_path_startmenu, Path.Combine(Environment.CurrentDirectory, @"osu!.exe"), @"osu!");
                }

                instance.Dispose();

                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(@"Error occured (please report this!):\n\n" + ex.ToString());
            }
        }