Esempio n. 1
0
            /// <summary>
            /// Create or overwrite a current file association for this FileAssociator's set extension.
            /// </summary>
            /// <param name="progID">The basic application name that uses this file extension.</param>
            /// <param name="description">The desription of this file extension and/or program that uses it.</param>
            /// <param name="defaultIcon">The icon to show on the program and it's files.</param>
            /// <param name="execApp">The application that will be run when the file extension is clicked.</param>
            /// <param name="openWith">The programs that appear in the OpenWith list.</param>
            /// <exception cref="Exception">Thrown when an error occurs that will prevent it from working correctly.</exception>
            public void Create(string progID, string description, ProgramIcon defaultIcon, ExecApplication execApp, OpenWithList openWith)
            {
                if (progID != null)
                {
                    if (defaultIcon.IsValid && execApp.IsValid)
                    {
                        Registry.ClassesRoot.CreateSubKey(Extension).SetValue("", progID);
                        RegistryKey key = Registry.ClassesRoot.CreateSubKey(progID,
                                                                            RegistryKeyPermissionCheck.ReadWriteSubTree);

                        if (description != null)
                        {
                            key.SetValue("", description, RegistryValueKind.String);
                        }

                        if (defaultIcon != null && defaultIcon.IsValid)
                        {
                            key.CreateSubKey("DefaultIcon").SetValue("", defaultIcon.IconPath, RegistryValueKind.String);
                        }
                        else
                        {
                            throw new Exception("The default icon you entered is either null or doesn't exist...");
                        }

                        if (execApp != null && execApp.IsValid)
                        {
                            key.CreateSubKey(@"Shell\Open\Command").SetValue("", execApp.Path + " %1", RegistryValueKind.String);
                        }
                        else
                        {
                            throw new Exception("The executable application you entered is either null or not an .exe format...");
                        }

                        if (openWith != null)
                        {
                            key = key.CreateSubKey("OpenWithList", RegistryKeyPermissionCheck.ReadWriteSubTree);
                            foreach (string file in openWith.List)
                            {
                                key.CreateSubKey(file);
                            }
                        }

                        key.Flush();
                        key.Close();
                    }
                    else
                    {
                        throw new Exception("Either the icon or executable application object is invalid...");
                    }
                }
                else
                {
                    throw new Exception("The program ID you entered is null...");
                }
            }
Esempio n. 2
0
        private void SetIcon()
        {
            var processId = 0;

            GetWindowThreadProcessId(Handler, out processId);

            var p = Process.GetProcessById(processId);

            var ic = Icon.ExtractAssociatedIcon(p.MainModule.FileName);

            ProgramIcon = Imaging.CreateBitmapSourceFromHBitmap((ic.ToBitmap()).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            ProgramIcon.Freeze();
            ic.Dispose();
        }
Esempio n. 3
0
    public static void Main()
    {
        // Initializes a new AF_FileAssociator to associate the .ABC file extension.
        AF_FileAssociator assoc = new AF_FileAssociator(".abc");

        // Creates a new file association for the .ABC file extension. Data is overwritten if it already exists.
        assoc.Create("My_App",
                     "My application's file association",
                     new ProgramIcon(@"C:\Program Files\My_App\icon.ico"),
                     new ExecApplication(@"C:\Program Files\My_App\myapp.exe"),
                     new OpenWithList(new string[] { "My_App" }));

        // Gets each piece of association info individually, all as strings.
        string id          = assoc.ID;
        string description = assoc.Description;
        string icon        = assoc.DefaultIcon.IconPath;
        string execApp     = assoc.Executable.Path;

        string[] openWithList = assoc.OpenWith.List;

        // Sets each peice of association info individually.
        ProgramIcon     newDefIcon  = new ProgramIcon(@"C:\Program Files\My_App\icon2.ico");
        ExecApplication newExecApp  = new ExecApplication(@"C:\Program Files\My_App\myapp2.exe");
        OpenWithList    newOpenWith = new OpenWithList(new string[] { "myapp2.exe" });

        assoc.ID          = "My_App_2";
        assoc.Description = "My application's file association #2";
        assoc.DefaultIcon = newDefIcon;
        assoc.Executable  = newExecApp;
        assoc.OpenWith    = newOpenWith;

        // Gets the extension of the associator that was set when initializing it.
        string extension = assoc.Extension;

        // Deletes any keys that were associated with the .ABC file extension.
        assoc.Delete();
    }
Esempio n. 4
0
        internal void UpdatePrograms() // TODO check how OS/Desktop does this in PCBS and adapt accordingly or call directly if at all possible
        {
            foreach (ProgramIcon programIcon in os.transform.GetComponentsInChildren <ProgramIcon>())
            {
                if (programIcon.transform.parent == os.transform)
                {
                    programIcon.transform.parent = null;
                    UnityEngine.Object.Destroy(programIcon);
                }
            }
            string[]           programsInstalled = ReflectionUtils.Get <string[]>("m_programsInstalled", os);
            List <ProgramIcon> programIcons      = ReflectionUtils.Get <List <ProgramIcon> >("m_icons", os);

            programIcons.Clear();
            float num     = 100f;
            Rect  rect    = (os.transform as RectTransform).rect;
            var   spacing = 100f;
            float num2    = rect.height - spacing;

            foreach (OSProgramDesc program in PartsDatabase.GetAllPrograms())
            {
                if (Array.Find <string>(programsInstalled, (string p) => p == program.m_id) != null)
                {
                    ProgramIcon programIcon2 = UnityEngine.Object.Instantiate <ProgramIcon>(os.m_programIconPrefab);
                    programIcon2.Init(program, false, null);
                    programIcon2.transform.SetParent(os.transform, false);
                    programIcon2.transform.localPosition = new Vector3(num, num2);
                    programIcons.Add(programIcon2);
                    num2 -= spacing;
                    if (num2 - spacing < 0f)
                    {
                        num += spacing;
                        num2 = rect.height - spacing;
                    }
                }
            }
        }
 public static void Dispose()
 {
     ((IDisposable)Logger)?.Dispose();
     FormIcon?.Dispose();
     ProgramIcon?.Dispose();
 }