public List <Stream> GetStreams(string filename) { string dirname = Path.GetDirectoryName(filename); string fname = Path.GetFileNameWithoutExtension(filename); if (string.IsNullOrEmpty(dirname) || string.IsNullOrEmpty(fname)) { return(null); } string basename = Path.Combine(dirname, fname); if (!File.Exists(basename + ".idx")) { return(null); } string bing = File.ReadAllText(basename + ".idx"); if (!bing.Contains("VobSub index file")) { return(null); } Regex ex = new Regex("\\nid: ([A-Za-z]{2})"); MatchCollection ma = ex.Matches(bing); int x = 0; List <Stream> ss = new List <Stream>(); foreach (Match m in ma) { if (m.Success) { string language = null; string val = m.Groups[1].Value.ToLower(); if (SubtitleHelper.Iso639_3_TO_Iso639_1.ContainsKey(val)) { language = SubtitleHelper.Iso639_3_TO_Iso639_1[val]; } else if (SubtitleHelper.Iso639_1_TO_Languages.ContainsKey(val)) { language = val; } else if (SubtitleHelper.Languages_TO_ISO639_1_Lower.ContainsKey(val)) { language = SubtitleHelper.Languages_TO_ISO639_1_Lower[val]; } if (language != null) { Stream s = new Stream(); s.Format = "vobsub"; s.StreamType = "3"; s.SubIndex = x.ToString(); s.File = basename + ".idx"; s.LanguageCode = SubtitleHelper.Iso639_1_TO_Iso639_3[language]; s.Language = SubtitleHelper.Iso639_1_TO_Languages[language]; ss.Add(s); } } x++; } return(ss); }
public string ReadContents() { MsgReader.Reader reader = new MsgReader.Reader(); string tempMsgFilePath = GetTempLocalFile(); DirectoryInfo tempDirectory = new DirectoryInfo(Path.GetTempPath()); DirectoryInfo tempOutputDirectory = tempDirectory.CreateSubdirectory(Guid.NewGuid().ToString()); reader.ExtractToFolder(tempMsgFilePath, tempOutputDirectory.FullName); StringBuilder builder = new StringBuilder(); Regex regex = new Regex(_HtmlRegExPattern); foreach (FileInfo file in tempOutputDirectory.EnumerateFiles()) { if (file.Extension.ToUpper() == ".HTM") { string fileContent = File.ReadAllText(file.FullName); fileContent = regex.Replace(fileContent, string.Empty); builder.Append(fileContent); } } try { File.Delete(tempMsgFilePath); tempOutputDirectory.Delete(true); } catch (Exception) { } return(builder.ToString()); }
public frmMain() { InitializeComponent(); #region Apply setting if (File.Exists("setting.json")) { appSetting = JsonConvert.DeserializeObject <AppSetting>(File.ReadAllText("setting.json")); txtCoursePath.Text = Directory.Exists(appSetting.CoursePath) ? appSetting.CoursePath : ""; txtDBPath.Text = File.Exists(appSetting.DatabasePath) ? appSetting.DatabasePath : ""; txtOutputPath.Text = Directory.Exists(appSetting.OutputPath) ? appSetting.OutputPath : ""; chkDecrypt.Checked = appSetting.Decrypt; chkCreateSub.Checked = appSetting.CreateSub; chkDelete.Checked = appSetting.DeleteAfterDecrypt; chkShowErrOnly.Checked = appSetting.ShowErrorOnly; chkCopyImage.Checked = appSetting.CopyImage; chkStartClipIndexAt1.Checked = appSetting.ClipIndexAtOne; chkStartModuleIndexAt1.Checked = appSetting.ModuleIndexAtOne; } else { appSetting = new AppSetting(); string pluralsightPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Pluralsight"; if (Directory.Exists(pluralsightPath)) { txtCoursePath.Text = Directory.Exists(pluralsightPath + @"\courses") ? pluralsightPath + @"\courses" : ""; txtDBPath.Text = File.Exists(pluralsightPath + @"\pluralsight.db") ? pluralsightPath + @"\pluralsight.db" : ""; appSetting.CoursePath = txtCoursePath.Text; appSetting.DatabasePath = txtDBPath.Text; } } #endregion imgList.ImageSize = new Size(170, 100); imgList.ColorDepth = ColorDepth.Depth32Bit; lsvCourse.LargeImageList = imgList; bgwDecrypt.DoWork += BgwDecrypt_DoWork; bgwDecrypt.ProgressChanged += BgwDecrypt_ProgressChanged; bgwDecrypt.RunWorkerCompleted += BgwDecrypt_RunWorkerCompleted; bgwGetCourse.DoWork += BgwGetCourse_DoWork; bgwGetCourse.ProgressChanged += BgwGetCourse_ProgressChanged; bgwGetCourse.RunWorkerCompleted += BgwGetCourse_RunWorkerCompleted; tslToolVersion.Text = $"Tool version: {System.Windows.Forms.Application.ProductVersion}"; if (File.Exists(txtDBPath.Text.Replace("pluralsight.db", "pluralsight.exe"))) { tslToolVersion.BorderSides = (ToolStripStatusLabelBorderSides.Left | ToolStripStatusLabelBorderSides.Right); FileVersionInfo fvInfo = FileVersionInfo.GetVersionInfo(txtDBPath.Text.Replace("pluralsight.db", "pluralsight.exe")); tslPOPVersion.Text = $"Pluralsight Offline Player Version: {fvInfo.FileVersion}"; } }
/// <summary> /// Loads the CSV file. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns></returns> public static CsvFile LoadCsvFile(string fileName) { Contract.Requires(fileName != null); var serial = File.ReadAllText(fileName); using (TextReader reader = new StringReader(serial)) { return((CsvFile)m_SerializerCurrentCsvFile.Value.Deserialize(reader)); } }
public void TestAppendAllTextEncoding() { var filename = Util.CreateNewFileUnicode(longPathDirectory); try { File.AppendAllText(filename, "test", Encoding.Unicode); Assert.AreEqual("beginning of file" + Environment.NewLine + "test", File.ReadAllText(filename, Encoding.Unicode)); } finally { File.Delete(filename); } }
public void TestWriteAllLinesWithEncoding() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file26.ext").ToString(); File.WriteAllLines(tempLongPathFilename, new string[] { "file26" }, Encoding.Unicode); try { Assert.AreEqual("file26" + Environment.NewLine, File.ReadAllText(tempLongPathFilename, Encoding.Unicode)); } finally { File.Delete(tempLongPathFilename); } }
public void TestAppendAllLines() { var filename = Util.CreateNewFile(longPathDirectory); try { File.AppendAllLines(filename, new[] { "test1", "test2" }); Assert.AreEqual("beginning of file" + Environment.NewLine + "test1" + Environment.NewLine + "test2" + Environment.NewLine, File.ReadAllText(filename)); } finally { File.Delete(filename); } }
public void TestCopyWithOverwrite() { var destLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename (Copy).ext").ToString(); File.Copy(longPathFilename, destLongPathFilename); try { Assert.IsTrue(File.Exists(destLongPathFilename)); File.Copy(longPathFilename, destLongPathFilename, true); Assert.AreEqual(File.ReadAllText(longPathFilename), File.ReadAllText(destLongPathFilename)); } finally { File.Delete(destLongPathFilename); } }
public void TestReadAllTextEncoding() { var filename = new StringBuilder(longPathDirectory).Append(@"\").Append("file3.ext").ToString(); const string fileText = "test"; using (File.CreateText(filename)) { } try { File.WriteAllText(filename, fileText, Encoding.Unicode); Assert.AreEqual(fileText, File.ReadAllText(filename, Encoding.Unicode)); } finally { File.Delete(filename); } }
public void TestCopyToWithOverwrite() { var fi = new FileInfo(filePath); var destLongPathFilename = new StringBuilder(uncDirectory).Append(@"\").Append("filename (Copy).ext").ToString(); fi.CopyTo(destLongPathFilename); try { Assert.IsTrue(File.Exists(destLongPathFilename)); fi.CopyTo(destLongPathFilename, true); Assert.AreEqual(File.ReadAllText(filePath), File.ReadAllText(destLongPathFilename)); } finally { File.Delete(destLongPathFilename); } }
public void TestReadAllTextWithEncoding() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file26.ext").ToString(); var fi = new FileInfo(tempLongPathFilename); try { using (var streamWriter = File.CreateText(tempLongPathFilename, Encoding.Unicode)) { streamWriter.WriteLine("file26"); } Assert.AreEqual("file26" + Environment.NewLine, File.ReadAllText(fi.FullName, Encoding.Unicode)); } finally { File.Delete(tempLongPathFilename); } }
public static bool VerifyContentsOfNewFile(string path) { string contents = File.ReadAllText(path); return("beginning of file" + Environment.NewLine == contents); }
public frmMain() { InitializeComponent(); #region Apply setting appSetting = File.Exists("setting.json") ? JsonConvert.DeserializeObject <AppSetting>(File.ReadAllText("setting.json")) : new AppSetting(); if (string.IsNullOrEmpty(appSetting.CoursePath)) { appSetting.CoursePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Pluralsight"; if (!Directory.Exists(appSetting.CoursePath)) { appSetting.CoursePath = string.Empty; } txtCoursePath.Text = Directory.Exists(appSetting.CoursePath) ? appSetting.CoursePath + @"\courses" : ""; txtDBPath.Text = Directory.Exists(appSetting.CoursePath) ? appSetting.CoursePath + @"\pluralsight.db" : ""; txtOutputPath.Text = Directory.Exists(appSetting.OutputPath) ? appSetting.OutputPath : ""; } else { appSetting.CoursePath = Directory.Exists(appSetting.CoursePath) ? appSetting.CoursePath : ""; txtCoursePath.Text = Directory.Exists(appSetting.CoursePath) ? appSetting.CoursePath : ""; txtDBPath.Text = File.Exists(appSetting.DatabasePath) ? appSetting.DatabasePath : ""; txtOutputPath.Text = Directory.Exists(appSetting.OutputPath) ? appSetting.OutputPath : ""; } chkDecrypt.Checked = appSetting.Decrypt; chkCreateSub.Checked = appSetting.CreateSub; chkDelete.Checked = appSetting.DeleteAfterDecrypt; chkShowErrOnly.Checked = appSetting.ShowErrorOnly; chkCopyImage.Checked = appSetting.CopyImage; chkStartClipIndexAt1.Checked = appSetting.ClipIndexAtOne; chkStartModuleIndexAt1.Checked = appSetting.ModuleIndexAtOne; #endregion imgList.ImageSize = new Size(170, 100); imgList.ColorDepth = ColorDepth.Depth32Bit; lsvCourse.LargeImageList = imgList; bgwDecrypt.DoWork += BgwDecrypt_DoWork; bgwDecrypt.ProgressChanged += BgwDecrypt_ProgressChanged; bgwDecrypt.RunWorkerCompleted += BgwDecrypt_RunWorkerCompleted; bgwGetCourse.DoWork += BgwGetCourse_DoWork; bgwGetCourse.ProgressChanged += BgwGetCourse_ProgressChanged; bgwGetCourse.RunWorkerCompleted += BgwGetCourse_RunWorkerCompleted; }
public static Boolean VerifyContentsOfNewFile(String path) { var contents = File.ReadAllText(path); return("beginning of file" + Environment.NewLine == contents); }
public static string ReadAllText(string path, Encoding encoding) { return(File.ReadAllText(path, encoding)); }
public static string ReadAllText(string path) { return(File.ReadAllText(path)); }
public void TestOpenAppend() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("file26.ext").ToString(); var fi = new FileInfo(tempLongPathFilename); using (var streamWriter = fi.CreateText()) { streamWriter.WriteLine("file26"); } try { using (var fileStream = fi.Open(System.IO.FileMode.Append)) { Assert.IsNotNull(fileStream); using (var streamWriter = new System.IO.StreamWriter(fileStream)) { streamWriter.WriteLine("eof"); } } Assert.AreEqual("file26" + Environment.NewLine + "eof" + Environment.NewLine, File.ReadAllText(fi.FullName)); } finally { File.Delete(tempLongPathFilename); } }
public void TestReadAllText() { Assert.AreEqual("test" + Environment.NewLine, File.ReadAllText(longPathFilename)); }
public void TestReadAllTextNullPath() { File.ReadAllText(null); }
public void TestReadAllTextNullPath() { Assert.Throws <ArgumentNullException>(() => File.ReadAllText(null)); }