Exemple #1
0
 private void GetChildModel(TreeModel topModel)
 {
     if (File.Exists(topModel.AbsolutePath))
     {
         //topModel.ContextMenu = contextMenu;
         return;
     }
     else
     {
         //获取文件和文件夹
         string[] paths = Directory.GetFileSystemEntries(topModel.AbsolutePath, "*", SearchOption.TopDirectoryOnly);
         if (paths != null && paths.Length > 0)
         {
             for (int i = 0; i < paths.Length; i++)
             {
                 TreeModel childModel = new TreeModel();
                 childModel.AbsolutePath = paths[i];
                 childModel.DisplayName  = IOPath.GetFileName(childModel.AbsolutePath);
                 childModel.Parent       = topModel;
                 topModel.Children.Add(childModel);
                 GetChildModel(childModel);
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Loads an unmanaged library from filesystem
        /// </summary>
        /// <param name="fullFileName">full qualified name of the library file</param>
        /// <param name="fileVersion">optional file version to check major and minor</param>
        /// <returns>handle to library</returns>
        /// <exception cref="FileNotFoundException">File is missing</exception>
        /// <exception cref="Win32Exception">Unable to load library</exception>
        /// <exception cref="FileLoadException">A version mismatch occurs</exception>
        /// <exception cref="ArgumentNullException">fullFileName is null or empty</exception>
        /// <exception cref="NetOfficeIOException">I/O related error</exception>
        public static CdeclHandle LoadLibrary(string fullFileName, Version fileVersion = null)
        {
            if (String.IsNullOrWhiteSpace(fullFileName))
            {
                throw new ArgumentNullException("fullFileName");
            }
            if (!File.Exists(fullFileName))
            {
                throw new FileNotFoundException("File is missing.", fullFileName);
            }

            string folder   = IOPath.GetDirectoryName(fullFileName);
            string fileName = IOPath.GetFileName(fullFileName);

            if (null != fileVersion)
            {
                FileVersionInfo version = FileVersionInfo.GetVersionInfo(fullFileName);
                if (version.FileMajorPart != fileVersion.Major ||
                    version.FileMinorPart != fileVersion.Minor)
                {
                    throw new FileLoadException(
                              String.Format("Unable to load library <{0}> because a version mismatch occurs.", fileName));
                }
            }

            IntPtr ptr = Interop.LoadLibrary(fullFileName);

            if (ptr == IntPtr.Zero)
            {
                throw new Win32Exception(String.Format("Unable to load library <{0}>.", fileName));
            }

            return(new CdeclHandle(ptr, folder, fileName));
        }
Exemple #3
0
        private TreeModel GetTreeModel(string path)
        {
            if (!Directory.Exists(path))
            {
                return(null);
            }
            TreeModel topModel = new TreeModel();

            topModel.DisplayName  = IOPath.GetFileName(path);
            topModel.AbsolutePath = path;
            topModel.Parent       = null;
            topModel.ContextMenu  = contextMenu;
            GetChildModel(topModel);
            return(topModel);
        }