Exemplo n.º 1
0
        private void DataReload()
        {
            _assoc = FileAssociations.GetAssociations();

            //////////////////////////////////
            // Types List

            __typesList.BeginUpdate();
            __typesList.Items.Clear();

            foreach (FileType type in _assoc.AllTypes)
            {
                ListViewItem item = CreateItemForType(type);

                __typesList.Items.Add(item);
            }

            __typesList.EndUpdate();

            //////////////////////////////////
            // Extensions List

            __extsList.BeginUpdate();
            __extsList.Items.Clear();

            foreach (FileExtension ext in _assoc.AllExtensions)
            {
                ListViewItem item = CreateItemForExt(ext);

                __extsList.Items.Add(item);
            }

            __extsList.EndUpdate();
        }
Exemplo n.º 2
0
        public override void Execute()
        {
            FileAssociations assoc = FileAssociations.GetAssociations();

            Backup(assoc, Package.ExecutionInfo.BackupGroup);
            List <String> extsToDeleteOnUninstall      = new List <String>();
            List <String> progidsToDeleteOnUninstall   = new List <String>();
            List <String> iconFilesToDeleteOnUninstall = new List <String>();

            DirectoryInfo iconsDir = new DirectoryInfo(PackageUtility.ResolvePath(@"%windir%\Resources\Icons"));

            if (!iconsDir.Exists)
            {
                iconsDir.Create();
            }

            foreach (FileTypeSetting setting in _types)
            {
                if (!setting.TypeExt.StartsWith(".", StringComparison.Ordinal))
                {
                    Package.Log.Add(LogSeverity.Warning, "Invalid extension, must start with '.': " + setting.TypeExt);
                    continue;
                }

                FileType      targetType      = null;
                FileExtension targetExtension = null;

                // get the type for this extension
                foreach (FileExtension ext in assoc.AllExtensions)
                {
                    if (String.Equals(ext.Extension, setting.TypeExt, StringComparison.OrdinalIgnoreCase))
                    {
                        targetExtension = ext;
                        break;
                    }
                }

                if (targetExtension == null)
                {
                    // create type and extension

                    Package.Log.Add(LogSeverity.Info, "Extension undefined: \"" + setting.TypeExt + "\". Creating FileType and FileExtension");

                    targetType = assoc.CreateFileType(assoc.GetUnusedProgIdForExtension(setting.TypeExt));
                    targetType.FriendlyName = setting.FriendlyName;

                    targetExtension          = assoc.CreateFileExtension(setting.TypeExt);
                    targetExtension.FileType = targetType;

                    extsToDeleteOnUninstall.Add(targetExtension.Extension);
                    progidsToDeleteOnUninstall.Add(targetType.ProgId);
                }
                else
                {
                    targetType = targetExtension.FileType;

                    if (targetType == null)
                    {
                        // create the type

                        Package.Log.Add(LogSeverity.Info, "Extension defined : \"" + setting.TypeExt + "\", but FileType undefined. Creating FileType");

                        String newProgid = assoc.GetUnusedProgIdForExtension(setting.TypeExt);
                        targetType = assoc.CreateFileType(newProgid);
                        targetType.FriendlyName = setting.FriendlyName;

                        targetExtension.FileType = targetType;

                        progidsToDeleteOnUninstall.Add(newProgid);
                    }
                }

                ////////////////////////
                // copy the icon files to %windir%\Resources\Icons

                FileInfo iconFile = Package.RootDirectory.GetFile(setting.Icon);

                String destinationFileName = P.Combine(iconsDir.FullName, iconFile.Name);

                iconFile.CopyTo(destinationFileName, true);
                iconFilesToDeleteOnUninstall.Add(destinationFileName);

                targetType.DefaultIcon = destinationFileName;
                targetType.IsDirty     = true;
            }

            assoc.CommitChanges();

            BackupPart2(Package.ExecutionInfo.BackupGroup, progidsToDeleteOnUninstall, extsToDeleteOnUninstall, iconFilesToDeleteOnUninstall);
        }