Revert "Доделаны требования и удалены ненужные файлы"

This reverts commit fe943481a9c1f4f5d0a08fbd511856b5a145ffb1.
This commit is contained in:
easynickname1 2024-05-26 21:41:55 +04:00
parent 595f6a9dbc
commit 88b25bd0d4

View File

@ -116,12 +116,11 @@ public class StorageCollection<T>
File.Delete(filename);
}
using (StreamWriter wr = new StreamWriter(filename))
{
wr.Write(_collectionKey);
StringBuilder sb = new();
sb.Append(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{
StringBuilder sb = new StringBuilder();
sb.Append(Environment.NewLine);
// Не сохраняем пустые коллекции
if (value.Value.Count == 0)
@ -147,9 +146,11 @@ public class StorageCollection<T>
sb.Append(data);
sb.Append(_separatorItems);
}
wr.Write(sb);
}
}
using FileStream fs = new(filename, FileMode.Create);
byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString());
fs.Write(info, 0, info.Length);
}
/// <summary>
@ -163,22 +164,30 @@ public class StorageCollection<T>
throw new Exception("Файл не существует");
}
using (StreamReader sr = new StreamReader(filename))
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
{
string str = sr.ReadLine();
if (str == null || str.Length == 0)
byte[] b = new byte[fs.Length];
UTF8Encoding temp = new(true);
while (fs.Read(b, 0, b.Length) > 0)
{
bufferTextFromFile += temp.GetString(b);
}
}
string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
throw new Exception("В файле нет данных");
}
if (!str.Equals(_collectionKey))
if (!strs[0].Equals(_collectionKey))
{
throw new Exception("В файле неверные данные");
}
_storages.Clear();
string data = "";
while ((data = sr.ReadLine()) != null)
foreach (string data in strs)
{
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4)
@ -208,11 +217,10 @@ public class StorageCollection<T>
throw new Exception("Коллекция переполнена", ex);
}
}
}
_storages.Add(record[0], collection);
}
}
}
}
/// <summary>
/// Создание коллекции по типу