예제 #1
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));
        }
예제 #2
0
        //根据歌曲,获取歌词
        private List <Lynic> GetLynicBySong(Song s)
        {
            string lynicFile1 = IOPath.Combine(IOPath.GetDirectoryName(s.Location), IOPath.GetFileNameWithoutExtension(s.Location) + ".lrc");
            string lynicFile2 = IOPath.Combine(IOPath.GetDirectoryName(s.Location), "Lynic", IOPath.GetFileNameWithoutExtension(s.Location) + ".lrc");

            if (File.Exists(lynicFile1))
            {
                return(EntityService.GetLynics(lynicFile1));
            }
            else if (File.Exists(lynicFile2))
            {
                return(EntityService.GetLynics(lynicFile2));
            }
            else
            {
                return(null);
            }
        }