コード例 #1
0
            void updateLink(ShellLink shortcut, string[] oldAppDirectories, string newAppPath)
            {
                this.Log().Info("Processing shortcut '{0}'", shortcut.Target);

                foreach (var oldAppDirectory in oldAppDirectories)
                {
                    if (!shortcut.Target.StartsWith(oldAppDirectory, StringComparison.OrdinalIgnoreCase) && !shortcut.IconPath.StartsWith(oldAppDirectory, StringComparison.OrdinalIgnoreCase))
                    {
                        this.Log().Info("Does not match '{0}', continuing to next directory", oldAppDirectory);
                        continue;
                    }

                    // replace old app path with new app path and check, if executable still exists
                    var newTarget = Path.Combine(newAppPath, shortcut.Target.Substring(oldAppDirectory.Length + 1));

                    if (File.Exists(newTarget))
                    {
                        shortcut.Target = newTarget;

                        // replace working directory too if appropriate
                        if (shortcut.WorkingDirectory.StartsWith(oldAppDirectory, StringComparison.OrdinalIgnoreCase))
                        {
                            this.Log().Info("Changing new directory to '{0}'", newAppPath);
                            shortcut.WorkingDirectory = Path.Combine(newAppPath,
                                                                     shortcut.WorkingDirectory.Substring(oldAppDirectory.Length + 1));
                        }

                        // replace working directory too if appropriate
                        if (shortcut.IconPath.StartsWith(oldAppDirectory, StringComparison.OrdinalIgnoreCase))
                        {
                            this.Log().Info("Changing new directory to '{0}'", newAppPath);
                            shortcut.IconPath = Path.Combine(newAppPath, shortcut.IconPath.Substring(oldAppDirectory.Length + 1));
                        }

                        shortcut.Save();
                    }
                    else
                    {
                        this.Log().Info("Unpinning {0} from taskbar", shortcut.Target);
                        TaskbarHelper.UnpinFromTaskbar(shortcut.Target);
                    }

                    break;
                }
            }
コード例 #2
0
            void updateLink(ShellLink shortcut, string newAppPath, bool newVersionExists)
            {
                string expectedStart = rootAppDirectory + "\\app-";

                if (!shortcut.WorkingDirectory.StartsWith(expectedStart, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }

                if (!newVersionExists)
                {
                    this.Log().Info("Unpinning {0} from taskbar", shortcut.ShortCutFile);
                    TaskbarHelper.UnpinFromTaskbar(shortcut.Target);
                    return;
                }

                shortcut.Target           = updatePath(shortcut.Target, newAppPath);
                shortcut.WorkingDirectory = updatePath(shortcut.WorkingDirectory, newAppPath);
                shortcut.IconPath         = updatePath(shortcut.IconPath, newAppPath);

                this.Log().Info("Updating shortcut {0}", shortcut.ShortCutFile);
                shortcut.Save();
            }