+ bool isImage = false;
+ bool isPlain = isHTTP ? false : true;
+
+ // Handle known types
+ if(isHTTP && f.contentType)
+ {
+ if(strstr(f.contentType, "image/") == f.contentType)
+ isImage = true;
+ else if(strstr(f.contentType, "text/") == f.contentType && strnicmp(f.contentType + 5, "html", 4))
+ isPlain = true;
+ }
+ else
+ {
+ const String imageExt[] = { "jpg", "jpeg", "bmp", "pcx", "png", "gif" };
+ const String htmlExt[] = { "html", "htm", "php" };
+ const String textExt[] = { "c", "h", "ec", "eh", "epj", "cpp", "cxx", "cc", "hpp", "hxx", "hh", "m", "java", "cs", "py", "Makefile", "mk", "cf" };
+ char ext[MAX_EXTENSION];
+ int i;
+ GetExtension(fileName, ext);
+ for(i = 0; i < sizeof(imageExt) / sizeof(imageExt[0]); i++)
+ if(!strcmpi(ext, imageExt[i]))
+ {
+ isImage = true;
+ break;
+ }
+
+ for(i = 0; i < sizeof(htmlExt) / sizeof(htmlExt[0]); i++)
+ if(!strcmpi(ext, htmlExt[i]))
+ {
+ isPlain = false;
+ break;
+ }
+
+ for(i = 0; i < sizeof(textExt) / sizeof(textExt[0]); i++)
+ if(!strcmpi(ext, textExt[i]))
+ {
+ isPlain = true;
+ break;
+ }
+ }
+
+ if(isImage)
+ {
+ Block subBlock;
+ html.body = HTMLFile::AddBlock(html.block, BODY);
+
+ subBlock = HTMLFile::AddBlock(html.body, IMAGE);
+ subBlock.valign = bottom;
+ subBlock.halign = middle;
+ subBlock.src = CopyString(fileName);
+ html.defaultFont.type = FONT;
+ html.defaultFont.face = CopyString("Times New Roman");
+ }
+ else if(isPlain)
+ {
+ uint size;
+ TempFile tmp { };
+ Block subBlock;
+ char * text;
+ int len;
+ String cd = eClass_IsDerived(f._class, class(HTTPFile)) ? f.contentDisposition : null;
+
+ String tmpPath = PrintString("File://", (uintptr)tmp);
+ f.CopyTo(tmpPath);
+ size = tmp.GetSize();
+ tmp.Seek(0, start);
+
+ html.defaultFont.type = FONT;
+ html.defaultFont.face = CopyString("Courier New");
+
+ if(cd)
+ {
+ char fn[MAX_LOCATION];
+ while(GetKeyWordEx(&cd, fn, sizeof(fn), true, false))
+ {
+ if(!strcmp(fn, "filename") && GetKeyWordEx(&cd, fn, sizeof(fn), true, true))
+ {
+ html.titleBlock = HTMLFile::AddBlock(html.block, TITLE);
+ subBlock = HTMLFile::AddBlock(html.titleBlock, TEXT);
+ subBlock.text = CopyString(fn);
+ subBlock.textLen = strlen(fn);
+ }
+ }
+ }
+
+ html.body = HTMLFile::AddBlock(html.block, BODY);
+ html.block = html.body;
+
+ text = new char[size + 1];
+ len = tmp.Read(text, 1, size);
+ text[len] = 0;
+
+ {
+ int c;
+ char ch;
+ int start = 0;
+ Block textBlock = HTMLFile::AddBlock(html.block, TEXT);
+
+ for(c = 0; ; c++)
+ {
+ ch = text[c];
+ if(ch == '\n' || ch == '\r' || !ch)
+ {
+ int len = c - start;
+ textBlock.text = renew textBlock.text char[textBlock.textLen + 1 + len];
+ memmove(textBlock.text + len, textBlock.text, textBlock.textLen + 1);
+ memcpy(textBlock.text, text + start, len);
+ textBlock.textLen += len;
+ if(!ch) break;
+ {
+ Block block { type = BR, parent = textBlock.parent };
+ Block newBlock { type = TEXT, parent = textBlock.parent };
+
+ textBlock.parent.subBlocks.Insert(textBlock, block);
+ textBlock.parent.subBlocks.Insert(block, newBlock);
+
+ newBlock.textLen = 0;
+ newBlock.text = new char[1];
+ newBlock.text[0] = 0;
+
+ textBlock = newBlock;
+ }
+ if(ch == '\r' && text[c+1] == '\n') c++;
+ start = c + 1;
+ }
+ }
+
+ html.block = html.block.parent;
+ delete text;
+ }
+ delete tmp;
+ delete tmpPath;
+
+ }
+ else
+ {
+ html.Parse(f);
+ if(html.baseHRef)
+ {
+ delete this.location;
+ this.location = CopyString(html.baseHRef);
+ }
+ }