コード例 #1
0
        /// <include file='doc\FileDialog.uex' path='docs/doc[@for="FileDialog.DoFileOk"]/*' />
        /// <devdoc>
        ///     Processes the CDN_FILEOK notification.
        /// </devdoc>
        private bool DoFileOk(IntPtr lpOFN)
        {
            NativeMethods.OPENFILENAME_I ofn = Marshal.PtrToStructure <NativeMethods.OPENFILENAME_I>(lpOFN);
            int saveOptions     = options;
            int saveFilterIndex = filterIndex;

            string[] saveFileNames = fileNames;
            bool     ok            = false;

            try {
                options = options & ~NativeMethods.OFN_READONLY |
                          ofn.Flags & NativeMethods.OFN_READONLY;
                filterIndex = ofn.nFilterIndex;
                charBuffer.PutCoTaskMem(ofn.lpstrFile);

                Thread.MemoryBarrier();

                if ((options & NativeMethods.OFN_ALLOWMULTISELECT) == 0)
                {
                    fileNames = new string[] { charBuffer.GetString() };
                }
                else
                {
                    fileNames = GetMultiselectFiles(charBuffer);
                }

                if (ProcessFileNames())
                {
                    CancelEventArgs ceevent = new CancelEventArgs();
                    if (NativeWindow.WndProcShouldBeDebuggable)
                    {
                        OnFileOk(ceevent);
                        ok = !ceevent.Cancel;
                    }
                    else
                    {
                        try
                        {
                            OnFileOk(ceevent);
                            ok = !ceevent.Cancel;
                        }
                        catch (Exception e)
                        {
                            Application.OnThreadException(e);
                        }
                    }
                }
            }
            finally {
                if (!ok)
                {
                    Thread.MemoryBarrier();
                    fileNames = saveFileNames;

                    options     = saveOptions;
                    filterIndex = saveFilterIndex;
                }
            }
            return(ok);
        }
コード例 #2
0
ファイル: FileDialog.cs プロジェクト: wenzai007/dotnet462
        /// <include file='doc\FileDialog.uex' path='docs/doc[@for="FileDialog.DoFileOk"]/*' />
        /// <devdoc>
        ///     Processes the CDN_FILEOK notification.
        /// </devdoc>
        private bool DoFileOk(IntPtr lpOFN)
        {
            NativeMethods.OPENFILENAME_I ofn = (NativeMethods.OPENFILENAME_I)UnsafeNativeMethods.PtrToStructure(lpOFN, typeof(NativeMethods.OPENFILENAME_I));
            int saveOptions     = options;
            int saveFilterIndex = filterIndex;

            string[] saveFileNames = fileNames;
            bool     saveSecurityCheckFileNames = securityCheckFileNames;
            bool     ok = false;

            try {
                options = options & ~NativeMethods.OFN_READONLY |
                          ofn.Flags & NativeMethods.OFN_READONLY;
                filterIndex = ofn.nFilterIndex;
                charBuffer.PutCoTaskMem(ofn.lpstrFile);

                // We are filling in the file names list with secure
                // data.  Any access to this list now will require
                // a security demand.  We set this bit before actually
                // setting the names; otherwise a thread ---- could
                // expose them.
                securityCheckFileNames = true;
                Thread.MemoryBarrier();

                if ((options & NativeMethods.OFN_ALLOWMULTISELECT) == 0)
                {
                    fileNames = new string[] { charBuffer.GetString() };
                }
                else
                {
                    fileNames = GetMultiselectFiles(charBuffer);
                }

                if (ProcessFileNames())
                {
                    CancelEventArgs ceevent = new CancelEventArgs();
                    if (NativeWindow.WndProcShouldBeDebuggable)
                    {
                        OnFileOk(ceevent);
                        ok = !ceevent.Cancel;
                    }
                    else
                    {
                        try
                        {
                            OnFileOk(ceevent);
                            ok = !ceevent.Cancel;
                        }
                        catch (Exception e)
                        {
                            Application.OnThreadException(e);
                        }
                    }
                }
            }
            finally {
                if (!ok)
                {
                    securityCheckFileNames = saveSecurityCheckFileNames;
                    Thread.MemoryBarrier();
                    fileNames = saveFileNames;

                    options     = saveOptions;
                    filterIndex = saveFilterIndex;
                }
            }
            return(ok);
        }