/// <summary> /// 获取文件内容 /// </summary> /// <param name="fileType">文件类型</param> /// <param name="fileName">文件名</param> /// <returns>文件内容</returns> public string GetFileContent(Common.FileType fileType, string fileName) { string tmpText = String.Empty; try { switch (fileType) { case Common.FileType.css: fileName += ".css"; tmpText = System.IO.File.ReadAllText(Common.PathHelper.MapPath(CSSDIR + fileName)); break; case Common.FileType.js: fileName += ".js"; tmpText = System.IO.File.ReadAllText(Common.PathHelper.MapPath(JSDIR + fileName)); break; case Common.FileType.content: fileName += ".html"; tmpText = System.IO.File.ReadAllText(Common.PathHelper.MapPath(ContentTemplateDIR + fileName)); break; case Common.FileType.category: fileName += ".html"; tmpText = System.IO.File.ReadAllText(Common.PathHelper.MapPath(CategoryTemplateDIR + fileName)); break; default: tmpText = "error!该文件不能编辑!"; break; } } catch (Exception ex) { logger.Error(ex); } return(tmpText); }
//Todo:保存文件时,重新全部静态化,重新生成静态页 /// <summary> /// 将更改保存到文件 /// </summary> /// <param name="contents">文件内容</param> /// <param name="fileType">文件类型</param> /// <param name="fileName">文件名</param> /// <returns></returns> public bool SaveFile(string contents, Common.FileType fileType, string fileName) { try { switch (fileType) { case Common.FileType.css: fileName += ".css"; System.IO.File.WriteAllText(Common.PathHelper.MapPath(CSSDIR + fileName), contents); break; case Common.FileType.js: fileName += ".js"; System.IO.File.WriteAllText(Common.PathHelper.MapPath(JSDIR + fileName), contents); break; case Common.FileType.content: fileName += ".html"; System.IO.File.WriteAllText(Common.PathHelper.MapPath(ContentTemplateDIR + fileName), contents); break; case Common.FileType.category: fileName += ".html"; System.IO.File.WriteAllText(Common.PathHelper.MapPath(CategoryTemplateDIR + fileName), contents); break; default: return(false); break; } return(true); } catch (Exception ex) { logger.Error(ex); } return(false); }
private void MakeAvs(int index) { Common.TaskData tdata = Task_Data_List[index]; List <string> olst = new List <string>(); int fcount = 0; double fps; Common.Resolution res; string filemainname = Path.GetFileNameWithoutExtension(tdata.FileName); string outputpath = tdata.CData.OutputPath + "\\" + filemainname + "\\"; fps = Common.FPSList[tdata.CData.FPSIndex]; res = Common.ResolutionList[tdata.CData.ResolutionIndex]; Common.FileType ftype = Common.GetFileType(tdata.FileFullPath); if (ftype == Common.FileType.ASS) { fcount = ASSFile.GetFrameCount(tdata.FileFullPath, fps); } else if (ftype == Common.FileType.SSA) { fcount = SSAFile.GetFrameCount(tdata.FileFullPath, fps); } fcount += 100; if (tdata.CData.BVSMod) { olst.Add("LoadPlugin(\"" + _vsfiltermodpath + "\")"); olst.Add("MaskSubMod(\"" + tdata.FileFullPath + "\", " + res.X.ToString() + ", " + res.Y.ToString() + ", " + fps.ToString() + ", " + fcount.ToString() + ")"); } else { olst.Add("LoadPlugin(\"" + _vsfilterpath + "\")"); olst.Add("MaskSub(\"" + tdata.FileFullPath + "\", " + res.X.ToString() + ", " + res.Y.ToString() + ", " + fps.ToString() + ", " + fcount.ToString() + ")"); } if (tdata.CData.ResolutionIndex == 3) { olst.Add("LanczosResize(720,480)"); } else if (tdata.CData.ResolutionIndex == 4) { olst.Add("LanczosResize(720,576)"); } else { olst.Add("LanczosResize(" + res.X.ToString() + ", " + res.Y.ToString() + ")"); } if (!Directory.Exists(tdata.CData.OutputPath)) { Directory.CreateDirectory(tdata.CData.OutputPath); } string avsfile = outputpath + filemainname + ".avs"; if (!Directory.Exists(outputpath)) { Directory.CreateDirectory(outputpath); } if (File.Exists(avsfile)) { File.Delete(avsfile); } FileStream fs = File.Create(avsfile); StreamWriter sr = new StreamWriter(fs); sr.AutoFlush = true; foreach (string s in olst) { sr.WriteLine(s); } sr.Close(); fs.Close(); }