예제 #1
0
        void InstallShortcuts(string[] destFolders, string backupFolder, List <FileFolder> rollbackList)
        {
            bool installCommonDesktopShortcut        = true;
            bool installCommonStartMenuShortcut      = true;
            bool installCurrentUserDesktopShortcut   = true;
            bool installCurrentUserStartMenuShortcut = true;

            // see if at least one previous shortcut on the desktop exists
            foreach (string shortcut in UpdtDetails.PreviousCommonDesktopShortcuts)
            {
                if (File.Exists(Path.Combine(destFolders[7], shortcut.Substring(11))))
                {
                    installCommonDesktopShortcut = true;
                    break;
                }

                installCommonDesktopShortcut = false;
            }

            //see if at least one previous shortcut in the start menu folder exists
            foreach (string shortcut in UpdtDetails.PreviousCommonSMenuShortcuts)
            {
                if (File.Exists(Path.Combine(destFolders[8], shortcut.Substring(13))))
                {
                    installCommonStartMenuShortcut = true;
                    break;
                }

                installCommonStartMenuShortcut = false;
            }

            // see if at least one previous shortcut on the desktop exists
            foreach (string shortcut in UpdtDetails.PreviousCUserDesktopShortcuts)
            {
                if (File.Exists(Path.Combine(destFolders[11], shortcut.Substring(8))))
                {
                    installCurrentUserDesktopShortcut = true;
                    break;
                }

                installCurrentUserDesktopShortcut = false;
            }

            //see if at least one previous shortcut in the start menu folder exists
            foreach (string shortcut in UpdtDetails.PreviousCUserSMenuShortcuts)
            {
                if (File.Exists(Path.Combine(destFolders[12], shortcut.Substring(9))))
                {
                    installCurrentUserStartMenuShortcut = true;
                    break;
                }

                installCurrentUserStartMenuShortcut = false;
            }

            // create the shortcuts
            for (int i = 0; i < UpdtDetails.ShortcutInfos.Count; i++)
            {
                //get the first 4 letters of the shortcut's path
                string tempFile = UpdtDetails.ShortcutInfos[i].RelativeOuputPath.Substring(0, 4);

                //if we can't install to that folder then continue to the next shortcut
                if (tempFile == "comd" && !installCommonDesktopShortcut ||
                    tempFile == "coms" && !installCommonStartMenuShortcut ||
                    tempFile == "curd" && !installCurrentUserDesktopShortcut ||
                    tempFile == "curs" && !installCurrentUserStartMenuShortcut)
                {
                    continue;
                }

                tempFile = FixUpdateDetailsPaths(UpdtDetails.ShortcutInfos[i].RelativeOuputPath);

                string tempPath;

                // see if the shortcut already exists
                if (File.Exists(tempFile))
                {
                    tempPath = Path.Combine(backupFolder, UpdtDetails.ShortcutInfos[i].RelativeOuputPath.Substring(0, UpdtDetails.ShortcutInfos[i].RelativeOuputPath.LastIndexOf('\\')));

                    // check if the backup folder exists (create it if not)
                    if (!Directory.Exists(tempPath))
                    {
                        Directory.CreateDirectory(tempPath);
                    }

                    // backup the existing shortcut
                    File.Copy(tempFile, Path.Combine(tempPath, Path.GetFileName(tempFile)), true);

                    // delete the shortcut
                    File.Delete(tempFile);
                }
                else
                {
                    //add file to "rollback" list
                    rollbackList.Add(new FileFolder(tempFile));
                }

                tempPath = Path.GetDirectoryName(tempFile);

                //if the folder doesn't exist
                if (!Directory.Exists(tempPath))
                {
                    //create the directory
                    Directory.CreateDirectory(tempPath);

                    //add to the rollback list
                    rollbackList.Add(new FileFolder(tempPath, true));
                }

                ShellShortcut shellShortcut = new ShellShortcut(tempFile)
                {
                    Path             = ParseText(UpdtDetails.ShortcutInfos[i].Path),
                    WorkingDirectory =
                        ParseText(UpdtDetails.ShortcutInfos[i].WorkingDirectory),
                    WindowStyle = UpdtDetails.ShortcutInfos[i].WindowStyle,
                    Description = UpdtDetails.ShortcutInfos[i].Description
                };
                //shellShortcut.IconPath
                //shellShortcut.IconIndex = 0;
                shellShortcut.Save();
            }
        }
예제 #2
0
        void InstallShortcuts(string[] destFolders, string backupFolder, List<FileFolder> rollbackList)
        {
            bool installCommonDesktopShortcut = true;
            bool installCommonStartMenuShortcut = true;
            bool installCurrentUserDesktopShortcut = true;
            bool installCurrentUserStartMenuShortcut = true;

            // see if at least one previous shortcut on the desktop exists
            foreach (string shortcut in UpdtDetails.PreviousCommonDesktopShortcuts)
            {
                if (File.Exists(Path.Combine(destFolders[7], shortcut.Substring(11))))
                {
                    installCommonDesktopShortcut = true;
                    break;
                }

                installCommonDesktopShortcut = false;
            }

            //see if at least one previous shortcut in the start menu folder exists
            foreach (string shortcut in UpdtDetails.PreviousCommonSMenuShortcuts)
            {
                if (File.Exists(Path.Combine(destFolders[8], shortcut.Substring(13))))
                {
                    installCommonStartMenuShortcut = true;
                    break;
                }

                installCommonStartMenuShortcut = false;
            }

            // see if at least one previous shortcut on the desktop exists
            foreach (string shortcut in UpdtDetails.PreviousCUserDesktopShortcuts)
            {
                if (File.Exists(Path.Combine(destFolders[11], shortcut.Substring(8))))
                {
                    installCurrentUserDesktopShortcut = true;
                    break;
                }

                installCurrentUserDesktopShortcut = false;
            }

            //see if at least one previous shortcut in the start menu folder exists
            foreach (string shortcut in UpdtDetails.PreviousCUserSMenuShortcuts)
            {
                if (File.Exists(Path.Combine(destFolders[12], shortcut.Substring(9))))
                {
                    installCurrentUserStartMenuShortcut = true;
                    break;
                }

                installCurrentUserStartMenuShortcut = false;
            }

            // create the shortcuts
            for (int i = 0; i < UpdtDetails.ShortcutInfos.Count; i++)
            {
                //get the first 4 letters of the shortcut's path
                string tempFile = UpdtDetails.ShortcutInfos[i].RelativeOuputPath.Substring(0, 4);

                //if we can't install to that folder then continue to the next shortcut
                if (tempFile == "comd" && !installCommonDesktopShortcut
                    || tempFile == "coms" && !installCommonStartMenuShortcut
                    || tempFile == "curd" && !installCurrentUserDesktopShortcut
                    || tempFile == "curs" && !installCurrentUserStartMenuShortcut)
                {
                    continue;
                }

                tempFile = FixUpdateDetailsPaths(UpdtDetails.ShortcutInfos[i].RelativeOuputPath);

                string tempPath;

                // see if the shortcut already exists
                if (File.Exists(tempFile))
                {
                    tempPath = Path.Combine(backupFolder, UpdtDetails.ShortcutInfos[i].RelativeOuputPath.Substring(0, UpdtDetails.ShortcutInfos[i].RelativeOuputPath.LastIndexOf('\\')));

                    // check if the backup folder exists (create it if not)
                    if (!Directory.Exists(tempPath))
                        Directory.CreateDirectory(tempPath);

                    // backup the existing shortcut
                    File.Copy(tempFile, Path.Combine(tempPath, Path.GetFileName(tempFile)), true);

                    // delete the shortcut
                    File.Delete(tempFile);
                }
                else
                    //add file to "rollback" list
                    rollbackList.Add(new FileFolder(tempFile));

                tempPath = Path.GetDirectoryName(tempFile);

                //if the folder doesn't exist
                if (!Directory.Exists(tempPath))
                {
                    //create the directory
                    Directory.CreateDirectory(tempPath);

                    //add to the rollback list
                    rollbackList.Add(new FileFolder(tempPath, true));
                }

                ShellShortcut shellShortcut = new ShellShortcut(tempFile)
                                                  {
                                                      Path = ParseText(UpdtDetails.ShortcutInfos[i].Path),
                                                      WorkingDirectory =
                                                          ParseText(UpdtDetails.ShortcutInfos[i].WorkingDirectory),
                                                      WindowStyle = UpdtDetails.ShortcutInfos[i].WindowStyle,
                                                      Description = UpdtDetails.ShortcutInfos[i].Description
                                                  };
                //shellShortcut.IconPath
                //shellShortcut.IconIndex = 0;
                shellShortcut.Save();
            }
        }