Skip to content

Commit

Permalink
Update check
Browse files Browse the repository at this point in the history
  • Loading branch information
libgenapps committed Jan 28, 2018
1 parent 24169c8 commit a53d2c8
Show file tree
Hide file tree
Showing 55 changed files with 2,032 additions and 528 deletions.
2 changes: 1 addition & 1 deletion LibgenDesktop.Setup/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
internal static class Constants
{
public const string CURRENT_VERSION = "0.11";
public const string CURRENT_VERSION = "0.12";
public const string PRODUCT_TITLE_FORMAT = "Libgen Desktop " + CURRENT_VERSION + " ({0}-bit)";
public const string SHORTCUT_TITLE_FORMAT = "Libgen Desktop ({0}-bit)";
public const string PRODUCT_COMPANY = "Libgen Apps";
Expand Down
4 changes: 2 additions & 2 deletions LibgenDesktop/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ private void ShowMainWindow(MainModel mainModel)

private void ShowCreateDatabaseWindow(MainModel mainModel)
{
CreateDatabaseViewModel createDatabaseViewModel = new CreateDatabaseViewModel(mainModel);
IWindowContext windowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.CREATE_DATABASE_WINDOW, createDatabaseViewModel);
CreateDatabaseWindowViewModel createDatabaseWindowViewModel = new CreateDatabaseWindowViewModel(mainModel);
IWindowContext windowContext = WindowManager.CreateWindow(RegisteredWindows.WindowKey.CREATE_DATABASE_WINDOW, createDatabaseWindowViewModel);
bool? result = windowContext.ShowDialog();
if (result == true)
{
Expand Down
11 changes: 8 additions & 3 deletions LibgenDesktop/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{
internal static class Constants
{
public const string CURRENT_VERSION = "0.11";
public const string CURRENT_VERSION = "0.12";
public const string CURRENT_GITHUB_RELEASE_NAME = "v0.12 alpha";
public const string CURRENT_DATABASE_VERSION = "0.7";

public const string APP_SETTINGS_FILE_NAME = "libgen.config";
Expand Down Expand Up @@ -41,15 +42,16 @@ internal static class Constants
public const int ERROR_WINDOW_DEFAULT_HEIGHT = 450;
public const int ERROR_WINDOW_MIN_WIDTH = 400;
public const int ERROR_WINDOW_MIN_HEIGHT = 300;
public const int IMPORT_WINDOW_MIN_WIDTH = 500;
public const int IMPORT_WINDOW_MIN_WIDTH = 530;
public const int IMPORT_WINDOW_MIN_HEIGHT = 400;
public const int CREATE_DATABASE_WINDOW_WIDTH = 500;
public const int SETTINGS_WINDOW_DEFAULT_WIDTH = 760;
public const int SETTINGS_WINDOW_DEFAULT_HEIGHT = 550;
public const int SETTINGS_WINDOW_MIN_WIDTH = 760;
public const int SETTINGS_WINDOW_MIN_HEIGHT = 550;
public const int SYNCHRONIZATION_WINDOW_MIN_WIDTH = 500;
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 MESSAGE_BOX_WINDOW_WIDTH = 500;

public const string DEFAULT_DATABASE_FILE_NAME = "libgen.db";
Expand Down Expand Up @@ -86,9 +88,12 @@ internal static class Constants
public const int DEFAULT_MAXIMUM_SEARCH_RESULT_COUNT = 50000;

public const double SEARCH_PROGRESS_REPORT_INTERVAL = 0.1;
public const double IMPORT_PROGRESS_UPDATE_INTERVAL = 0.5;
public const double SYNCHRONIZATION_PROGRESS_UPDATE_INTERVAL = 0.1;
public const int DATABASE_TRANSACTION_BATCH = 500;
public const int MAX_EXPORT_ROWS_PER_FILE = 1000000;

public const string GITHUB_RELEASE_API_URL = "https://api.github.com/repos/libgenapps/LibgenDesktop/releases";
public const string USER_AGENT = "LibgenDesktop/" + CURRENT_VERSION;
public const int MIN_PROXY_PORT = 1;
public const int MAX_PROXY_PORT = 65535;
Expand Down
2 changes: 1 addition & 1 deletion LibgenDesktop/Common/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static string GetOsVersion()
ManagementObject osInfo = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<ManagementObject>().FirstOrDefault();
if (osInfo != null)
{
return $"{osInfo.Properties["Caption"].Value.ToString()}{osInfo.Properties["Version"].Value.ToString()} {osInfo.Properties["OSArchitecture"].Value.ToString()}";
return $"{osInfo.Properties["Caption"].Value.ToString()} {osInfo.Properties["Version"].Value.ToString()} {osInfo.Properties["OSArchitecture"].Value.ToString()}";
}
else
{
Expand Down
1 change: 1 addition & 0 deletions LibgenDesktop/Common/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private static void CreateLogger()
private static void LogEnvironmentInformation()
{
logger.Debug("Libgen Desktop " + CURRENT_VERSION);
logger.Debug("Release: " + CURRENT_GITHUB_RELEASE_NAME);
logger.Debug("OS: " + Environment.OsVersion);
logger.Debug(".NET Framework: " + Environment.NetFrameworkVersion);
logger.Debug("Is in 64-bit process: " + Environment.IsIn64BitProcess);
Expand Down
6 changes: 4 additions & 2 deletions LibgenDesktop/Infrastructure/RegisteredWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ internal enum WindowKey
IMPORT_WINDOW,
CREATE_DATABASE_WINDOW,
SETTINGS_WINDOW,
SYNCHRONIZATION_WINDOW
SYNCHRONIZATION_WINDOW,
APPLICATION_UPDATE_WINDOW
}

internal class RegisteredWindow
Expand All @@ -43,9 +44,10 @@ static RegisteredWindows()
RegisterWindow(WindowKey.SCI_MAG_DETAILS_WINDOW, typeof(SciMagDetailsWindow), typeof(SciMagDetailsWindowViewModel));
RegisterWindow(WindowKey.ERROR_WINDOW, typeof(ErrorWindow), typeof(ErrorWindowViewModel));
RegisterWindow(WindowKey.IMPORT_WINDOW, typeof(ImportWindow), typeof(ImportWindowViewModel));
RegisterWindow(WindowKey.CREATE_DATABASE_WINDOW, typeof(CreateDatabaseWindow), typeof(CreateDatabaseViewModel));
RegisterWindow(WindowKey.CREATE_DATABASE_WINDOW, typeof(CreateDatabaseWindow), typeof(CreateDatabaseWindowViewModel));
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));
}

public static Dictionary<WindowKey, RegisteredWindow> AllWindows { get; }
Expand Down
34 changes: 31 additions & 3 deletions LibgenDesktop/LibgenDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,16 @@
<Compile Include="Models\Import\SciMagImporter.cs" />
<Compile Include="Models\JsonApi\JsonApiClient.cs" />
<Compile Include="Models\JsonApi\JsonApiNonFictionBook.cs" />
<Compile Include="Models\Localization\LocalizationStorage.cs" />
<Compile Include="Models\ProgressArgs\DownloadFileProgress.cs" />
<Compile Include="Models\ProgressArgs\ImportCreateIndexProgress.cs" />
<Compile Include="Models\ProgressArgs\ImportLoadLibgenIdsProgress.cs" />
<Compile Include="Models\ProgressArgs\ImportObjectsProgress.cs" />
<Compile Include="Models\ProgressArgs\ImportSearchTableDefinitionProgress.cs" />
<Compile Include="Models\ProgressArgs\ImportTableDefinitionFoundProgress.cs" />
<Compile Include="Models\ProgressArgs\JsonApiDownloadProgress.cs" />
<Compile Include="Models\ProgressArgs\ExportProgress.cs" />
<Compile Include="Models\ProgressArgs\SearchProgress.cs" />
<Compile Include="Models\ProgressArgs\SynchronizationProgress.cs" />
<Compile Include="Models\Settings\Mirrors.cs" />
<Compile Include="Models\Settings\MirrorStorage.cs" />
<Compile Include="Models\SqlDump\ColumnDefinition.cs" />
Expand All @@ -161,11 +164,14 @@
<Compile Include="Models\SqlDump\TableDefinition.cs" />
<Compile Include="Models\SqlDump\TableDefinitions.cs" />
<Compile Include="Models\SqlDump\TableType.cs" />
<Compile Include="Models\Update\GitHubApiRelease.cs" />
<Compile Include="Models\Update\Updater.cs" />
<Compile Include="Models\Utils\UrlGenerator.cs" />
<Compile Include="ViewModels\ApplicationUpdateWindowViewModel.cs" />
<Compile Include="ViewModels\ExportPanelViewModel.cs" />
<Compile Include="ViewModels\FictionDetailsTabViewModel.cs" />
<Compile Include="ViewModels\ImportLogPanelViewModel.cs" />
<Compile Include="ViewModels\LibgenWindowViewModel.cs" />
<Compile Include="ViewModels\ProgressLogItemViewModel.cs" />
<Compile Include="ViewModels\SearchResultsTabViewModel.cs" />
<Compile Include="ViewModels\SynchronizationWindowViewModel.cs" />
<Compile Include="ViewModels\NonFictionDetailsTabViewModel.cs" />
Expand All @@ -175,7 +181,7 @@
<Compile Include="ViewModels\SciMagSearchResultsTabViewModel.cs" />
<Compile Include="ViewModels\NonFictionDetailsWindowViewModel.cs" />
<Compile Include="Infrastructure\Command.cs" />
<Compile Include="ViewModels\CreateDatabaseViewModel.cs" />
<Compile Include="ViewModels\CreateDatabaseWindowViewModel.cs" />
<Compile Include="ViewModels\ErrorWindowViewModel.cs" />
<Compile Include="ViewModels\ImportWindowViewModel.cs" />
<Compile Include="ViewModels\FictionSearchResultsTabViewModel.cs" />
Expand All @@ -184,6 +190,9 @@
<Compile Include="ViewModels\SearchTabViewModel.cs" />
<Compile Include="ViewModels\SettingsWindowViewModel.cs" />
<Compile Include="ViewModels\TabViewModel.cs" />
<Compile Include="Views\ApplicationUpdateWindow.xaml.cs">
<DependentUpon>ApplicationUpdateWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Controls\AddTabButton.xaml.cs">
<DependentUpon>AddTabButton.xaml</DependentUpon>
</Compile>
Expand All @@ -193,6 +202,9 @@
<Compile Include="Views\Controls\ExportPanel.xaml.cs">
<DependentUpon>ExportPanel.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Controls\ImportLogPanel.xaml.cs">
<DependentUpon>ImportLogPanel.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Controls\TabControl.cs" />
<Compile Include="Views\MessageBoxWindow.xaml.cs">
<DependentUpon>MessageBoxWindow.xaml</DependentUpon>
Expand Down Expand Up @@ -267,6 +279,10 @@
<Compile Include="Views\Utils\DataGridLengthConverter.cs" />
<Compile Include="Views\Utils\EventListenerExtensions.cs" />
<Compile Include="Views\Utils\PasswordBoxExtensions.cs" />
<Page Include="Views\ApplicationUpdateWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Controls\AddTabButton.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -279,14 +295,26 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Controls\ImportLogPanel.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\MessageBoxWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Styles\ApplicationUpdateWindowStyles.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Styles\ExportPanelStyles.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Styles\ImportLogPanelStyles.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Styles\MessageBoxWindowStyles.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
111 changes: 104 additions & 7 deletions LibgenDesktop/Models/Database/LocalDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void CreateMetadataTable()

public bool CheckIfMetadataExists()
{
return ExecuteScalarCommand(SqlScripts.CHECK_IF_METADATA_TABLE_EXIST) == 1;
return ExecuteIntScalarCommand(SqlScripts.CHECK_IF_METADATA_TABLE_EXIST) == 1;
}

public DatabaseMetadata GetMetadata()
Expand Down Expand Up @@ -96,6 +97,36 @@ public void AddMetadata(DatabaseMetadata databaseMetadata)
}
}

public void UpdateMetadata(DatabaseMetadata newMetadata)
{
DatabaseMetadata oldMetadata = GetMetadata();
foreach (DatabaseMetadata.FieldDefinition fieldDefinition in DatabaseMetadata.FieldDefinitions.Values)
{
if (fieldDefinition.Getter(oldMetadata) != fieldDefinition.Getter(newMetadata))
{
SetMetadataValue(newMetadata, fieldDefinition);
}
}
}

public void SetMetadataValue(DatabaseMetadata databaseMetadata, DatabaseMetadata.FieldDefinition field)
{
bool metadataItemExist;
using (SQLiteCommand command = connection.CreateCommand())
{
command.CommandText = SqlScripts.CHECK_IF_METADATA_ITEM_EXIST;
command.Parameters.AddWithValue("Key", field.FieldName);
metadataItemExist = ParseIntScalarResult(command.ExecuteScalar()) == 1;
}
using (SQLiteCommand command = connection.CreateCommand())
{
command.CommandText = metadataItemExist ? SqlScripts.UPDATE_METADATA_ITEM : SqlScripts.INSERT_METADATA_ITEM;
command.Parameters.AddWithValue("Key", field.FieldName);
command.Parameters.AddWithValue("Value", field.Getter(databaseMetadata));
command.ExecuteNonQuery();
}
}

public void CreateNonFictionTables()
{
ExecuteCommands(SqlScripts.CREATE_NON_FICTION_TABLE);
Expand All @@ -112,9 +143,14 @@ public void CreateNonFictionLibgenIdIndex()
ExecuteCommands(SqlScripts.CREATE_NON_FICTION_LIBGENID_INDEX);
}

public BitArray GetNonFictionLibgenIdsBitArray()
{
return GetLibgenIdsBitArray(SqlScripts.GET_ALL_NON_FICTION_LIBGEN_IDS, GetNonFictionMaxLibgenId());
}

public int CountNonFictionBooks()
{
return ExecuteScalarCommand(SqlScripts.COUNT_NON_FICTION);
return ExecuteIntScalarCommand(SqlScripts.COUNT_NON_FICTION);
}

public NonFictionBook GetNonFictionBookById(int id)
Expand Down Expand Up @@ -151,6 +187,11 @@ public NonFictionBook GetLastModifiedNonFictionBook()
}
}

public int GetNonFictionMaxLibgenId()
{
return ExecuteIntScalarCommand(SqlScripts.GET_NON_FICTION_MAX_LIBGEN_ID);
}

public IEnumerable<NonFictionBook> SearchNonFictionBooks(string searchQuery, int? resultLimit)
{
searchQuery = EscapeSearchQuery(searchQuery);
Expand Down Expand Up @@ -454,9 +495,14 @@ public void CreateFictionLibgenIdIndex()
ExecuteCommands(SqlScripts.CREATE_FICTION_LIBGENID_INDEX);
}

public BitArray GetFictionLibgenIdsBitArray()
{
return GetLibgenIdsBitArray(SqlScripts.GET_ALL_FICTION_LIBGEN_IDS, GetFictionMaxLibgenId());
}

public int CountFictionBooks()
{
return ExecuteScalarCommand(SqlScripts.COUNT_FICTION);
return ExecuteIntScalarCommand(SqlScripts.COUNT_FICTION);
}

public FictionBook GetFictionBookById(int id)
Expand Down Expand Up @@ -493,6 +539,11 @@ public FictionBook GetLastModifiedFictionBook()
}
}

public int GetFictionMaxLibgenId()
{
return ExecuteIntScalarCommand(SqlScripts.GET_FICTION_MAX_LIBGEN_ID);
}

public IEnumerable<FictionBook> SearchFictionBooks(string searchQuery, int? resultLimit)
{
searchQuery = EscapeSearchQuery(searchQuery);
Expand Down Expand Up @@ -925,9 +976,14 @@ public void CreateSciMagAddedDateTimeIndex()
ExecuteCommands(SqlScripts.CREATE_SCIMAG_ADDEDDATETIME_INDEX);
}

public BitArray GetSciMagLibgenIdsBitArray()
{
return GetLibgenIdsBitArray(SqlScripts.GET_ALL_SCIMAG_LIBGEN_IDS, GetSciMagMaxLibgenId());
}

public int CountSciMagArticles()
{
return ExecuteScalarCommand(SqlScripts.COUNT_SCIMAG);
return ExecuteIntScalarCommand(SqlScripts.COUNT_SCIMAG);
}

public SciMagArticle GetSciMagArticleById(int id)
Expand Down Expand Up @@ -964,6 +1020,11 @@ public SciMagArticle GetLastAddedSciMagArticle()
}
}

public int GetSciMagMaxLibgenId()
{
return ExecuteIntScalarCommand(SqlScripts.GET_SCIMAG_MAX_LIBGEN_ID);
}

public IEnumerable<SciMagArticle> SearchSciMagArticles(string searchQuery, int? resultLimit)
{
searchQuery = EscapeSearchQuery(searchQuery);
Expand Down Expand Up @@ -1258,16 +1319,35 @@ private void ExecuteCommands(params string[] commands)
}
}

private int ExecuteScalarCommand(string commandText)
private int ExecuteIntScalarCommand(string commandText)
{
return ParseIntScalarResult(ExecuteScalarCommand(commandText));
}

private string ExecuteStringScalarCommand(string commandText)
{
return ParseStringScalarResult(ExecuteScalarCommand(commandText));
}

private object ExecuteScalarCommand(string commandText)
{
using (SQLiteCommand command = connection.CreateCommand())
{
command.CommandText = commandText;
object objectResult = command.ExecuteScalar();
return objectResult != DBNull.Value ? (int)(long)objectResult : 0;
return command.ExecuteScalar();
}
}

private int ParseIntScalarResult(object objectResult)
{
return objectResult != DBNull.Value ? (int)(long)objectResult : 0;
}

private string ParseStringScalarResult(object objectResult)
{
return objectResult != DBNull.Value ? objectResult.ToString() : null;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private DateTime ParseDbDate(string input)
{
Expand Down Expand Up @@ -1324,5 +1404,22 @@ private List<string> GetIndexList(string getIndexListQuery)
}
}
}

private BitArray GetLibgenIdsBitArray(string query, int maxLibgenId)
{
BitArray result = new BitArray(maxLibgenId + 1);
using (SQLiteCommand command = connection.CreateCommand())
{
command.CommandText = query;
using (SQLiteDataReader dataReader = command.ExecuteReader())
{
while (dataReader.Read())
{
result[dataReader.GetInt32(0)] = true;
}
}
}
return result;
}
}
}
Loading

0 comments on commit a53d2c8

Please sign in to comment.