private static void copyFolder(string srcDir, string tgtDir, StringBuilder errs) { if (!Directory.Exists(tgtDir)) { Directory.CreateDirectory(tgtDir); } string s = VPLUtil.GrantFolderFullPermission(tgtDir); if (!string.IsNullOrEmpty(s)) { errs.Append(string.Format(CultureInfo.InvariantCulture, "Error granting permissions to [{0}]. {1}\r\n", tgtDir, s)); } string[] ss = Directory.GetFiles(srcDir); for (int i = 0; i < ss.Length; i++) { string tgtFile = Path.Combine(tgtDir, Path.GetFileName(ss[i])); File.Copy(ss[i], tgtFile, true); } ss = Directory.GetDirectories(srcDir); if (ss != null && ss.Length > 0) { for (int i = 0; i < ss.Length; i++) { string s0 = Path.Combine(tgtDir, Path.GetFileName(ss[i])); copyFolder(ss[i], s0, errs); } } }
public static IWebHost CreateHtmlHost(ILimnorDesignerLoader loader, Form caller) { IWebHost host = null; Encoding encode = Encoding.Unicode; string docType = null; VirtualWebDir webSite = WebHost.GetWebSite(loader.Project, caller); if (webSite != null) { installHtmlEdiotr(caller); if (!loader.Project.WebFolderGranted) { string err = VPLUtil.GrantFolderFullPermission(webSite.PhysicalDirectory); if (string.IsNullOrEmpty(err)) { loader.Project.SetWebFolderGranted(); } else { MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error granting permissions to [{0}]. {1}", webSite.PhysicalDirectory, err), "Web Editor", MessageBoxButtons.OK, MessageBoxIcon.Error); } } WebPage wpage = loader.RootObject as WebPage; bool openWebTab = true; string hf = WebHost.GetHtmlFile(loader.ComponentFilePath); //saved HTML file string editFile = Path.Combine(webSite.PhysicalDirectory, Path.GetFileName(hf)); //in WebFiles //create editFile contents if (File.Exists(hf)) { try { //set editing file to the doc type for editing (IE requirement) //for Chrome, try not to do it string line; StringBuilder sbBeforeHtml = new StringBuilder(); bool gotHtml = false; StreamReader sr = new StreamReader(hf, true); encode = sr.CurrentEncoding; while (!sr.EndOfStream) { line = sr.ReadLine(); if (gotHtml) { } else { if (!string.IsNullOrEmpty(line)) { int pos = line.IndexOf("<html", StringComparison.OrdinalIgnoreCase); if (pos >= 0) { if (pos > 0) { sbBeforeHtml.Append(line.Substring(0, pos)); } docType = sbBeforeHtml.ToString(); gotHtml = true; break; //for Chrome } else { sbBeforeHtml.Append(line); sbBeforeHtml.Append("\r\n"); } } } } sr.Close(); } catch (Exception err) { MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error copying [{0}] to [{1}]. {2}", hf, editFile, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error); openWebTab = false; } //for Chrome if (openWebTab) { try { File.Copy(hf, editFile, true); } catch (Exception err) { MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error copying from [{0}] to [{1}]. {2}.", hf, editFile, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error); openWebTab = false; } } if (openWebTab) { int p0 = hf.LastIndexOf('.'); if (p0 > 0) { string css = string.Format(CultureInfo.InvariantCulture, "{0}.css", hf.Substring(0, p0)); if (File.Exists(css)) { string tgt = Path.Combine(webSite.PhysicalDirectory, Path.GetFileName(css)); try { File.Copy(css, tgt, true); } catch (Exception err) { MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error copying from [{0}] to [{1}]. {2}.", css, tgt, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error); openWebTab = false; } } } } } else { try { StreamWriter sw = new StreamWriter(editFile); sw.Write(Resources.emptyPageEdit); sw.Close(); } catch (Exception err) { MessageBox.Show(caller, string.Format(CultureInfo.InvariantCulture, "Error creating empty html file for editing: [{0}]. {1}", editFile, err.Message), "Load HTML", MessageBoxButtons.OK, MessageBoxIcon.Error); openWebTab = false; } } if (openWebTab) { try { CopyJsLib(webSite.PhysicalDirectory); CopyJsColor(webSite.PhysicalDirectory); } catch (Exception err) { MathNode.Log(err, "Error preparing html file for editing: [{0}]", editFile); openWebTab = false; } bool bErr; string rootPath = IisUtility.FindLocalRootWebPath(caller, out bErr); if (string.IsNullOrEmpty(rootPath)) { MathNode.Log("Cannot get physical path for web root."); } else { string libjs = Path.Combine(rootPath, "libjs"); if (!Directory.Exists(libjs)) { try { Directory.CreateDirectory(libjs); } catch (Exception err2) { MathNode.Log(err2, "Error creating web folder: [{0}]", libjs); } } string jsfile = Path.Combine(libjs, "htmlEditorClient.js"); if (!File.Exists(jsfile)) { try { StreamWriter sw = new StreamWriter(jsfile, false, Encoding.ASCII); sw.Write(Resources.htmleditorClient); sw.Close(); } catch (Exception err3) { MathNode.Log(err3, "Error creating file: [{0}]", jsfile); } } } } if (openWebTab) { #if USECEF if (IntPtr.Size == 4) { WebHostX86 hx86 = new WebHostX86(); host = hx86; hx86.LoadWebHost(loader.Project.ProjectFolder, webSite.PhysicalDirectory, webSite.WebName, editFile, encode, docType, wpage); } else { } //host.SetHtmlFile(editFile, webSite.WebName); #else host = new WebHost(loader.Project.ProjectFolder, webSite.PhysicalDirectory, webSite.WebName, editFile, encode, docType, wpage); host.SetEncode(encode); if (!string.IsNullOrEmpty(docType)) { host.SetDocType(docType); } #endif wpage.RefreshWebDisplay(); } } return(host); }