Skip to content

Commit

Permalink
Refactored core libs
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianMorozov committed Nov 12, 2024
1 parent ddea1da commit 25d7df5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 54 deletions.
1 change: 0 additions & 1 deletion Core/TgInfrastructure/Helpers/TgLocaleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public sealed class TgLocaleHelper : ObservableObject
public string From => "from";
public string HomeResetToDefault => "Reset to default";
public string HomeSaveToXml => "Save to XML";
public string MenuAppDeprecatedStorage => "Setting the path to the deprecated storage file";
public string MenuAppEfStorage => "Setting the path to the EF Core storage file";
public string MenuAppFileSession => "Setting the path to the session file";
public string MenuAppUseProxy => "Usage proxy";
Expand Down
1 change: 0 additions & 1 deletion Core/TgStorage/Enums/TgEnumMenuAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ public enum TgEnumMenuAppSettings
Reset,
SetFileSession,
SetEfStorage,
SetDepreactedStorage,
SetUseProxy,
}
21 changes: 3 additions & 18 deletions Core/TgStorage/Helpers/TgAppSettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public TgAppSettingsHelper()

public void LoadXmlSettings(Encoding? encoding = null)
{
if (!File.Exists(TgFileUtils.FileAppXmlSettings))
return;

if (!File.Exists(TgFileUtils.FileAppXmlSettings)) return;
using StreamReader streamReader = new(TgFileUtils.FileAppXmlSettings, encoding ?? Encoding.Unicode);
string xml = streamReader.ReadToEnd();
if (!string.IsNullOrEmpty(xml))
Expand All @@ -56,24 +54,11 @@ public void LoadXmlSettings(Encoding? encoding = null)

public void DefaultXmlSettings(Encoding? encoding = null)
{
AppXml.XmlFileSession = TgFileUtils.FileSession;
AppXml.XmlEfStorage = TgFileUtils.FileEfStorage;
//AppXml.XmlFileStorage = TgFileUtils.FileDeprecatedStorage;
StoreXmlSettingsUnsafe(encoding);
AppXml.Default();
StoreXmlSettings(encoding);
}

public void StoreXmlSettings(Encoding? encoding = null)
{
//if (string.IsNullOrEmpty(AppXml.XmlFileSession) || !AppXml.IsExistsFileSession)
// AppXml.XmlFileSession = TgFileUtils.FileSession;
//if (string.IsNullOrEmpty(AppXml.XmlEfStorage) || !AppXml.IsExistsEfStorage)
// AppXml.XmlEfStorage = TgFileUtils.FileEfStorage;
//if (string.IsNullOrEmpty(AppXml.XmlDeprecatedStorage) || !AppXml.IsExistsDeprecatedStorage)
// AppXml.XmlDeprecatedStorage = TgFileUtils.FileDeprecatedStorage;
StoreXmlSettingsUnsafe(encoding);
}

public void StoreXmlSettingsUnsafe(Encoding? encoding = null)
{
var xml = TgDataFormatUtils.SerializeAsXmlDocument(AppXml, isAddEmptyNamespace: true).InnerXml;
xml = TgDataFormatUtils.GetPrettyXml(xml);
Expand Down
46 changes: 15 additions & 31 deletions Core/TgStorage/Models/TgAppXmlModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,21 @@ public sealed class TgAppXmlModel : ObservableObject, ITgCommon

[DefaultValue("")]
[XmlElement("FileSession")]
public string XmlFileSession { get; set; }
[XmlIgnore]
public bool IsExistsFileSession => File.Exists(XmlFileSession);
public string XmlFileSession { get; set; } = default!;
[DefaultValue("")]
[XmlElement("EfStorage")]
public string XmlEfStorage { get; set; }
public string XmlEfStorage { get; set; } = default!;

[XmlIgnore]
public bool IsExistsFileSession => File.Exists(XmlFileSession);
[XmlIgnore]
public bool IsExistsEfStorage => File.Exists(XmlEfStorage) && new FileInfo(XmlEfStorage).Length > 0;
//[DefaultValue("")]
//[XmlElement("FileStorage")]
//public string XmlFileStorage { get; set; }
//[XmlIgnore]
//public bool IsExistsDeprecatedStorage => File.Exists(XmlFileStorage) && new FileInfo(XmlFileStorage).Length > 0;
[XmlIgnore]
public bool IsReady => IsExistsFileSession && IsExistsEfStorage;

public TgAppXmlModel()
{
XmlFileSession = this.GetDefaultPropertyString(nameof(XmlFileSession));
XmlEfStorage = this.GetDefaultPropertyString(nameof(XmlEfStorage));
//XmlFileStorage = this.GetDefaultPropertyString(nameof(XmlFileStorage));
Default();
}

#endregion
Expand All @@ -43,23 +37,25 @@ public TgAppXmlModel()
public string ToDebugString() =>
$"{TgCommonUtils.GetIsReady(IsReady)} | {nameof(XmlFileSession)}: {XmlFileSession} | {nameof(XmlEfStorage)}: {XmlEfStorage}";

/// <summary>
/// Set path for file session.
/// </summary>
/// <param name="path"></param>
public void Default()
{
XmlFileSession = TgFileUtils.FileTgSession;
XmlEfStorage = TgFileUtils.FileEfStorage;
}

/// <summary> Set path for file session </summary>
public void SetFileSessionPath(string path)
{
XmlFileSession = !File.Exists(path) && Directory.Exists(path)
? Path.Combine(path, TgFileUtils.FileSession)
? Path.Combine(path, TgFileUtils.FileTgSession)
: path;
if (!IsExistsFileSession)
{
XmlFileSession = Path.Combine(Directory.GetCurrentDirectory(), TgFileUtils.FileSession);
XmlFileSession = Path.Combine(Directory.GetCurrentDirectory(), TgFileUtils.FileTgSession);
}
}

/// <summary> Set path for file storage </summary>
/// <param name="path"></param>
public void SetEfStoragePath(string path)
{
XmlEfStorage = !File.Exists(path) && Directory.Exists(path)
Expand All @@ -71,17 +67,5 @@ public void SetEfStoragePath(string path)
}
}

///// <summary> Set path for deprecated storage </summary>
//public void SetDeprecatedStoragePath(string path)
//{
// XmlFileStorage = !File.Exists(path) && Directory.Exists(path)
// ? Path.Combine(path, TgFileUtils.FileDeprecatedStorage)
// : path;
// if (!IsExistsDeprecatedStorage)
// {
// XmlFileStorage = Path.Combine(Directory.GetCurrentDirectory(), TgFileUtils.FileDeprecatedStorage);
// }
//}

#endregion
}
5 changes: 2 additions & 3 deletions Core/TgStorage/Utils/TgFileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public static class TgFileUtils
private static TgLocaleHelper TgLocale => TgLocaleHelper.Instance;
private static TgLogHelper TgLog => TgLogHelper.Instance;
public static string FileAppXmlSettings => $"{AppDomain.CurrentDomain.BaseDirectory}TgDownloader.xml";
public static string FileSession => "TgDownloader.session";
public static string FileTgSession => "TgDownloader.session";
public static string FileEfStorage => "TgStorage.db";
public static string FileDeprecatedStorage => "TgDownloader.db";
//public static string FileDeprecatedStorage => "TgDownloader.db";

#endregion

Expand All @@ -30,7 +30,6 @@ public static ulong GetContentRowsCountSlow(string sourceFile)
rows++;
}
streamReader.Close();
streamReader.Dispose();
return rows;
}

Expand Down

0 comments on commit 25d7df5

Please sign in to comment.