public void Add(string internalFileName, int position, int length) { if (isDisposed) { throw new InvalidOperationException(); } headerLookup.Add(internalFileName, new MyArchiveFileHeaderElement(position, length)); HeaderOrder.Add(position, internalFileName); using (MemoryStream tempStream = new MemoryStream(TEMP_STREAM_BUFFER)) { using (BinaryWriter writer = new BinaryWriter(tempStream)) { writer.Write(internalFileName.Length); foreach (char c in internalFileName) { writer.Write(c); } writer.Write(position); writer.Write(length); writer.Flush(); var buffer = tempStream.ToArray(); RawHeader.Write(buffer, 0, buffer.Length); } } }
//public int CompressedHeaderLength { get; set; } public void Dispose() { if (isDisposed) { return; } headerLookup.Clear(); HeaderOrder.Clear(); RawHeader.Close(); RawHeader.Dispose(); isDisposed = true; }
public int Compare(object x, object y) { HeaderOrder ho = _sorter.ActiveHead; if (ho == null) { return(0); } if (ho.Comparison == null) { _sorter.SearchHeaderComparer(_sorter.ActiveHead); } int c = 0; int subIndex = ho.SubItemIndex; try { c = ho.Comparison( ((ListViewItem)x).SubItems[subIndex].Text, ((ListViewItem)y).SubItems[subIndex].Text ); if (_sorter.SortOrder == SortOrder.Descending) { c *= -1; } return(c); } catch { } return(0); }
protected void SearchHeaderComparer(HeaderOrder ho) { Random r = new Random(); IEnumerable <ListViewItem> items = Items.Cast <ListViewItem>(); List <string> list = items.Select(i => i.SubItems[ho.SubItemIndex].Text).Where(s => !String.IsNullOrEmpty(s)).OrderBy(i => r.Next(-1, 1)).ToList(); list = list.GetRange( 0, (list.Count >= 10 ? 10 : list.Count) ); long tryObjLong; double tryObjDouble; DateTime tryObjDate; Dictionary <Comparison <string>, int> dict = new Dictionary <Comparison <string>, int>(); foreach (string str in list) { Comparison <string> func = null; if (Double.TryParse(str, out tryObjDouble)) { func = ho.CompareDouble; } else if (Int64.TryParse(str, out tryObjLong)) { func = ho.CompareLong; } else if (DateTime.TryParse(str, out tryObjDate)) { func = ho.CompareDate; } else { string[] strs = str.Split(" ".ToCharArray()); if (strs.Length > 1 && Double.TryParse(strs[0], out tryObjDouble)) { func = ho.CompareSubString; } else { func = ho.CompareString; } } if (func != null) { if (!dict.ContainsKey(func)) { dict[func] = 0; } dict[func] += 1; } } if (dict.Count == 1) { ho.Comparison = dict.Keys.First(); } else { ho.Comparison = ho.CompareString; } }