Exemplo n.º 1
0
        /// <include file='doc\FileDialog.uex' path='docs/doc[@for="FileDialog.GetMultiselectFiles"]/*' />
        /// <devdoc>
        ///     Extracts the filename(s) returned by the file dialog.
        /// </devdoc>
        private string[] GetMultiselectFiles(CharBuffer charBuffer)
        {
            string directory = charBuffer.GetString();
            string fileName  = charBuffer.GetString();

            if (fileName.Length == 0)
            {
                return new string[] {
                           directory
                }
            }
            ;
            if (directory[directory.Length - 1] != '\\')
            {
                directory = directory + "\\";
            }
            ArrayList names = new ArrayList();

            do
            {
                if (fileName[0] != '\\' && (fileName.Length <= 3 ||
                                            fileName[1] != ':' || fileName[2] != '\\'))
                {
                    fileName = directory + fileName;
                }
                names.Add(fileName);
                fileName = charBuffer.GetString();
            } while (fileName.Length > 0);
            string[] temp = new string[names.Count];
            names.CopyTo(temp, 0);
            return(temp);
        }
Exemplo n.º 2
0
        private string[] GetMultiselectFiles(System.Windows.Forms.UnsafeNativeMethods.CharBuffer charBuffer)
        {
            string str  = charBuffer.GetString();
            string str2 = charBuffer.GetString();

            if (str2.Length == 0)
            {
                return(new string[] { str });
            }
            if (str[str.Length - 1] != '\\')
            {
                str = str + @"\";
            }
            ArrayList list = new ArrayList();

            do
            {
                if ((str2[0] != '\\') && (((str2.Length <= 3) || (str2[1] != ':')) || (str2[2] != '\\')))
                {
                    str2 = str + str2;
                }
                list.Add(str2);
                str2 = charBuffer.GetString();
            }while (str2.Length > 0);
            string[] array = new string[list.Count];
            list.CopyTo(array, 0);
            return(array);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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 = (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);
        }
Exemplo n.º 5
0
 /// <include file='doc\FileDialog.uex' path='docs/doc[@for="FileDialog.GetMultiselectFiles"]/*' />
 /// <devdoc>
 ///     Extracts the filename(s) returned by the file dialog.
 /// </devdoc>
 private string[] GetMultiselectFiles(CharBuffer charBuffer) {
     string directory = charBuffer.GetString();
     string fileName = charBuffer.GetString();
     if (fileName.Length == 0) return new string[] {
             directory
         };
     if (directory[directory.Length - 1] != '\\') {
         directory = directory + "\\";
     }
     ArrayList names = new ArrayList();
     do {
         if (fileName[0] != '\\' && (fileName.Length <= 3 ||
                                     fileName[1] != ':' || fileName[2] != '\\')) {
             fileName = directory + fileName;
         }
         names.Add(fileName);
         fileName = charBuffer.GetString();
     } while (fileName.Length > 0);
     string[] temp = new string[names.Count];
     names.CopyTo(temp, 0);
     return temp;
 }