Example #1
0
        private bool DoFileOk(IntPtr lpOFN)
        {
            System.Windows.Forms.NativeMethods.OPENFILENAME_I openfilename_i = (System.Windows.Forms.NativeMethods.OPENFILENAME_I)System.Windows.Forms.UnsafeNativeMethods.PtrToStructure(lpOFN, typeof(System.Windows.Forms.NativeMethods.OPENFILENAME_I));
            int options     = this.options;
            int filterIndex = this.filterIndex;

            string[] fileNames = this.fileNames;
            bool     securityCheckFileNames = this.securityCheckFileNames;
            bool     flag2 = false;

            try
            {
                this.options     = (this.options & -2) | (openfilename_i.Flags & 1);
                this.filterIndex = openfilename_i.nFilterIndex;
                this.charBuffer.PutCoTaskMem(openfilename_i.lpstrFile);
                this.securityCheckFileNames = true;
                Thread.MemoryBarrier();
                if ((this.options & 0x200) == 0)
                {
                    this.fileNames = new string[] { this.charBuffer.GetString() };
                }
                else
                {
                    this.fileNames = this.GetMultiselectFiles(this.charBuffer);
                }
                if (!this.ProcessFileNames())
                {
                    return(flag2);
                }
                CancelEventArgs e = new CancelEventArgs();
                if (NativeWindow.WndProcShouldBeDebuggable)
                {
                    this.OnFileOk(e);
                    return(!e.Cancel);
                }
                try
                {
                    this.OnFileOk(e);
                    flag2 = !e.Cancel;
                }
                catch (Exception exception)
                {
                    Application.OnThreadException(exception);
                }
            }
            finally
            {
                if (!flag2)
                {
                    this.securityCheckFileNames = securityCheckFileNames;
                    Thread.MemoryBarrier();
                    this.fileNames   = fileNames;
                    this.options     = options;
                    this.filterIndex = filterIndex;
                }
            }
            return(flag2);
        }
Example #2
0
        private bool RunDialogOld(IntPtr hWndOwner)
        {
            bool flag;

            System.Windows.Forms.NativeMethods.WndProc        proc = new System.Windows.Forms.NativeMethods.WndProc(this.HookProc);
            System.Windows.Forms.NativeMethods.OPENFILENAME_I ofn  = new System.Windows.Forms.NativeMethods.OPENFILENAME_I();
            try
            {
                this.charBuffer = System.Windows.Forms.UnsafeNativeMethods.CharBuffer.CreateBuffer(0x2000);
                if (this.fileNames != null)
                {
                    this.charBuffer.PutString(this.fileNames[0]);
                }
                ofn.lStructSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.OPENFILENAME_I));
                if ((Environment.OSVersion.Platform != PlatformID.Win32NT) || (Environment.OSVersion.Version.Major < 5))
                {
                    ofn.lStructSize = 0x4c;
                }
                ofn.hwndOwner       = hWndOwner;
                ofn.hInstance       = this.Instance;
                ofn.lpstrFilter     = MakeFilterString(this.filter, this.DereferenceLinks);
                ofn.nFilterIndex    = this.filterIndex;
                ofn.lpstrFile       = this.charBuffer.AllocCoTaskMem();
                ofn.nMaxFile        = 0x2000;
                ofn.lpstrInitialDir = this.initialDir;
                ofn.lpstrTitle      = this.title;
                ofn.Flags           = this.Options | 0x880020;
                ofn.lpfnHook        = proc;
                ofn.FlagsEx         = 0x1000000;
                if ((this.defaultExt != null) && this.AddExtension)
                {
                    ofn.lpstrDefExt = this.defaultExt;
                }
                flag = this.RunFileDialog(ofn);
            }
            finally
            {
                this.charBuffer = null;
                if (ofn.lpstrFile != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ofn.lpstrFile);
                }
            }
            return(flag);
        }
 private bool RunDialogOld(IntPtr hWndOwner)
 {
     bool flag;
     System.Windows.Forms.NativeMethods.WndProc proc = new System.Windows.Forms.NativeMethods.WndProc(this.HookProc);
     System.Windows.Forms.NativeMethods.OPENFILENAME_I ofn = new System.Windows.Forms.NativeMethods.OPENFILENAME_I();
     try
     {
         this.charBuffer = System.Windows.Forms.UnsafeNativeMethods.CharBuffer.CreateBuffer(0x2000);
         if (this.fileNames != null)
         {
             this.charBuffer.PutString(this.fileNames[0]);
         }
         ofn.lStructSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.OPENFILENAME_I));
         if ((Environment.OSVersion.Platform != PlatformID.Win32NT) || (Environment.OSVersion.Version.Major < 5))
         {
             ofn.lStructSize = 0x4c;
         }
         ofn.hwndOwner = hWndOwner;
         ofn.hInstance = this.Instance;
         ofn.lpstrFilter = MakeFilterString(this.filter, this.DereferenceLinks);
         ofn.nFilterIndex = this.filterIndex;
         ofn.lpstrFile = this.charBuffer.AllocCoTaskMem();
         ofn.nMaxFile = 0x2000;
         ofn.lpstrInitialDir = this.initialDir;
         ofn.lpstrTitle = this.title;
         ofn.Flags = this.Options | 0x880020;
         ofn.lpfnHook = proc;
         ofn.FlagsEx = 0x1000000;
         if ((this.defaultExt != null) && this.AddExtension)
         {
             ofn.lpstrDefExt = this.defaultExt;
         }
         flag = this.RunFileDialog(ofn);
     }
     finally
     {
         this.charBuffer = null;
         if (ofn.lpstrFile != IntPtr.Zero)
         {
             Marshal.FreeCoTaskMem(ofn.lpstrFile);
         }
     }
     return flag;
 }
Example #4
0
 internal abstract bool RunFileDialog(System.Windows.Forms.NativeMethods.OPENFILENAME_I ofn);
Example #5
0
        protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
        {
            if (msg == 0x4e)
            {
                this.dialogHWnd = System.Windows.Forms.UnsafeNativeMethods.GetParent(new HandleRef(null, hWnd));
                try
                {
                    System.Windows.Forms.UnsafeNativeMethods.OFNOTIFY structure = (System.Windows.Forms.UnsafeNativeMethods.OFNOTIFY)System.Windows.Forms.UnsafeNativeMethods.PtrToStructure(lparam, typeof(System.Windows.Forms.UnsafeNativeMethods.OFNOTIFY));
                    switch (structure.hdr_code)
                    {
                    case -606:
                        if (this.ignoreSecondFileOkNotification)
                        {
                            if (this.okNotificationCount != 0)
                            {
                                break;
                            }
                            this.okNotificationCount = 1;
                        }
                        goto Label_0171;

                    case -604:
                        this.ignoreSecondFileOkNotification = true;
                        this.okNotificationCount            = 0;
                        goto Label_01CF;

                    case -602:
                    {
                        System.Windows.Forms.NativeMethods.OPENFILENAME_I openfilename_i = (System.Windows.Forms.NativeMethods.OPENFILENAME_I)System.Windows.Forms.UnsafeNativeMethods.PtrToStructure(structure.lpOFN, typeof(System.Windows.Forms.NativeMethods.OPENFILENAME_I));
                        int num = (int)System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.dialogHWnd), 0x464, IntPtr.Zero, IntPtr.Zero);
                        if (num > openfilename_i.nMaxFile)
                        {
                            try
                            {
                                int size = num + 0x800;
                                System.Windows.Forms.UnsafeNativeMethods.CharBuffer buffer = System.Windows.Forms.UnsafeNativeMethods.CharBuffer.CreateBuffer(size);
                                IntPtr ptr = buffer.AllocCoTaskMem();
                                Marshal.FreeCoTaskMem(openfilename_i.lpstrFile);
                                openfilename_i.lpstrFile = ptr;
                                openfilename_i.nMaxFile  = size;
                                this.charBuffer          = buffer;
                                Marshal.StructureToPtr(openfilename_i, structure.lpOFN, true);
                                Marshal.StructureToPtr(structure, lparam, true);
                            }
                            catch
                            {
                            }
                        }
                        this.ignoreSecondFileOkNotification = false;
                        goto Label_01CF;
                    }

                    case -601:
                        CommonDialog.MoveToScreenCenter(this.dialogHWnd);
                        goto Label_01CF;

                    default:
                        goto Label_01CF;
                    }
                    this.ignoreSecondFileOkNotification = false;
                    System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(new HandleRef(null, hWnd), 0, new HandleRef(null, System.Windows.Forms.NativeMethods.InvalidIntPtr));
                    return(System.Windows.Forms.NativeMethods.InvalidIntPtr);

Label_0171:
                    if (!this.DoFileOk(structure.lpOFN))
                    {
                        System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(new HandleRef(null, hWnd), 0, new HandleRef(null, System.Windows.Forms.NativeMethods.InvalidIntPtr));
                        return(System.Windows.Forms.NativeMethods.InvalidIntPtr);
                    }
                }
                catch
                {
                    if (this.dialogHWnd != IntPtr.Zero)
                    {
                        System.Windows.Forms.UnsafeNativeMethods.EndDialog(new HandleRef(this, this.dialogHWnd), IntPtr.Zero);
                    }
                    throw;
                }
            }
Label_01CF:
            return(IntPtr.Zero);
        }