/// <summary> /// Recherche un élément dans la TBL /// </summary> /// <param name="dte">Objet DTE a rechercher dans la TBL</param> /// <returns>Retourne la position ou ce trouve cette élément dans le tableau</returns> public int Find(DTE dte) => _DTEList.BinarySearch(dte);
/// <summary> /// Ajouter un element a la collection /// </summary> /// <param name="dte">objet DTE a ajouter fans la collection</param> public void Add(DTE dte) => _DTEList.Add(dte);
/// <summary> /// Effacer un element de la collection a partir d'un objet DTE /// </summary> /// <param name="dte"></param> public void Remove(DTE dte) => _DTEList.Remove(dte);
/// <summary> /// Chargé le fichier dans l'objet /// </summary> /// <returns>Retoune vrai si le fichier est bien charger</returns> private bool Load() { //Vide la collection _DTEList.Clear(); //ouverture du fichier if (!File.Exists(_FileName)) { FileStream fs = File.Create(_FileName); fs.Close(); } StreamReader TBLFile; try { TBLFile = new StreamReader(_FileName, Encoding.ASCII); } catch { return(false); } if (TBLFile.BaseStream.CanRead) { //lecture du fichier jusqua la fin et séparation par ligne char[] sepEndLine = { '\n' }; //Fin de ligne char[] sepEqual = { '=' }; //Fin de ligne //build strings line StringBuilder textFromFile = new StringBuilder(TBLFile.ReadToEnd()); textFromFile.Insert(textFromFile.Length, '\r'); textFromFile.Insert(textFromFile.Length, '\n'); string[] lines = textFromFile.ToString().Split(sepEndLine); //remplir la collection de DTE : this._DTE foreach (string line in lines) { string[] info = line.Split(sepEqual); //ajout a la collection (ne prend pas encore en charge le Japonais) DTE dte = new DTE(); try { switch (info[0].Length) { case 2: if (info[1].Length == 2) { dte = new DTE(info[0], info[1].Substring(0, info[1].Length - 1), DTEType.ASCII); } else { dte = new DTE(info[0], info[1].Substring(0, info[1].Length - 1), DTEType.DualTitleEncoding); } break; case 4: // >2 dte = new DTE(info[0], info[1].Substring(0, info[1].Length - 1), DTEType.MultipleTitleEncoding); break; default: continue; } } catch (IndexOutOfRangeException) { switch (info[0].Substring(0, 1)) { case @"/": dte = new DTE(info[0].Substring(0, info[0].Length - 1), "", DTEType.EndBlock); break; case @"*": dte = new DTE(info[0].Substring(0, info[0].Length - 1), "", DTEType.EndLine); break; //case @"\": default: continue; } } catch (ArgumentOutOfRangeException) { //Du a une entre qui a 2 = de suite... EX: XX== dte = new DTE(info[0], "=", DTEType.DualTitleEncoding); } _DTEList.Add(dte); } //Load bookmark BookMarks.Clear(); BookMark fav = null; string[] lineSplited; foreach (string line in lines) { try { if (line.Substring(0, 1) == "(") { fav = new BookMark(); lineSplited = line.Split(new char[] { ')' }); fav.Description = lineSplited[1].Substring(0, lineSplited[1].Length - 1); lineSplited = line.Split(new char[] { 'h' }); fav.BytePositionInFile = ByteConverters.HexLiteralToLong(lineSplited[0].Substring(1, lineSplited[0].Length - 1)).position; fav.Marker = ScrollMarker.TBLBookmark; BookMarks.Add(fav); } } catch { } //Nothing to add if error } TBLFile.Close(); return(true); } else { return(false); } }