Skip to content

Commit

Permalink
Database and About windows
Browse files Browse the repository at this point in the history
  • Loading branch information
libgenapps committed Mar 15, 2018
1 parent 2a85bad commit ce05e62
Show file tree
Hide file tree
Showing 35 changed files with 2,660 additions and 70 deletions.
2 changes: 2 additions & 0 deletions LibgenDesktop.Setup/AppFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ static AppFiles()
X64.Add(new AppFile(@"x64\SQLite.Interop.dll", "SQLite.Interop.dll"));
AddFile(@"Languages\English.lng");
AddFile(@"Languages\Russian.lng");
AddFile(@"Languages\Romanian.lng");
AddFile(@"Languages\Ukrainian.lng");
AddFile(@"Mirrors\mirrors.config");
AddFile(@"Mirrors\libgen_io_nonfiction.xslt");
AddFile(@"Mirrors\libgen_io_fiction.xslt");
Expand Down
11 changes: 8 additions & 3 deletions LibgenDesktop/Common/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
namespace LibgenDesktop.Common
using System;

namespace LibgenDesktop.Common
{
internal static class Constants
{
public const string CURRENT_VERSION = "1.0";
public const string CURRENT_GITHUB_RELEASE_NAME = "v1.0 beta 1";
public const string CURRENT_DATABASE_VERSION = "0.7";
public const string CURRENT_GITHUB_RELEASE_NAME = "1.0";
public static readonly DateTime CURRENT_GITHUB_RELEASE_DATE = new DateTime(2018, 3, 15);
public const string CURRENT_DATABASE_VERSION = "1.0";

public const string APP_SETTINGS_FILE_NAME = "libgen.config";
public const string MIRRORS_DIRECTORY_NAME = "Mirrors";
Expand Down Expand Up @@ -60,6 +63,8 @@ internal static class Constants
public const int SYNCHRONIZATION_WINDOW_MIN_WIDTH = 530;
public const int SYNCHRONIZATION_WINDOW_MIN_HEIGHT = 400;
public const int APPLICATION_UPDATE_WINDOW_WIDTH = 700;
public const int DATABASE_WINDOW_WIDTH = 500;
public const int ABOUT_WINDOW_WIDTH = 670;
public const int MESSAGE_BOX_WINDOW_WIDTH = 500;

public const string DEFAULT_DATABASE_FILE_NAME = "libgen.db";
Expand Down
2 changes: 1 addition & 1 deletion LibgenDesktop/Common/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static Environment()
}
}
string logFileName = $"{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.log";
LogFilePath = Path.Combine(AppDataDirectory, logFileName);
LogFilePath = Path.Combine(AppDataDirectory, "Logs", logFileName);
AppSettingsFilePath = Path.Combine(AppDataDirectory, APP_SETTINGS_FILE_NAME);
MirrorsDirectoryPath = Path.Combine(AppBinariesDirectory, MIRRORS_DIRECTORY_NAME);
LanguagesDirectoryPath = Path.Combine(AppBinariesDirectory, LANGUAGES_DIRECTORY_NAME);
Expand Down
6 changes: 5 additions & 1 deletion LibgenDesktop/Infrastructure/RegisteredWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ internal enum WindowKey
CREATE_DATABASE_WINDOW,
SETTINGS_WINDOW,
SYNCHRONIZATION_WINDOW,
APPLICATION_UPDATE_WINDOW
APPLICATION_UPDATE_WINDOW,
DATABASE_WINDOW,
ABOUT_WINDOW
}

internal class RegisteredWindow
Expand Down Expand Up @@ -48,6 +50,8 @@ static RegisteredWindows()
RegisterWindow(WindowKey.SETTINGS_WINDOW, typeof(SettingsWindow), typeof(SettingsWindowViewModel));
RegisterWindow(WindowKey.SYNCHRONIZATION_WINDOW, typeof(SynchronizationWindow), typeof(SynchronizationWindowViewModel));
RegisterWindow(WindowKey.APPLICATION_UPDATE_WINDOW, typeof(ApplicationUpdateWindow), typeof(ApplicationUpdateWindowViewModel));
RegisterWindow(WindowKey.DATABASE_WINDOW, typeof(DatabaseWindow), typeof(DatabaseWindowViewModel));
RegisterWindow(WindowKey.ABOUT_WINDOW, typeof(AboutWindow), typeof(AboutWindowViewModel));
MessageBox = new MessageBox();
}

Expand Down
37 changes: 37 additions & 0 deletions LibgenDesktop/LibgenDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
<Compile Include="Infrastructure\WindowContext.cs" />
<Compile Include="Infrastructure\WindowManager.cs" />
<Compile Include="Common\Logger.cs" />
<Compile Include="Models\Database\DatabaseStats.cs" />
<Compile Include="Models\Database\Migration.cs" />
<Compile Include="Models\Database\SearchQueryParser.cs" />
<Compile Include="Models\Download\Downloader.cs" />
<Compile Include="Models\Download\DownloadItem.cs" />
Expand Down Expand Up @@ -167,7 +169,9 @@
<Compile Include="Models\Localization\Language.cs" />
<Compile Include="Models\Localization\Localizators\ApplicationUpdateLocalizator.cs" />
<Compile Include="Models\Localization\Localizators\CommonDetailsTabLocalizator.cs" />
<Compile Include="Models\Localization\Localizators\AboutWindowLocalizator.cs" />
<Compile Include="Models\Localization\Localizators\DatabaseWindowLocalizator.cs" />
<Compile Include="Models\Localization\Localizators\CreateDatabaseWindowLocalizator.cs" />
<Compile Include="Models\Localization\Localizators\DetailsTabLocalizator.cs" />
<Compile Include="Models\Localization\Localizators\DownloadManagerLocalizator.cs" />
<Compile Include="Models\Localization\Localizators\ErrorWindowLocalizator.cs" />
Expand Down Expand Up @@ -232,6 +236,8 @@
<Compile Include="ViewModels\SearchResultItems\NonFictionSearchResultItemViewModel.cs" />
<Compile Include="ViewModels\Windows\ApplicationUpdateWindowViewModel.cs" />
<Compile Include="ViewModels\Tabs\DetailsTabViewModel.cs" />
<Compile Include="ViewModels\Windows\AboutWindowViewModel.cs" />
<Compile Include="ViewModels\Windows\DatabaseWindowViewModel.cs" />
<Compile Include="ViewModels\Windows\DetailsWindowViewModel.cs" />
<Compile Include="ViewModels\EventArguments\OpenFictionDetailsEventArgs.cs" />
<Compile Include="ViewModels\EventArguments\OpenNonFictionDetailsEventArgs.cs" />
Expand Down Expand Up @@ -261,6 +267,7 @@
<Compile Include="ViewModels\Tabs\SearchTabViewModel.cs" />
<Compile Include="ViewModels\Windows\SettingsWindowViewModel.cs" />
<Compile Include="ViewModels\Tabs\TabViewModel.cs" />
<Compile Include="Views\Utils\IconExtension.cs" />
<Compile Include="Views\Windows\ApplicationUpdateWindow.xaml.cs">
<DependentUpon>ApplicationUpdateWindow.xaml</DependentUpon>
</Compile>
Expand All @@ -282,6 +289,12 @@
<DependentUpon>PressedToggleButton.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Controls\TabControl.cs" />
<Compile Include="Views\Windows\AboutWindow.xaml.cs">
<DependentUpon>AboutWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Windows\DatabaseWindow.xaml.cs">
<DependentUpon>DatabaseWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Windows\MessageBoxWindow.xaml.cs">
<DependentUpon>MessageBoxWindow.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -356,6 +369,14 @@
<Compile Include="Views\Utils\EventListenerExtensions.cs" />
<Compile Include="Views\Utils\GridLengthConverter.cs" />
<Compile Include="Views\Utils\PasswordBoxExtensions.cs" />
<Page Include="Views\Styles\AboutWindowStyles.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Styles\DatabaseWindowStyles.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Windows\ApplicationUpdateWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand All @@ -380,6 +401,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Windows\AboutWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Windows\DatabaseWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Windows\MessageBoxWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -661,6 +690,14 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>Languages\English.lng</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Resources\Languages\Romanian.lng">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>Languages\Romanian.lng</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="Resources\Languages\Ukrainian.lng">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>Languages\Ukrainian.lng</TargetPath>
</ContentWithTargetPath>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
14 changes: 14 additions & 0 deletions LibgenDesktop/Models/Database/DatabaseStats.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace LibgenDesktop.Models.Database
{
internal class DatabaseStats
{
public int NonFictionBookCount;
public DateTime? NonFictionLastUpdate;
public int FictionBookCount;
public DateTime? FictionLastUpdate;
public int SciMagArticleCount;
public DateTime? SciMagLastUpdate;
}
}
72 changes: 54 additions & 18 deletions LibgenDesktop/Models/Database/LocalDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,15 @@ public NonFictionBook GetNonFictionBookById(int id)
command.Parameters.AddWithValue("@Id", id);
using (SQLiteDataReader dataReader = command.ExecuteReader())
{
dataReader.Read();
NonFictionBook book = ReadNonFictionBook(dataReader);
return book;
if (dataReader.Read())
{
NonFictionBook book = ReadNonFictionBook(dataReader);
return book;
}
else
{
return null;
}
}
}
}
Expand All @@ -180,9 +186,15 @@ public NonFictionBook GetLastModifiedNonFictionBook()
command.CommandText = SqlScripts.GET_LAST_MODIFIED_NON_FICTION;
using (SQLiteDataReader dataReader = command.ExecuteReader())
{
dataReader.Read();
NonFictionBook book = ReadNonFictionBook(dataReader);
return book;
if (dataReader.Read())
{
NonFictionBook book = ReadNonFictionBook(dataReader);
return book;
}
else
{
return null;
}
}
}
}
Expand Down Expand Up @@ -513,9 +525,15 @@ public FictionBook GetFictionBookById(int id)
command.Parameters.AddWithValue("@Id", id);
using (SQLiteDataReader dataReader = command.ExecuteReader())
{
dataReader.Read();
FictionBook book = ReadFictionBook(dataReader);
return book;
if (dataReader.Read())
{
FictionBook book = ReadFictionBook(dataReader);
return book;
}
else
{
return null;
}
}
}
}
Expand All @@ -532,9 +550,15 @@ public FictionBook GetLastModifiedFictionBook()
command.CommandText = SqlScripts.GET_LAST_MODIFIED_FICTION;
using (SQLiteDataReader dataReader = command.ExecuteReader())
{
dataReader.Read();
FictionBook book = ReadFictionBook(dataReader);
return book;
if (dataReader.Read())
{
FictionBook book = ReadFictionBook(dataReader);
return book;
}
else
{
return null;
}
}
}
}
Expand Down Expand Up @@ -994,9 +1018,15 @@ public SciMagArticle GetSciMagArticleById(int id)
command.Parameters.AddWithValue("@Id", id);
using (SQLiteDataReader dataReader = command.ExecuteReader())
{
dataReader.Read();
SciMagArticle article = ReadSciMagArticle(dataReader);
return article;
if (dataReader.Read())
{
SciMagArticle article = ReadSciMagArticle(dataReader);
return article;
}
else
{
return null;
}
}
}
}
Expand All @@ -1013,9 +1043,15 @@ public SciMagArticle GetLastAddedSciMagArticle()
command.CommandText = SqlScripts.GET_LAST_ADDED_SCIMAG;
using (SQLiteDataReader dataReader = command.ExecuteReader())
{
dataReader.Read();
SciMagArticle article = ReadSciMagArticle(dataReader);
return article;
if (dataReader.Read())
{
SciMagArticle article = ReadSciMagArticle(dataReader);
return article;
}
else
{
return null;
}
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions LibgenDesktop/Models/Database/Migration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using LibgenDesktop.Common;
using LibgenDesktop.Models.Entities;

namespace LibgenDesktop.Models.Database
{
internal static class Migration
{
public static bool Migrate(LocalDatabase localDatabase, DatabaseMetadata databaseMetadata)
{
switch (databaseMetadata.Version)
{
case "0.7":
return MigrateFrom_0_7(localDatabase, databaseMetadata);
case Constants.CURRENT_DATABASE_VERSION:
return true;
default:
return false;
}
}

private static bool MigrateFrom_0_7(LocalDatabase localDatabase, DatabaseMetadata databaseMetadata)
{
databaseMetadata.Version = Constants.CURRENT_DATABASE_VERSION;
localDatabase.UpdateMetadata(databaseMetadata);
return true;
}
}
}
17 changes: 14 additions & 3 deletions LibgenDesktop/Models/Localization/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class Language
{
private readonly List<Translation> translations;
private MainWindowLocalizator mainWindow;
private DatabaseWindowLocalizator databaseWindow;
private CreateDatabaseWindowLocalizator createDatabaseWindow;
private SearchTabLocalizator searchTab;
private NonFictionSearchResultsTabLocalizator nonFictionSearchResultsTab;
private FictionSearchResultsTabLocalizator fictionSearchResultsTab;
Expand All @@ -26,15 +26,17 @@ internal class Language
private SynchronizationLocalizator synchronization;
private DownloadManagerLocalizator downloadManager;
private ApplicationUpdateLocalizator applicationUpdate;
private DatabaseWindowLocalizator database;
private SettingsWindowLocalizator settings;
private AboutWindowLocalizator about;
private MessageBoxLocalizator messageBox;
private ErrorWindowLocalizator errorWindow;

public Language(List<Translation> prioritizedTranslationList)
{
translations = prioritizedTranslationList;
mainWindow = null;
databaseWindow = null;
createDatabaseWindow = null;
searchTab = null;
nonFictionSearchResultsTab = null;
fictionSearchResultsTab = null;
Expand All @@ -51,7 +53,9 @@ public Language(List<Translation> prioritizedTranslationList)
synchronization = null;
downloadManager = null;
applicationUpdate = null;
database = null;
settings = null;
about = null;
messageBox = null;
errorWindow = null;
Translation mainTranslation = prioritizedTranslationList.First();
Expand All @@ -66,18 +70,21 @@ public Language(List<Translation> prioritizedTranslationList)
DisplayName = "Error";
}
CultureCode = mainTranslation.General?.CultureCode?.Trim() ?? String.Empty;
TranslatorName = mainTranslation.General?.TranslatorName ?? "unknown";
Formatter = new LanguageFormatter(prioritizedTranslationList);
}

public string Name { get; }
public string LocalizedName { get; }
public string DisplayName { get; }
public string CultureCode { get; }
public string TranslatorName { get; }
public LanguageFormatter Formatter { get; }

public MainWindowLocalizator MainWindow => mainWindow ?? (mainWindow = new MainWindowLocalizator(translations, Formatter));

public DatabaseWindowLocalizator DatabaseWindow => databaseWindow ?? (databaseWindow = new DatabaseWindowLocalizator(translations, Formatter));
public CreateDatabaseWindowLocalizator CreateDatabaseWindow =>
createDatabaseWindow ?? (createDatabaseWindow = new CreateDatabaseWindowLocalizator(translations, Formatter));

public SearchTabLocalizator SearchTab => searchTab ?? (searchTab = new SearchTabLocalizator(translations, Formatter));

Expand Down Expand Up @@ -120,8 +127,12 @@ public Language(List<Translation> prioritizedTranslationList)
public ApplicationUpdateLocalizator ApplicationUpdate =>
applicationUpdate ?? (applicationUpdate = new ApplicationUpdateLocalizator(translations, Formatter));

public DatabaseWindowLocalizator Database => database ?? (database = new DatabaseWindowLocalizator(translations, Formatter));

public SettingsWindowLocalizator Settings => settings ?? (settings = new SettingsWindowLocalizator(translations, Formatter));

public AboutWindowLocalizator About => about ?? (about = new AboutWindowLocalizator(translations, Formatter));

public MessageBoxLocalizator MessageBox => messageBox ?? (messageBox = new MessageBoxLocalizator(translations, Formatter));

public ErrorWindowLocalizator ErrorWindow => errorWindow ?? (errorWindow = new ErrorWindowLocalizator(translations, Formatter));
Expand Down
2 changes: 1 addition & 1 deletion LibgenDesktop/Models/Localization/LanguageFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public string ToFormattedTimeString(DateTime dateTime)

public string ToFormattedDateTimeString(DateTime dateTime)
{
return dateTime.ToString(dateFormat, CultureInfo.InvariantCulture);
return dateTime.ToString(dateTimeFormat, CultureInfo.InvariantCulture);
}

public string FileSizeToString(long fileSize, bool showBytes)
Expand Down
Loading

0 comments on commit ce05e62

Please sign in to comment.