Ejemplo n.º 1
0
        private void btnDeleteCustomShortcut_Click(object sender, EventArgs e)
        {
            if (
                MessageBox.Show(
                    string.Format(Strings.ConfirmDeleteCustomShortcut,
                                  Path.GetFileNameWithoutExtension(CurrentShortcutItem.ShortcutFileInfo.Name).QuoteWrap()),
                    Strings.AreYouSure,
                    MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            try
            {
                var customShortcut = CustomShortcut.Load(CurrentShortcutItem.TargetFilePath);
                customShortcut.Delete();
            }
            catch (Exception ex)
            {
                FrmException.ShowExceptionHandler(ex);
                MessageBox.Show(Strings.UnableToClearShortcuts);
            }

            StartFullUpdate();
        }
Ejemplo n.º 2
0
            public void SelectingAnyDateRangeDoesNotMakeTheAppCrash(DateTimeOffset a, DateTimeOffset b, DateTimeOffset c)
            {
                var dates = new[] { a, b, c };

                Array.Sort(dates);
                var start = dates[0];
                var now   = dates[1];
                var end   = dates[2];

                TimeService.CurrentDateTime.Returns(now);
                var selectedRange     = ReportsDateRangeParameter.WithDates(start, end).WithSource(ReportsSource.Calendar);
                var customShortcut    = new CustomShortcut(selectedRange, TimeService);
                var errorObserver     = TestScheduler.CreateObserver <Exception>();
                var executionObserver = TestScheduler.CreateObserver <bool>();

                // in this property test it is not possible to use the default ViewModel,
                // because we have to reset it in each iteration of the test
                var viewModel = CreateViewModel();

                viewModel.Prepare();
                viewModel.Initialize().Wait();
                viewModel.SelectShortcut.Errors.Subscribe(errorObserver);
                viewModel.SelectShortcut.Executing.Subscribe(executionObserver);

                viewModel.SelectShortcut.Inputs.OnNext(customShortcut);
                TestScheduler.Start();

                errorObserver.Messages.Should().BeEmpty();
                executionObserver.Messages.Should().NotBeEmpty();
            }
 public CustomShortcutListViewItem(CustomShortcut customShortcut)
 {
     CustomShortcut = customShortcut;
     Text           = CustomShortcut.ShortcutName;
     SubItems.Add(CustomShortcut.ShortcutType.ToString());
     SubItems.Add(CustomShortcut.ShortcutItem.ShortcutUser.ToString());
 }
        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
                );
        }
        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);
        }
Ejemplo n.º 6
0
        private void IconSet(object sender)
        {
            IconSelectorResult selectedImage;

            try
            {
                var imagePath = GetSenderPictureBoxToMetaData(sender).ShortcutItemImage.Path;
                //if we haven't got a valid file from previously, try and get the default icon
                if (string.IsNullOrEmpty(imagePath) || !File.Exists(imagePath))
                {
                    //if it's a custom shortcut, try and get the target path from the VBS file
                    if (CurrentShortcutItem.IsTileIconifierCustomShortcut)
                    {
                        try
                        {
                            var customShortcutExecutionTarget = CustomShortcut.Load(CurrentShortcutItem.TargetFilePath);
                            imagePath = customShortcutExecutionTarget.TargetPath.UnQuoteWrap();
                        }
                        catch (InvalidCustomShortcutException)
                        {
                            //corrupted custom shortcut?
                            imagePath = CurrentShortcutItem.TargetFilePath;
                        }
                    }
                    else
                    {
                        //otherwise we just use the target file path from the shortcut
                        imagePath = CurrentShortcutItem.TargetFilePath;
                    }
                }
                selectedImage = FrmIconSelector.GetImage(this, imagePath);
            }
            catch (UserCancellationException)
            {
                return;
            }

            var pictureBoxMetaDataToUse = chkUseSameImg.Checked
                ? _pannablePictureBoxMetaDatas
                : new List <PannablePictureBoxMetaData> {
                GetSenderPictureBoxToMetaData(sender)
            };

            foreach (var pictureBoxMetaData in pictureBoxMetaDataToUse)
            {
                pictureBoxMetaData.ShortcutItemImage.Path = selectedImage.ImagePath;
                pictureBoxMetaData.ShortcutItemImage.SetImage(selectedImage.ImageBytes, pictureBoxMetaData.Size);
                UpdatePictureBoxImage(pictureBoxMetaData.PannablePictureBox, pictureBoxMetaData.ShortcutItemImage);
                pictureBoxMetaData.PannablePictureBox.ResetImage();
            }

            RunUpdate();
        }
Ejemplo n.º 7
0
        private void GenerateFullShortcut(
            string targetPath,
            string targetArguments,
            CustomShortcutType shortcutType,
            string basicShortcutIcon = null,
            string workingFolder     = null,
            WindowType windowType    = WindowType.ActiveAndDisplayed
            )
        {
            var shortcutName = txtShortcutName.Text.CleanInvalidFilenameChars();

            byte[] imageToUse;

            try
            {
                ValidateFields(shortcutName, targetPath, out imageToUse);
            }
            catch (ValidationFailureException)
            {
                return;
            }

            //build our new custom shortcut
            var customShortcut = new CustomShortcut(shortcutName, targetPath, targetArguments, shortcutType, windowType,
                                                    radShortcutLocation.PathSelection(), basicShortcutIcon, workingFolder);

            //If we didn't specify a shortcut icon path, make one
            if (string.IsNullOrWhiteSpace(basicShortcutIcon))
            {
                customShortcut.BuildCustomShortcut(pctCurrentIcon.Image);
            }
            else
            {
                customShortcut.BuildCustomShortcut();
            }


            //Iconify a TileIconifier shortcut for this with default settings
            var newShortcutItem = customShortcut.ShortcutItem;

            newShortcutItem.Properties.CurrentState.MediumImage.SetImage(imageToUse,
                                                                         ShortcutConstantsAndEnums.MediumShortcutDisplaySize);
            newShortcutItem.Properties.CurrentState.SmallImage.SetImage(imageToUse,
                                                                        ShortcutConstantsAndEnums.SmallShortcutDisplaySize);
            var iconify = new TileIcon(newShortcutItem);

            iconify.RunIconify();

            //confirm to the user the shortcut has been created
            MessageBox.Show(
                $"A shortcut for {shortcutName.QuoteWrap()} has been created in your start menu under TileIconify. The item will need to be pinned manually.",
                @"Shortcut created!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Ejemplo n.º 8
0
        private static void BuildIconifiedTile(byte[] imageToUse, CustomShortcut customShortcut)
        {
            //Iconify a TileIconifier shortcut for this with default settings
            var newShortcutItem = customShortcut.ShortcutItem;

            newShortcutItem.Properties.CurrentState.MediumImage.SetImage(imageToUse,
                                                                         ShortcutConstantsAndEnums.MediumShortcutDisplaySize);
            newShortcutItem.Properties.CurrentState.SmallImage.SetImage(imageToUse,
                                                                        ShortcutConstantsAndEnums.SmallShortcutDisplaySize);
            var iconify = new TileIcon(newShortcutItem);

            iconify.RunIconify();
        }
Ejemplo n.º 9
0
        private static IEnumerable <CustomShortcut> LoadCustomShortcuts()
        {
            if (!Directory.Exists(CustomShortcutGetters.CustomShortcutVbsPath))
            {
                return(new List <CustomShortcut>());
            }

            //get all VBS files built by TileIconifier
            return(new DirectoryInfo(CustomShortcutGetters.CustomShortcutVbsPath)
                   .GetFiles("*.vbs", SearchOption.AllDirectories)
                   .Select(vbsFile => CustomShortcut.Load(vbsFile.FullName))
                   .Where(customShortcut => customShortcut.ShortcutItem.ShortcutUser != ShortcutUser.Unknown)
                   .ToList());
        }
 private void GenerateNewIcon(CustomShortcut customShortcut, Image basicIconImage)
 {
     customShortcut.BasicShortcutIcon = customShortcut.VbsFolderPath + customShortcut.ShortcutName + ".ico";
     try
     {
         using (var iconWriter = new FileStream(customShortcut.BasicShortcutIcon, FileMode.Create))
         {
             ImageUtils.ConvertToIcon(basicIconImage, iconWriter);
         }
     }
     catch
     {
         customShortcut.BasicShortcutIcon = null;
     }
 }
        public virtual CustomShortcut GenerateCustomShortcut(string shortcutName)
        {
            var customShortcut =
                new CustomShortcut(shortcutName,
                    Parameters.ShortcutTarget,
                    Parameters.ShortcutArguments,
                    ShortcutType,
                    Parameters.WindowType,
                    Parameters.ShortcutRootPath,
                    Parameters.IconPath);

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

            return customShortcut;
        }
        public virtual CustomShortcut GenerateCustomShortcut(string shortcutName)
        {
            var customShortcut =
                new CustomShortcut(shortcutName,
                                   Parameters.ShortcutTarget,
                                   Parameters.ShortcutArguments,
                                   ShortcutType,
                                   Parameters.WindowType,
                                   Parameters.ShortcutRootPath,
                                   Parameters.IconPath);

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

            return(customShortcut);
        }
        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
                                        );
        }
            public void SelectingAnyDateRangeDoesNotMakeTheAppCrash(DateTimeOffset a, DateTimeOffset b, DateTimeOffset c)
            {
                var dates = new[] { a, b, c };

                Array.Sort(dates);
                var start = dates[0];
                var now   = dates[1];
                var end   = dates[2];

                TimeService.CurrentDateTime.Returns(now);
                var selectedRange  = ReportsDateRangeParameter.WithDates(start, end).WithSource(ReportsSource.Calendar);
                var customShortcut = new CustomShortcut(selectedRange, TimeService);

                // in this property test it is not possible to use the default ViewModel,
                // because we have to reset it in each iteration of the test
                var viewModel = CreateViewModel();

                viewModel.Prepare();
                viewModel.Initialize().Wait();

                Action usingShortcut = () => viewModel.QuickSelectCommand.Execute(customShortcut);

                usingShortcut.Should().NotThrow();
            }
 private void GenerateNewIcon(CustomShortcut customShortcut, Image basicIconImage)
 {
     customShortcut.BasicShortcutIcon = customShortcut.VbsFolderPath + customShortcut.ShortcutName + ".ico";
     try
     {
         using (var iconWriter = new FileStream(customShortcut.BasicShortcutIcon, FileMode.Create))
         {
             ImageUtils.ConvertToIcon(basicIconImage, iconWriter);
         }
     }
     catch
     {
         customShortcut.BasicShortcutIcon = null;
     }
 }