Example #1
0
        // get file from virtual file system
        public File GetFile(FilePath path, FileOpenMode mode)
        {
            if (!path.IsValid)
            {
                return(null);
            }

            // package is specified, look up in package file map
            if (path.PackageSpecified)
            {
                if ((mode & FileOpenMode.NoPackage) == FileOpenMode.NoPackage)
                {
                    PackageFactory factory = new PackageFactory();
                    return(factory.OpenFileDirectly(path.Package, path.PathWithoutPackage, mode));
                }
                else
                {
                    if (!nameMountMap.ContainsKey(path.Package))
                    {
                        return(null);
                    }

                    // translate file name from global name to package name
                    if (nameMountMap[path.Package].FileMap.ContainsKey(path.PathWithoutPackage))
                    {
                        string filepath = nameMountMap[path.Package].FileMap[path.PathWithoutPackage];
                        return(nameMountMap[path.Package].Package.GetFile(filepath, mode));
                    }
                    // if file not found and in write mode directly access package
                    else if (mode == FileOpenMode.Write)
                    {
                        nameMountMap[path.Package].Package.AddFile(path.PathWithoutPackage);
                        RefreshFileMountMap();
                        return(nameMountMap[path.Package].Package.GetFile(path.PathWithoutPackage, mode));
                    }
                }
            }
            // package is not specified, look up in global map
            else
            {
                if ((mode & FileOpenMode.NoPackage) == FileOpenMode.NoPackage)
                {
                    return(null);
                }

                if (fileMountMap.ContainsKey(path.PathWithoutPackage))
                {
                    LinkInfo link = fileMountMap[path.PathWithoutPackage];
                    if (link.FilePath == null)
                    {
                        return(link.Mount.Package.GetFile(path.PathWithoutPackage, mode));
                    }
                    return(link.Mount.Package.GetFile(link.FilePath, mode));
                }
            }

            return(null);
        }
Example #2
0
        // return virtual file
        static public File GetFile(FilePath path, FileOpenMode mode)
        {
            if (!path.IsValid)
            {
                Log.Warning("File path invalid: " + path);
                return(null);
            }

            if ((mode & FileOpenMode.NoPackage) == FileOpenMode.NoPackage)
            {
                PackageFactory factory = new PackageFactory();
                return(factory.OpenFileDirectly(GetBasedPath(path.Package), path.PathWithoutPackage, mode));
            }
            else
            {
                if (mode == FileOpenMode.Write)
                {
                    // if we need write access then always use the user package
                    path.Package = "user";
                }

                if (!path.PackageSpecified)
                {
                    File file = vfs.GetFile(path, mode);
                    if (file == null)
                    {
                        Log.Warning("File not found: " + path);
                    }

                    return(file);
                }
                else
                {
                    return(vfs.GetFile(path, mode));
                }
            }

            //    string[] token = path.Package.Split(new char[] { '\\', '/' });
            //if (!dicPackages.ContainsKey(token[token.Length - 1].ToLower()))
            //{
            //    if (PackagePak.IsPak(basePath + path.Package))
            //    {
            //        PackagePak pak = new PackagePak("", basePath + path.Package);
            //        File file = pak.GetFile(path.PathWithoutPackage, false);
            //        pak.Close();

            //        return file;
            //    }
            //    else
            //    {
            //        SystemFile file = new SystemFile(basePath + path.Package + "/" + path.PathWithoutPackage, path, false);
            //        return file;
            //    }
            //}

            //IPackage p = dicPackages[token[token.Length - 1].ToLower()];
            //return p.GetFile(path, WriteAccess);
        }