コード例 #1
0
        public override CustomShortcut GenerateCustomShortcut(string shortcutName)
        {
            var customShortcut =
                new CustomShortcut(shortcutName,
                                   Parameters.ShortcutTarget,
                                   string.Empty,
                                   ShortcutType,
                                   Parameters.WindowType,
                                   Parameters.ShortcutRootPath,
                                   Parameters.IconPath);


            var urlGenerationPath = $"{customShortcut.VbsFolderPath}{shortcutName}.url";

            ShortcutUtils.CreateUrlFile(urlGenerationPath, Parameters.ShortcutTarget);

            customShortcut.TargetPath = urlGenerationPath;

            if (string.IsNullOrEmpty(Parameters.IconPath))
            {
                Build(customShortcut, Parameters.Image);
            }
            else
            {
                Build(customShortcut);
            }

            return(customShortcut);
        }
コード例 #2
0
ファイル: ShortcutsVM.cs プロジェクト: ervingegprifti/MDSHO
        public void DeleteItem(ItemVM itemVMToDelete)
        {
            bool stop = false;

            foreach (WindowItemVM windowItemVM in WindowItemVMs)
            {
                if (windowItemVM.RootItemVMs.Contains(itemVMToDelete))
                {
                    // Delete physical file/s first
                    ShortcutUtils.DeleteShortcuts(itemVMToDelete);
                    // Delete the item
                    windowItemVM.RootItemVMs.Remove(itemVMToDelete);
                    stop = true;
                    break;
                }

                foreach (ItemVM rootItemVM in windowItemVM.RootItemVMs)
                {
                    IEnumerable <ItemVM> itemVMs = rootItemVM.FlattenItemVMs();
                    foreach (ItemVM itemVM in itemVMs)
                    {
                        if (itemVM.IsGroup)
                        {
                            if (itemVM.ItemVMs.Contains(itemVMToDelete))
                            {
                                // Delete physical file/s first
                                ShortcutUtils.DeleteShortcuts(itemVMToDelete);
                                // Delete the item
                                itemVM.ItemVMs.Remove(itemVMToDelete);
                                //
                                stop = true;
                                break;
                            }
                        }

                        if (stop)
                        {
                            break;
                        }
                    }

                    if (stop)
                    {
                        break;
                    }
                }

                if (stop)
                {
                    break;
                }
            }
            SaveData.SaveShortcuts(false);
        }
コード例 #3
0
ファイル: ShortcutsVM.cs プロジェクト: ervingegprifti/MDSHO
 public void DeleteAllItems(WindowItemVM windowItemVM)
 {
     // Delete physical files first
     foreach (ItemVM subItemVMToDelete in windowItemVM.RootItemVMs)
     {
         ShortcutUtils.DeleteShortcuts(subItemVMToDelete);
     }
     // Delete all items
     windowItemVM.RootItemVMs.Clear();
     SaveData.SaveShortcuts(false);
 }
コード例 #4
0
        private void ApplySettings()
        {
            if (_config.PromptForFileName)
            {
                outputFileTextBox.Text = string.Empty;
            }
            else
            {
                outputFileTextBox.Text = NextRecordingPath;
            }

            InitTrayIcon();
            Topmost = _config.AlwaysOnTop;

            Tuple <double, double> windowSize = _config.GetWindowSize(Name);

            Width  = windowSize.Item1;
            Height = windowSize.Item2;

            viewRecordingSettingPanelMenuItem.IsChecked = _config.RecordingSettingsPanelVisible;
            viewRecordingOutputPanelMenuItem.IsChecked  = _config.RecordingOutputPanelVisible;
            viewStatusBarMenuItem.IsChecked             = _config.StatusBarVisible;
            viewStatusBarItemMenuItem.IsChecked         = _config.StatusBarItemVisible;
            viewFreeSpaceMenuItem.IsChecked             = _config.FreeSpaceBarItemVisible;

            if (_config.RunAtStartup)
            {
                try
                {
                    ShortcutUtils.AddStartupShortcut();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format(Messages.GUIErrorAddingStartupShortcut, Environment.NewLine, ex.Message), Messages.GUIErrorCommon, MessageBoxButton.OK, MessageBoxImage.Error);
                    _config.RunAtStartup = false;
                    ConfigHandler.SaveConfig(_config);
                }
            }
            else
            {
                try
                {
                    ShortcutUtils.RemoveStartupShortcut();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format(Messages.GUIErrorRemovingStartupShortcut, Environment.NewLine, ex.Message), Messages.GUIErrorCommon, MessageBoxButton.OK, MessageBoxImage.Error);
                    _config.RunAtStartup = true;
                    ConfigHandler.SaveConfig(_config);
                }
            }
        }
コード例 #5
0
        private StartupFileModel GetModelFromShortcut(string shortcutFileName)
        {
            var shortcutInfo = ShortcutUtils.ResolveShortcut(shortcutFileName);

            return(new StartupFileModel
            {
                FileDirectory = Path.GetDirectoryName(shortcutInfo.Path),
                FileName = Path.GetFileName(shortcutInfo.Path),
                Arguments = shortcutInfo.Arguments,
                Icon = Icon.ExtractAssociatedIcon(shortcutFileName),
                StartupType = StartupType.StartMenu,
            });
        }
コード例 #6
0
        private string GetSteamFolder()
        {
            var rootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                                        "Spectrasonics", "STEAM");

            if (Directory.Exists(rootPath))
            {
                return(rootPath);
            }

            rootPath += ".lnk";

            if (!ShortcutUtils.IsShortcut(rootPath))
            {
                throw new IOException("Could not find the default STEAM folder or shortcut");
            }

            return(ShortcutUtils.ResolveShortcut(rootPath));
        }
コード例 #7
0
        public void BuildCustomShortcut()
        {
            VbsFilePath = VbsFolderPath + ShortcutName + ".vbs";

            File.WriteAllText(VbsFilePath,
                              string.Format(Resources.CustomShortcutVbsTemplate,
                                            ShortcutName.EscapeVba(),
                                            ShortcutItem.ShortcutFileInfo.FullName.EscapeVba(),
                                            TargetPath.QuoteWrap().EscapeVba(),
                                            TargetArguments.EscapeVba(),
                                            ShortcutType,
                                            (int)WindowType
                                            ));

            ShortcutUtils.CreateLnkFile(ShortcutItem.ShortcutFileInfo.FullName, VbsFilePath,
                                        ShortcutName + " shortcut created by TileIconifier",
                                        iconPath: BasicShortcutIcon,
                                        workingDirectory: WorkingFolder
                                        );
        }
コード例 #8
0
        private string GetPresetDirectory(string dataDirectoryName, string productName, bool userPresets)
        {
            dataDirectoryName = GetDataDirectory(dataDirectoryName);

            var shortCutDataDirectoryName = dataDirectoryName + ".lnk";

            string dataDirectory;

            var isShortcut = false;

            try
            {
                isShortcut = ShortcutUtils.IsShortcut(shortCutDataDirectoryName);
            }
            catch (IOException e)
            {
                Logger.Error(
                    $"Error while trying to resolve the shortcut {shortCutDataDirectoryName}: {e.GetType().FullName}: {e.Message}");
                Logger.Debug(e.StackTrace);
            }

            if (isShortcut)
            {
                dataDirectory = ShortcutUtils.ResolveShortcut(shortCutDataDirectoryName);
            }
            else
            {
                dataDirectory = dataDirectoryName;
            }

            if (dataDirectory != null)
            {
                return(Path.Combine(dataDirectory, userPresets ? "UserPresets" : "Presets", productName));
            }

            Logger.Error($"Unable to find the data directory because {dataDirectoryName} is not a directory and no " +
                         $"shortcut {shortCutDataDirectoryName} exists.");
            return(null);
        }
コード例 #9
0
        protected void Build(CustomShortcut customShortcut, Image iconImage = null)
        {
            if (iconImage != null)
            {
                GenerateNewIcon(customShortcut, iconImage);
            }

            customShortcut.VbsFilePath = customShortcut.VbsFolderPath + customShortcut.ShortcutName + ".vbs";

            var targetDir = "";

            try
            {
                targetDir = $@"{new FileInfo(customShortcut.TargetPath).Directory?.FullName}\".EscapeVba();
            }
            catch
            {
                //ignore
            }

            File.WriteAllText(customShortcut.VbsFilePath,
                              string.Format(Resources.CustomShortcutVbsTemplate,
                                            customShortcut.ShortcutName.EscapeVba(),
                                            customShortcut.ShortcutItem.ShortcutFileInfo.FullName.EscapeVba(),
                                            customShortcut.TargetPath.QuoteWrap().EscapeVba(),
                                            customShortcut.TargetArguments.EscapeVba(),
                                            ShortcutType,
                                            (int)customShortcut.WindowType,
                                            targetDir
                                            ), Encoding.Unicode);

            ShortcutUtils.CreateLnkFile(customShortcut.ShortcutItem.ShortcutFileInfo.FullName,
                                        customShortcut.VbsFilePath,
                                        customShortcut.ShortcutName + " shortcut created by TileIconifier",
                                        iconPath: customShortcut.BasicShortcutIcon,
                                        workingDirectory: customShortcut.WorkingFolder
                                        );
        }
コード例 #10
0
        public ItemVM(string guid, bool isGroup, bool isExpanded, string name, string target, string ext)
        {
            try
            {
                Guid       = guid;
                IsGroup    = isGroup;
                IsExpanded = isExpanded;

                if (string.IsNullOrEmpty(name))
                {
                    // This is called from a drop down event. In this case the name is not specified. This item is a shortcut.
                    if (!string.IsNullOrEmpty(target))
                    {
                        if (File.Exists(target) || Directory.Exists(target))
                        {
                            string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(target);
                            string fileNameWithExtension    = System.IO.Path.GetFileName(target);
                            Name = fileNameWithExtension;
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException(nameof(target));
                    }
                }
                else
                {
                    // This is called from an convertion item (items have their names specified) to viewmodel or it is just a group.
                    Name = name;
                }

                Target = target;
                Ext    = ext;
                // Set the default values
                ItemVMs               = new ObservableCollection <ItemVM>();
                NewGroupCommand       = new RelayCommand(NewGroup, CanExecuteNewGroup);
                DeleteCommand         = new RelayCommand(Delete);
                CutCommand            = new RelayCommand(Cut);
                CopyCommand           = new RelayCommand(Copy);
                PasteCommand          = new RelayCommand(Paste, CanExecutePaste);
                EditNameCommand       = new RelayCommand(EditName);
                SortAscendingCommand  = new RelayCommand(SortAscending, CanSort);
                SortDescendingCommand = new RelayCommand(SortDescending, CanSort);

                // Get the icon for the shortcut
                if (IsGroup)
                {
                    ImageIconBitmapSource = null;
                }
                else
                {
                    // IMPORTANT INFO
                    // In case of control panel items we first create the link
                    // then COPY the link in Shortcuts folder and execute from there
                    // In case of normal cases we CREATE the link in Shortcuts folder and execute from there
                    // If the target does not exists then there is nothing to create in the Shortcuts folder
                    // (we are talking not in the case of a drag androp event, but in just opening the application and the shortcut in Shortcuts folder has been deleted)

                    // Write the shortcut (not groups) to physical user local folder C:\Users\USER_NAME\AppData\Local
                    // LocalApplicationData (applies to current user - local only). No need for Administrator access to write on that folder.
                    // File.Exists & Directory.Exists are time consuming in case of \\server... For that reason we just let it fail silently
                    try
                    {
                        if (ext.Equals(Constants.EXT_LNK, StringComparison.InvariantCultureIgnoreCase))
                        {
                            ShortcutUtils.GreateShortcutLnk(guid, target);
                        }
                        else if (ext.Equals(Constants.EXT_URL, StringComparison.InvariantCultureIgnoreCase))
                        {
                            ShortcutUtils.GreateShortcutUrl(guid, target);
                        }
                    }
                    catch (Exception)
                    {
                        // Let it fail silently
                    }

                    string shortcutsDirectoryPath = Helper.GetShortcutsPath();
                    string shortcutFilePath       = Path.Combine(shortcutsDirectoryPath, Guid + Ext);
                    if (File.Exists(shortcutFilePath))
                    {
                        ImageIconBitmapSource = ShortcutUtils.GetShortcutIconBitmapSource(shortcutFilePath);
                    }
                }
            }
            catch (Exception ex)
            {
                Error.ShowDialog(ex);
            }
        }