public virtual string GetFileHash(IVirtualFile virtualFile)
        {
            if (virtualFile == null)
                return String.Empty;

            return virtualFile.GetFileHash();
        }
Exemple #2
0
        private List<string> ConvertFileNameToTreeableData(IVirtualFile fi)
        {
            List<string> result = fi.VirtualPath.Split('\\').ToList();
            if(result.Count < 3)
                result.Add("CD1");

            result.Add(fi.Name);
            return result;
        }
        MemCachedFile( IVirtualFile file )
        {
            if (file == null) throw new FileNotFoundException();
            this.path = file.VirtualPath;

            using (Stream s = file.Open()) {
                this.data = StreamExtensions.CopyToBytes(s);
            }
        }
        public static void WriteFile(this IVirtualPathProvider pathProvider, IVirtualFile file, string filePath = null)
        {
            var writableFs = pathProvider as IVirtualFiles;
            if (writableFs == null)
                throw new InvalidOperationException(ErrorNotWritable.Fmt(pathProvider.GetType().Name));

            using (var stream = file.OpenRead())
            {
                writableFs.WriteFile(filePath ?? file.VirtualPath, stream);
            }
        }
        public RazorPageHost(IVirtualPathProvider pathProvider,
                              IVirtualFile file,
                              IRazorCodeTransformer codeTransformer,
                              CodeDomProvider codeDomProvider,
                              IDictionary<string, string> directives)
            : base(new CSharpRazorCodeLanguage())
        {
            this.PathProvider = pathProvider;
            this.File = file;

            if (codeTransformer == null)
            {
                throw new ArgumentNullException("codeTransformer");
            }
            if (this.PathProvider == null)
            {
                throw new ArgumentNullException("pathProvider");
            }
            if (this.File == null)
            {
                throw new ArgumentNullException("file");
            }
            if (codeDomProvider == null)
            {
                throw new ArgumentNullException("codeDomProvider");
            }
            _codeTransformer = codeTransformer;
            _codeDomProvider = codeDomProvider;
            _directives = directives;
            base.DefaultNamespace = "ASP";
            EnableLinePragmas = true;

            base.GeneratedClassContext = new GeneratedClassContext(
                executeMethodName: GeneratedClassContext.DefaultExecuteMethodName,
                writeMethodName: GeneratedClassContext.DefaultWriteMethodName,
                writeLiteralMethodName: GeneratedClassContext.DefaultWriteLiteralMethodName,
                writeToMethodName: "WriteTo",
                writeLiteralToMethodName: "WriteLiteralTo",
                templateTypeName: typeof(HelperResult).FullName,
                defineSectionMethodName: "DefineSection",
                beginContextMethodName: "BeginContext",
                endContextMethodName: "EndContext"
                )
                {
                    ResolveUrlMethodName = "Href",
                };

            base.DefaultBaseClass = typeof(ViewPage).FullName;
            foreach (var import in _defaultImports)
            {
                base.NamespaceImports.Add(import);
            }
        }
        public HttpResult(IVirtualFile fileResponse, string contentType = null, bool asAttachment = false)
            : this(null, contentType ?? MimeTypes.GetMimeType(fileResponse.Name), HttpStatusCode.OK)
        {
            this.AllowsPartialResponse = true;
            this.ResponseStream = fileResponse.OpenRead();

            if (!asAttachment) return;

            var headerValue = $"attachment; filename=\"{fileResponse.Name}\"; size={fileResponse.Length}; modification-date={fileResponse.LastModified.ToString("R").Replace(",", "")}";

            this.Headers = new Dictionary<string, string>
            {
                { HttpHeaders.ContentDisposition, headerValue },
            };
        }
Exemple #7
0
        /// <summary>
        /// Creates file list item object.
        /// </summary>
        /// <param name="file">actual file it presents.</param>
        /// <param name="window">window it belongs to.</param>
        public FileListItem(IVirtualFile file, Window window)
            : base(window, CreationFlag.FlagsNone)
        {
            if (null == file)
            {
                throw new Exception("file can not be null");
            }

            this.file = file;
            this.NeedTranslation = false;
            this.Text = file.Name;
            this.Name = file.Name;
            this.ListStyle = ListStyle.Details;
            this.BackColor = Colors.None;

            SetFileIcon();
        }
 /// <summary>
 /// The write to stream.
 /// </summary>
 /// <param name="provider">
 /// The provider.
 /// </param>
 /// <param name="sw">
 /// The sw.
 /// </param>
 /// <param name="vf">
 /// The vf.
 /// </param>
 /// <param name="type">
 /// The type.
 /// </param>
 /// <param name="origUrl">
 /// The orig url.
 /// </param>
 /// <param name="http">
 /// The http.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public bool WriteToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, IVirtualFile vf, ClientDependencyType type, string origUrl, HttpContextBase http)
 {
     try
     {
         using (var readStream = vf.Open())
         using (var streamReader = new StreamReader(readStream))
         {
             var output = streamReader.ReadToEnd();
             DefaultFileWriter.WriteContentToStream(provider, sw, output, type, http, origUrl);
             return true;
         }
     }
     catch (Exception)
     {
         // the file must have failed to open
         return false;
     }
 }
Exemple #9
0
        protected virtual void TrackRazorPage( IVirtualFile file )
        {
            //get the base type.
            var pageBaseType = this.Config.PageBaseType;

            var transformer = new RazorViewPageTransformer( pageBaseType );

            //create a RazorPage
            var page = new RazorPage
                {
                    PageHost = new RazorPageHost( PathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>() ),
                    IsValid = false,
                    File = file
                };

            //add it to our pages dictionary.
            AddRazorPage(page);
        }
 /// <summary>
 /// Writes the virtual file to a stream for serving.
 /// </summary>
 /// <param name="provider">The file processing provider.</param>
 /// <param name="streamWriter">The <see cref="StreamWriter"/>.</param>
 /// <param name="virtualFile">The <see cref="IVirtualFile"/> to write.</param>
 /// <param name="type">The <see cref="ClientDependencyType"/> the virtual file matches.</param>
 /// <param name="originalUrl">The original url to the virtual file.</param>
 /// <param name="context">The <see cref="HttpContextBase"/>.</param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public bool WriteToStream(
     BaseCompositeFileProcessingProvider provider, 
     StreamWriter streamWriter, 
     IVirtualFile virtualFile, 
     ClientDependencyType type, 
     string originalUrl, 
     HttpContextBase context)
 {
     try
     {
         using (Stream readStream = virtualFile.Open())
         using (StreamReader streamReader = new StreamReader(readStream))
         {
             string output = streamReader.ReadToEnd();
             DefaultFileWriter.WriteContentToStream(provider, streamWriter, output, type, context, originalUrl);
             return true;
         }
     }
     catch (Exception)
     {
         // The file must have failed to open
         return false;
     }
 }
Exemple #11
0
 public HttpResult(IVirtualFile fileResponse, bool asAttachment)
     : this(fileResponse, MimeTypes.GetMimeType(fileResponse.Name), asAttachment)
 { }
 public virtual RazorPage AddPage(IVirtualFile file)
 {
     return(IsWatchedFile(file)
         ? TrackPage(file)
         : null);
 }
Exemple #13
0
        protected internal virtual void readSection(PbpSection section)
        {
            if (section.size > 0)
            {
                try
                {
                    if (section.cacheFile != null)
                    {
                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("XmbIsoVirtualFile.readSection from Cache {0}", section.cacheFile));
                        }

                        System.IO.Stream @is = new System.IO.FileStream(section.cacheFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        @is.Read(contents, section.offset, section.size);
                        @is.Close();
                    }
                    else
                    {
                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("XmbIsoVirtualFile.readSection from UMD {0}", section.umdFilename));
                        }

                        UmdIsoReader       iso   = new UmdIsoReader(umdFilename);
                        IVirtualFileSystem vfs   = new UmdIsoVirtualFileSystem(iso);
                        IVirtualFile       vFile = vfs.ioOpen(section.umdFilename, IoFileMgrForUser.PSP_O_RDONLY, 0);
                        if (vFile != null)
                        {
                            vFile.ioRead(contents, section.offset, section.size);
                            vFile.ioClose();
                        }
                        vfs.ioExit();
                    }
                }
                catch (IOException e)
                {
                    Console.WriteLine("readSection", e);
                }

                // PARAM.SFO?
                if (section.index == 1)
                {
                    // Patch the CATEGORY in the PARAM.SFO:
                    // the VSH is checking that the CATEGORY value is starting
                    // with 'M' (meaning MemoryStick) and not 'U' (UMD).
                    // Change the first letter 'U' into 'M'.
                    int offset           = section.offset;
                    int keyTableOffset   = readUnaligned32(contents, offset + 8) + offset;
                    int valueTableOffset = readUnaligned32(contents, offset + 12) + offset;
                    int numberKeys       = readUnaligned32(contents, offset + 16);
                    for (int i = 0; i < numberKeys; i++)
                    {
                        int    keyOffset = readUnaligned16(contents, offset + 20 + i * 16);
                        string key       = Utilities.readStringZ(contents, keyTableOffset + keyOffset);
                        if ("CATEGORY".Equals(key))
                        {
                            int  valueOffset    = readUnaligned32(contents, offset + 20 + i * 16 + 12);
                            char valueFirstChar = (char)contents[valueTableOffset + valueOffset];

                            // Change the first letter 'U' into 'M'.
                            if (valueFirstChar == 'U')
                            {
                                contents[valueTableOffset + valueOffset] = (sbyte)'M';
                            }
                            break;
                        }
                    }
                }
            }

            section.availableInContents = true;
        }
Exemple #14
0
 public virtual int ioIoctl(IVirtualFile file, int command, TPointer inputPointer, int inputLength, TPointer outputPointer, int outputLength)
 {
     return(vfs.ioIoctl(file, command, inputPointer, inputLength, outputPointer, outputLength));
 }
 private RazorPageHost CreatePageHost(IVirtualFile file, RazorViewPageTransformer transformer)
 {
     return new RazorPageHost(PathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>())
     {
         IncludeDebugInformation = IncludeDebugInformation,
         CompileFilter = CompileFilter,
     };
 }
Exemple #16
0
 public WebVirtualFile(IVirtualFile virtualFile)
     : base(virtualFile.VirtualPath)
 {
     _virtualFile = virtualFile;
 }
 /// <summary>
 /// Override to return whether static files should be sent compressed or not (if supported by UserAgent)
 /// </summary>
 public virtual bool ShouldCompressFile(IVirtualFile file)
 {
     return(!string.IsNullOrEmpty(file.Extension) &&
            Config.CompressFilesWithExtensions.Contains(file.Extension) &&
            (Config.CompressFilesLargerThanBytes == null || file.Length > Config.CompressFilesLargerThanBytes));
 }
Exemple #18
0
 public virtual bool IsViewFile(IVirtualFile virtualFile)
 {
     return(virtualFile.RealPath != null &&
            virtualFile.RealPath.Contains("{0}{1}".Fmt(RealPathSeparator, "Views")));
 }
Exemple #19
0
 public virtual string GetFileHash(IVirtualFile virtualFile)
 {
     return(virtualFile == null ? string.Empty : virtualFile.GetFileHash());
 }
Exemple #20
0
        public void Register(IAppHost appHost)
        {
            if (ResourceFilterPattern != null)
            {
                SwaggerResourcesService.resourceFilterRegex = new Regex(ResourceFilterPattern, RegexOptions.Compiled);
            }

            SwaggerResourcesService.ResourcesResponseFilter = ResourcesResponseFilter;

            SwaggerApiService.UseCamelCaseModelPropertyNames           = UseCamelCaseModelPropertyNames;
            SwaggerApiService.UseLowercaseUnderscoreModelPropertyNames = UseLowercaseUnderscoreModelPropertyNames;
            SwaggerApiService.DisableAutoDtoInBodyParam = DisableAutoDtoInBodyParam;
            SwaggerApiService.ApiDeclarationFilter      = ApiDeclarationFilter;
            SwaggerApiService.OperationFilter           = OperationFilter;
            SwaggerApiService.ModelFilter         = ModelFilter;
            SwaggerApiService.ModelPropertyFilter = ModelPropertyFilter;
            SwaggerApiService.AnyRouteVerbs       = AnyRouteVerbs.ToArray();

            appHost.RegisterService(typeof(SwaggerResourcesService), "/resources");
            appHost.RegisterService(typeof(SwaggerApiService), SwaggerResourcesService.RESOURCE_PATH + "/{Name*}");

            var swaggerUrl = UseBootstrapTheme
                ? "swagger-ui-bootstrap/"
                : "swagger-ui/";

            appHost.GetPlugin <MetadataFeature>()
            .AddPluginLink(swaggerUrl, "Swagger UI");

            appHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) =>
            {
                IVirtualFile indexFile;
                IVirtualFile patchFile = null;
                switch (pathInfo)
                {
                case "/swagger-ui":
                case "/swagger-ui/":
                case "/swagger-ui/default.html":
                    indexFile = appHost.VirtualFileSources.GetFile("/swagger-ui/index.html");
                    patchFile = appHost.VirtualFileSources.GetFile("/swagger-ui/patch.js");
                    break;

                case "/swagger-ui-bootstrap":
                case "/swagger-ui-bootstrap/":
                case "/swagger-ui-bootstrap/index.html":
                    indexFile = appHost.VirtualFileSources.GetFile("/swagger-ui-bootstrap/index.html");
                    break;

                default:
                    indexFile = null;
                    break;
                }
                if (indexFile != null)
                {
                    var html     = indexFile.ReadAllText();
                    var injectJs = patchFile?.ReadAllText();

                    return(new CustomResponseHandler((req, res) =>
                    {
                        res.ContentType = MimeTypes.HtmlUtf8; //use alt HTML ContentType so it's not overridden when Feature.Html is removed
                        var resourcesUrl = req.ResolveAbsoluteUrl("~/resources");
                        var logoHref = LogoHref ?? "./";
                        html = html.Replace("http://petstore.swagger.io/v2/swagger.json", resourcesUrl)
                               .Replace("ApiDocs", HostContext.ServiceName)
                               .Replace("<a id=\"logo\" href=\"http://swagger.io\">swagger</a>", $"<a id=\"logo\" href=\"{logoHref}\">{HostContext.ServiceName}</a>");

                        if (LogoUrl != null)
                        {
                            html = html.Replace("{LogoUrl}", LogoUrl);
                        }

                        if (injectJs != null)
                        {
                            html = html.Replace("</body>",
                                                "<script type='text/javascript'>" + injectJs + "</script></body>");
                        }

                        return html;
                    }));
                }
                return(pathInfo.StartsWith("/swagger-ui") ? new StaticFileHandler() : null);
            });
        }
        /// <summary>
        /// Writes the output of a local file to the stream
        /// </summary>
        /// <param name="sw"></param>
        /// <param name="vf"></param>
        /// <param name="virtualWriter"></param>
        /// <param name="type"></param>
        /// <param name="http"></param>
        protected virtual CompositeFileDefinition WriteVirtualFileToStream(StreamWriter sw, IVirtualFile vf, IVirtualFileWriter virtualWriter, ClientDependencyType type, HttpContextBase http)
        {
            if (virtualWriter == null)
            {
                throw new ArgumentNullException("virtualWriter");
            }
            if (vf == null)
            {
                return(null);
            }

            return(virtualWriter.WriteToStream(this, sw, vf, type, vf.Path, http)
                ? new CompositeFileDefinition(vf.Path, true)
                : null);
        }
Exemple #22
0
 public StaticFileHandler(IVirtualFile virtualFile) : this()
 {
     VirtualNode = virtualFile;
 }
Exemple #23
0
 public virtual bool IsViewFile(IVirtualFile virtualFile)
 {
     return(virtualFile.RealPath != null &&
            virtualFile.RealPath.Contains($"{RealPathSeparator}Views"));
 }
Exemple #24
0
 protected virtual bool IsWatchedFile( IVirtualFile file )
 {
     return this.Config.RazorFileExtension.EndsWith( file.Extension, StringComparison.InvariantCultureIgnoreCase );
 }
 public virtual string GetFileHash(IVirtualFile virtualFile)
 {
     return virtualFile == null ? string.Empty : virtualFile.GetFileHash();
 }
Exemple #26
0
 public static void DeleteFile(this IVirtualPathProvider pathProvider, IVirtualFile file)
 {
     pathProvider.DeleteFile(file.VirtualPath);
 }
Exemple #27
0
 public virtual bool IsSharedFile(IVirtualFile virtualFile)
 {
     return(virtualFile.RealPath != null &&
            virtualFile.RealPath.Contains($"{RealPathSeparator}Shared"));
 }
Exemple #28
0
 private string GetPageContents(IVirtualFile page)
 {
     return(ReplaceContentWithRewriteTokens(page.ReadAllText()));
 }
 public virtual bool IsWatchedFile(IVirtualFile file)
 {
     return this.Config.RazorFileExtension.EndsWithIgnoreCase(file.Extension);
 }
Exemple #30
0
        public void Register(IAppHost appHost)
        {
            if (ResourceFilterPattern != null)
            {
                SwaggerResourcesService.resourceFilterRegex = new Regex(ResourceFilterPattern, RegexOptions.Compiled);
            }

            SwaggerApiService.UseCamelCaseModelPropertyNames           = UseCamelCaseModelPropertyNames;
            SwaggerApiService.UseLowercaseUnderscoreModelPropertyNames = UseLowercaseUnderscoreModelPropertyNames;
            SwaggerApiService.DisableAutoDtoInBodyParam = DisableAutoDtoInBodyParam;
            SwaggerApiService.ModelFilter         = ModelFilter;
            SwaggerApiService.ModelPropertyFilter = ModelPropertyFilter;

            appHost.RegisterService(typeof(SwaggerResourcesService), new[] { "/resources" });
            appHost.RegisterService(typeof(SwaggerApiService), new[] { SwaggerResourcesService.RESOURCE_PATH + "/{Name*}" });

            //modified by Yang Li
            //var swaggerUrl = UseBootstrapTheme
            //    ? "swagger-ui-bootstrap/"
            //    : "swagger-ui/";
            var swaggerUrl = UseBootstrapTheme
                ? "JSOA/Api/UI/jsoa-api-ui-bootstrap/"
                : "JSOA/Api/UI/jsoa-api-ui/";

            //var swaggerUrl = UseBootstrapTheme
            //    ? "ServiceStack/Api/Swagger/swagger-ui-bootstrap/"
            //    : "ServiceStack/Api/Swagger/swagger-ui/";

            //modified by Yang Li
            //appHost.GetPlugin<MetadataFeature>()
            //    .AddPluginLink(swaggerUrl, "Swagger UI");
            appHost.GetPlugin <MetadataFeature>()
            .AddPluginLink(swaggerUrl, "JSOA 2.0 API UI");

            appHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) =>
            {
                IVirtualFile indexFile;
                IVirtualFile patchFile = null;
                switch (pathInfo)
                {
                //modified by Yang Li
                //case "/swagger-ui":
                //case "/swagger-ui/":
                //case "/swagger-ui/default.html":
                case "/jsoa-api-ui":
                case "/jsoa-api-ui/":
                case "/jsoa-api-ui/default.html":
                    //modified by Yang Li
                    //indexFile = appHost.VirtualPathProvider.GetFile("/swagger-ui/index.html");
                    //patchFile = appHost.VirtualPathProvider.GetFile("/swagger-ui/patch.js");
                    indexFile = appHost.VirtualPathProvider.GetFile("/JSOA/Api/UI/jsoa-api-ui/index.html");
                    patchFile = appHost.VirtualPathProvider.GetFile("/JSOA/Api/UI/jsoa-api-ui/patch.js");
                    //indexFile = appHost.VirtualPathProvider.GetFile("/ServiceStack/Api/Swagger/swagger-ui/index.html");
                    //patchFile = appHost.VirtualPathProvider.GetFile("/ServiceStack/Api/Swagger/swagger-ui/patch.js");
                    break;

                //modified by Yang Li
                //case "/swagger-ui-bootstrap":
                //case "/swagger-ui-bootstrap/":
                //case "/swagger-ui-bootstrap/index.html":
                case "/jsoa-api-ui-bootstrap":
                case "/jsoa-api-ui-bootstrap/":
                case "/jsoa-api-ui-bootstrap/index.html":
                    //modified by Yang Li
                    //indexFile = appHost.VirtualPathProvider.GetFile("/swagger-ui-bootstrap/index.html");
                    indexFile = appHost.VirtualPathProvider.GetFile("/JSOA/Api/UI/jsoa-api-ui-bootstrap/index.html");
                    //indexFile = appHost.VirtualPathProvider.GetFile("/ServiceStack/Api/Swagger/swagger-ui-bootstrap/index.html");
                    break;

                default:
                    indexFile = null;
                    break;
                }
                if (indexFile != null)
                {
                    var html     = indexFile.ReadAllText();
                    var injectJs = patchFile != null
                        ? patchFile.ReadAllText()
                        : null;

                    return(new CustomResponseHandler((req, res) =>
                    {
                        res.ContentType = MimeTypes.Html;
                        var resourcesUrl = req.ResolveAbsoluteUrl("~/resources");
                        html = html.Replace("http://petstore.swagger.io/v2/swagger.json", resourcesUrl)
                               .Replace("ApiDocs", HostContext.ServiceName)
                               .Replace("{LogoUrl}", LogoUrl);

                        if (injectJs != null)
                        {
                            html = html.Replace("</body>",
                                                "<script type='text/javascript'>" + injectJs + "</script></body>");
                        }

                        return html;
                    }));
                }
                //modified by Yang Li
                //return pathInfo.StartsWith("/swagger-ui") ? new StaticFileHandler() : null;
                return(pathInfo.StartsWith("/JSOA/Api/UI/jsoa-api-ui") ? new StaticFileHandler() : null);
                //return pathInfo.StartsWith("/ServiceStack/Api/Swagger/swagger-ui") ? new StaticFileHandler() : null;
            });
        }
 /// <summary>
 /// The write to stream.
 /// </summary>
 /// <param name="provider">
 /// The provider.
 /// </param>
 /// <param name="sw">
 /// The sw.
 /// </param>
 /// <param name="vf">
 /// The vf.
 /// </param>
 /// <param name="type">
 /// The type.
 /// </param>
 /// <param name="origUrl">
 /// The orig url.
 /// </param>
 /// <param name="http">
 /// The http.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public bool WriteToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, IVirtualFile vf, ClientDependencyType type, string origUrl, HttpContextBase http)
 {
     try
     {
         using (var readStream = vf.Open())
             using (var streamReader = new StreamReader(readStream))
             {
                 var output = streamReader.ReadToEnd();
                 DefaultFileWriter.WriteContentToStream(provider, sw, output, type, http, origUrl);
                 return(true);
             }
     }
     catch (Exception)
     {
         // the file must have failed to open
         return(false);
     }
 }
Exemple #32
0
 public override bool IsViewFile(IVirtualFile virtualFile)
 {
     return(virtualFile.VirtualPathProvider.IsViewFile(virtualFile));
 }
Exemple #33
0
        public XmbIsoVirtualFile(string umdFilename) : base(null)
        {
            this.umdFilename = umdFilename;
            umdName          = System.IO.Path.GetFileName(umdFilename);

            File cacheDirectory   = new File(CacheDirectory);
            bool createCacheFiles = !cacheDirectory.Directory;

            if (createCacheFiles)
            {
                cacheDirectory.mkdirs();
            }

            try
            {
                UmdIsoReader       iso = new UmdIsoReader(umdFilename);
                IVirtualFileSystem vfs = new UmdIsoVirtualFileSystem(iso);
                sections           = new PbpSection[umdFilenames.Length + 1];
                sections[0]        = new PbpSection();
                sections[0].index  = 0;
                sections[0].offset = 0;
                sections[0].size   = 0x28;
                sections[0].availableInContents = true;
                int       offset = 0x28;
                SceIoStat stat   = new SceIoStat();
                for (int i = 0; i < umdFilenames.Length; i++)
                {
                    PbpSection section = new PbpSection();
                    section.index       = i + 1;
                    section.offset      = offset;
                    section.umdFilename = umdFilenames[i];
                    if (vfs.ioGetstat(section.umdFilename, stat) >= 0)
                    {
                        section.size = (int)stat.size;
                        if (log.TraceEnabled)
                        {
                            log.trace(string.Format("{0}: mapping {1} at offset 0x{2:X}, size 0x{3:X}", umdFilename, umdFilenames[i], section.offset, section.size));
                        }
                    }

                    string cacheFileName = getCacheFileName(section);
                    File   cacheFile     = new File(cacheFileName);

                    // Create only cache files for PARAM.SFO and ICON0.PNG
                    if (createCacheFiles && i < 2)
                    {
                        IVirtualFile vFile = vfs.ioOpen(section.umdFilename, IoFileMgrForUser.PSP_O_RDONLY, 0);
                        if (vFile != null)
                        {
                            section.size = (int)vFile.Length();
                            sbyte[] buffer = new sbyte[section.size];
                            int     Length = vFile.ioRead(buffer, 0, buffer.Length);
                            vFile.ioClose();

                            System.IO.Stream os = new System.IO.FileStream(cacheFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                            os.Write(buffer, 0, Length);
                            os.Close();
                        }
                    }

                    if (cacheFile.canRead())
                    {
                        section.cacheFile = cacheFile;
                    }

                    sections[section.index] = section;
                    offset += section.size;
                }
                totalLength = offset;

                contents = new sbyte[offset];
                ByteBuffer buffer = ByteBuffer.wrap(contents).order(ByteOrder.LITTLE_ENDIAN);
                buffer.putInt(PBP.PBP_MAGIC);
                buffer.putInt(0x10000);                 // version
                for (int i = 1; i < sections.Length; i++)
                {
                    buffer.putInt(sections[i].offset);
                }
                int endSectionOffset = sections[sections.Length - 1].offset + sections[sections.Length - 1].size;
                for (int i = sections.Length; i <= 8; i++)
                {
                    buffer.putInt(endSectionOffset);
                }

                if (log.TraceEnabled)
                {
                    log.trace(string.Format("{0}: PBP header :{1}", umdFilename, Utilities.getMemoryDump(contents, sections[0].offset, sections[0].size)));
                }
                vfs.ioExit();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("XmbIsoVirtualFile", e);
            }
            catch (IOException e)
            {
                Console.WriteLine("XmbIsoVirtualFile", e);
            }
        }
Exemple #34
0
 TemplatePage CreatePage(IVirtualFile file) =>
 new TemplatePage(appHost.GetPlugin <TemplatePagesFeature>(), file);
Exemple #35
0
        public IVirtualFile GetFileIfCached(string virtualPath, System.Collections.Specialized.NameValueCollection queryString, IVirtualFile original)
        {
            if (!"disk".Equals(queryString["scache"], StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            if (this.AsyncModuleMode)
            {
                throw new InvalidOperationException("SourceDiskCache cannot be used in synchronous mode if AsyncModuleMode=true");
            }


            //Verify web.config exists in the cache folder.
            writer.CheckWebConfigEvery5();

            //Use alternate cache key if provided
            string key = original is IVirtualFileSourceCacheKey ? ((IVirtualFileSourceCacheKey)original).GetCacheKey(false) : original.VirtualPath;
            //If cached, serve it.

            var r = cache.GetCachedFile(key, ".cache", delegate(Stream target)
            {
                using (Stream data = original.Open())
                { //Very long-running call
                    data.CopyToStream(target);
                }
            }, 15 * 1000, true);

            if (r.Result == CacheQueryResult.Failed)
            {
                return(null);
            }

            if (r.Result == CacheQueryResult.Hit && cleaner != null)
            {
                cleaner.UsedFile(r.RelativePath, r.PhysicalPath);
            }


            return(new SourceVirtualFile(original.VirtualPath, delegate(){
                return r.Data ?? File.Open(r.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            }));
        }
Exemple #36
0
 public RazorPage GetPage(IVirtualFile file)
 {
     return(GetPage(file.VirtualPath));
 }
        public IVirtualFile GetFileIfCached(string virtualPath, System.Collections.Specialized.NameValueCollection queryString, IVirtualFile original)
        {
            if (!"disk".Equals(queryString["scache"], StringComparison.OrdinalIgnoreCase)) return null;

            //Verify web.config exists in the cache folder.
            writer.CheckWebConfigEvery5();

            //Use alternate cache key if provided
            string key = original is IVirtualFileSourceCacheKey ? ((IVirtualFileSourceCacheKey)original).GetCacheKey(false) : original.VirtualPath;
            //If cached, serve it.
            var r = cache.GetCachedFile(key, ".cache", delegate(Stream target)
            {
                using (Stream data = original.Open())
                {//Very long-running call
                    StreamExtensions.CopyToStream(data, target);
                }
            }, DateTime.MinValue, 15 * 1000,true);

            if (r.Result == CacheQueryResult.Failed)
                throw new ImageResizer.ImageProcessingException("Failed to acquire a lock on file \"" + r.PhysicalPath + "\" within 15 seconds. Source caching failed.");

            if (r.Result == CacheQueryResult.Hit && cleaner != null)
                cleaner.UsedFile(r.RelativePath, r.PhysicalPath);

            return new SourceVirtualFile(original.VirtualPath,delegate(){
                return r.Data ?? File.Open(r.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            });
        }
 public virtual bool IsViewFile(IVirtualFile virtualFile)
 {
     return virtualFile.RealPath != null
         && virtualFile.RealPath.Contains("{0}{1}".Fmt(RealPathSeparator, "Views"));
 }
 private bool ShouldSkipPath(IVirtualFile csHtmlFile)
 {
     foreach (var skipPath in SkipPaths)
     {
         if (csHtmlFile.VirtualPath.StartsWith(skipPath, StringComparison.InvariantCultureIgnoreCase))
             return true;
     }
     return false;
 }
        /// <summary>
        /// Writes the output of a local file to the stream
        /// </summary>
        /// <param name="sw"></param>
        /// <param name="vf"></param>
        /// <param name="virtualWriter"></param>
        /// <param name="type"></param>
        /// <param name="http"></param>
        protected virtual CompositeFileDefinition WriteVirtualFileToStream(StreamWriter sw, IVirtualFile vf, IVirtualFileWriter virtualWriter, ClientDependencyType type, HttpContextBase http)
        {
            if (virtualWriter == null) throw new ArgumentNullException("virtualWriter");
            if (vf == null) return null;

            return virtualWriter.WriteToStream(this, sw, vf, type, vf.Path, http)
                ? new CompositeFileDefinition(vf.Path, true)
                : null;
        }
        public virtual RazorPage TrackPage(IVirtualFile file)
        {
            //get the base type.
            var pageBaseType = this.Config.PageBaseType;

            var transformer = new RazorViewPageTransformer(pageBaseType);

            //create a RazorPage
            var page = new RazorPage
            {
                PageHost = new RazorPageHost(PathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>()),
                IsValid = false,
                File = file
            };

            //add it to our pages dictionary.
            AddPage(page);

            if (Config.PrecompilePages.GetValueOrDefault())
                PrecompilePage(page);

            return page;
        }
 public override bool IsViewFile(IVirtualFile virtualFile)
 {
     return virtualFile.VirtualPathProvider.IsViewFile(virtualFile);
 }
        private bool CheckDestFreeSpace(OverwriteDialogResult overwrite, IVirtualFile source, IVirtualFile dest, IVirtualFolder destFolder)
        {
            bool flag;
            long num = -1L;
            IVirtualFolder folderRoot = VirtualItemHelper.GetFolderRoot(destFolder);
            if ((folderRoot != null) && folderRoot.IsPropertyAvailable(0x1b))
            {
                object obj2 = folderRoot[0x1b];
                if (obj2 != null)
                {
                    num = Convert.ToInt64(obj2);
                }
            }
            if (num < 0L)
            {
                return true;
            }
            object obj3 = source[3];
            if (obj3 == null)
            {
                return true;
            }
            uint clusterSize = 0;
            IGetVirtualVolume volume = destFolder as IGetVirtualVolume;
            if (volume != null)
            {
                clusterSize = volume.ClusterSize;
                if (string.Equals(volume.FileSystem, "FAT32", StringComparison.OrdinalIgnoreCase))
                {
                    num = Math.Min(num, 0x100000000L);
                }
            }
            long num3 = Convert.ToInt64(obj3);
            if (clusterSize > 0)
            {
                num3 = (long) (((num3 / ((ulong) clusterSize)) + Math.Sign((long) (num3 % ((ulong) clusterSize)))) * clusterSize);
            }
        Label_00E7:
            flag = num3 <= num;
            if ((!flag && (dest is IPersistVirtualItem)) && ((IPersistVirtualItem) dest).Exists)
            {
                long num4 = Convert.ToInt64(dest[3]);
                if (clusterSize > 0)
                {
                    num4 = (long) (((num4 / ((ulong) clusterSize)) + Math.Sign((long) (num4 % ((ulong) clusterSize)))) * clusterSize);
                }
                switch (overwrite)
                {
                    case OverwriteDialogResult.Overwrite:
                        flag = num3 < (num + num4);
                        break;

                    case OverwriteDialogResult.Resume:
                        flag = (num3 - num4) < num;
                        break;
                }
            }
            if (flag)
            {
                return true;
            }
            Exception error = new WarningException(string.Format(Resources.sNotEnoughSpaceInDest, destFolder.FullName, source.FullName));
            switch (this.ChangeItemError(null, source, dest, AvailableItemActions.CanRetryOrIgnore, error))
            {
                case ChangeItemAction.Retry:
                    goto Label_00E7;

                case ChangeItemAction.Ignore:
                    return true;

                case ChangeItemAction.Skip:
                    return false;

                case ChangeItemAction.Cancel:
                    base.CancelAsync();
                    return false;
            }
            throw error;
        }
        public virtual RazorPage AddPage(IVirtualFile file)
        {
            if (!IsWatchedFile(file))
                return null;

            var page = GetPage(file);
            if (page != null)
                return page;

            return TrackPage(file);
        }
Exemple #45
0
 public virtual bool IsWatchedFile(IVirtualFile file)
 {
     return(file != null && this.Config.RazorFileExtension.EndsWithIgnoreCase(file.Extension));
 }
Exemple #46
0
 public SeekableDataInputVirtualFile(SeekableDataInput file, IVirtualFile ioctlFile) : base(file, ioctlFile)
 {
 }
 private string GetPageContents(IVirtualFile page)
 {
     return ReplaceContentWithRewriteTokens(page.ReadAllText());
 }
Exemple #48
0
 public virtual string GetDictionaryPagePath(IVirtualFile file)
 {
     return(GetDictionaryPagePath(file.VirtualPath));
 }
 public virtual RazorPage AddPage(IVirtualFile file)
 {
     return IsWatchedFile(file)
         ? TrackPage(file)
         : null;
 }
Exemple #50
0
 public string textContents(IVirtualFile file) => file?.ReadAllText();
Exemple #51
0
 public IVirtualFile GetFileIfCached(string virtualPath, System.Collections.Specialized.NameValueCollection queryString, IVirtualFile original)
 {
     //Use alternate cache key if provided
     string key = original is IVirtualFileSourceCacheKey ? ((IVirtualFileSourceCacheKey)original).GetCacheKey(true) : original.VirtualPath;
     //If cached, serve it.
     CachedVirtualFile c = cache.Get(key);
     if (c != null) return c;
     //If not, let's cache it.
     if ("mem".Equals(queryString["scache"], StringComparison.OrdinalIgnoreCase)) {
         locks.TryExecute(key, 3000, delegate() {
             c = cache.Get(key);
             if (c == null) {
                 using (Stream data = original.Open()) {//Very long-running call
                     c = new CachedVirtualFile(original.VirtualPath, StreamExtensions.CopyToBytes(data, true));
                 }
                 cache.Set(key, c);//Save to cache (may trigger cleanup)
             }
         });
         return c;
     }
     return null;
 }
Exemple #52
0
 public byte[] bytesContent(IVirtualFile file) => file?.ReadAllBytes();
Exemple #53
0
 public string fileHash(IVirtualFile file) => file?.GetFileHash();
Exemple #54
0
 public AbstractVirtualFile(SeekableDataInput file)
 {
     this.file = file;
     ioctlFile = null;
 }
        public virtual RazorPage TrackPage(IVirtualFile file)
        {
            //get the base type.
            var pageBaseType = this.Config.PageBaseType;

            var transformer = new RazorViewPageTransformer(pageBaseType);

            //create a RazorPage
            var page = new RazorPage
            {
                PageHost = CreatePageHost(file, transformer),
                IsValid = false,
                File = file,
                VirtualPath = file.VirtualPath,
            };

            //add it to our pages dictionary.
            AddPage(page);

            if (Config.PrecompilePages.GetValueOrDefault())
                PrecompilePage(page);

            return page;
        }
Exemple #56
0
 public AbstractVirtualFile(SeekableDataInput file, IVirtualFile ioctlFile)
 {
     this.file      = file;
     this.ioctlFile = ioctlFile;
 }
 public RazorPage GetPage(IVirtualFile file)
 {
     return GetPage(file.VirtualPath);
 }
Exemple #58
0
 public HttpResult(IVirtualFile fileResponse, bool asAttachment)
     : this(fileResponse, MimeTypes.GetMimeType(fileResponse.Name), asAttachment)
 {
 }
 public virtual string GetDictionaryPagePath(IVirtualFile file)
 {
     return GetDictionaryPagePath(file.VirtualPath);
 }
Exemple #60
0
 public virtual long ioLseek(IVirtualFile file, long offset)
 {
     return(vfs.ioLseek(file, offset));
 }