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

This commit is contained in:
easynickname1 2024-05-26 21:09:44 +04:00
parent 7f7e5253a3
commit 01275ea1dd

View File

@ -116,11 +116,12 @@ public class StorageCollection<T>
File.Delete(filename);
}
StringBuilder sb = new();
sb.Append(_collectionKey);
using (StreamWriter wr = new StreamWriter(filename))
{
wr.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{
StringBuilder sb = new StringBuilder();
sb.Append(Environment.NewLine);
// Не сохраняем пустые коллекции
if (value.Value.Count == 0)
@ -146,11 +147,9 @@ 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);
return true;
}
@ -166,31 +165,23 @@ public class StorageCollection<T>
return false;
}
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
using (StreamReader sr = new StreamReader(filename))
{
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)
string str = sr.ReadLine();
if (str == null || str.Length == 0)
{
return false;
}
if (!strs[0].Equals(_collectionKey))
if (!str.Equals(_collectionKey))
{
// Если нет такой записи, то это не те данные
return false;
}
_storages.Clear();
foreach (string data in strs)
string data = "";
while ((data = sr.ReadLine()) != null)
{
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4)
@ -221,7 +212,7 @@ public class StorageCollection<T>
_storages.Add(record[0], collection);
}
}
return true;
}