Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
JosefNemec committed May 24, 2017
2 parents 469811f + 705592b commit fd7cab0
Show file tree
Hide file tree
Showing 78 changed files with 2,137 additions and 653 deletions.
6 changes: 4 additions & 2 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ param(
[string]$OutputPath = (Join-Path $PWD $Configuration),
[switch]$Setup = $false,
[switch]$Portable = $false,
[switch]$SkipBuild = $false
[switch]$SkipBuild = $false,
[ValidateSet("x86", "x64")]
[string]$Platform = "x86"
)

$ErrorActionPreference = "Stop"
Expand Down Expand Up @@ -32,7 +34,7 @@ if (!$SkipBuild)

$solutionDir = Join-Path $pwd "..\source"
$msbuildPath = "c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe";
$arguments = "build.xml /p:SolutionDir=`"$solutionDir`" /p:OutputPath=`"$outputPath`";Configuration=$configuration /property:Platform=x86 /t:Build";
$arguments = "build.xml /p:SolutionDir=`"$solutionDir`" /p:OutputPath=`"$outputPath`";Configuration=$configuration /property:Platform=$Platform /t:Build";
$compiler = Start-Process $msbuildPath $arguments -PassThru -NoNewWindow
$handle = $compiler.Handle # cache proc.Handle http://stackoverflow.com/a/23797762/1479211
$compiler.WaitForExit()
Expand Down
5 changes: 4 additions & 1 deletion source/Playnite.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.9
VisualStudioVersion = 15.0.26430.6
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{FBE3E4C8-611E-435D-B47C-FE006AAA8C4A}"
EndProject
Expand All @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlayniteServices", "Playnit
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayniteServicesTests", "PlayniteServicesTests\PlayniteServicesTests.csproj", "{10B4D1CC-3A24-496C-8BCF-9CAEA65970C4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{9783B123-F0C8-4F03-B680-4E2D6D6C684A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -98,6 +100,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{3BB5A3D4-B998-4D0F-9B7A-B133905AA5C9} = {FBE3E4C8-611E-435D-B47C-FE006AAA8C4A}
{59D0C141-64A8-4D86-8156-4BEF8472CB8E} = {FBE3E4C8-611E-435D-B47C-FE006AAA8C4A}
{B06BF5BB-0B33-437B-8759-38278FF15706} = {9783B123-F0C8-4F03-B680-4E2D6D6C684A}
{10B4D1CC-3A24-496C-8BCF-9CAEA65970C4} = {FBE3E4C8-611E-435D-B47C-FE006AAA8C4A}
EndGlobalSection
EndGlobal
9 changes: 5 additions & 4 deletions source/Playnite/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
<remove invariant="System.Data.SQLite" /><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /></DbProviderFactories>
</system.data>
</configuration>
48 changes: 33 additions & 15 deletions source/Playnite/Database/GameDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public LiteDatabase Database
}
}

private LiteCollection<IGame> dbGames;
private LiteCollection<IGame> dbCollection;

private ObservableCollection<IGame> games = new ObservableCollection<IGame>();
public ObservableCollection<IGame> Games
Expand Down Expand Up @@ -111,7 +111,7 @@ public GameDatabase(IGogLibrary gogLibrary, ISteamLibrary steamLibrary, IOriginL

private void CheckDbState()
{
if (dbGames == null)
if (dbCollection == null)
{
throw new Exception("Database is not opened.");
}
Expand All @@ -126,7 +126,7 @@ public LiteDatabase OpenDatabase(string path, bool loadGames = false)
// To force litedb to try to open file, should throw exceptuion if something is wrong with db file
database.GetCollectionNames();

dbGames = database.GetCollection<IGame>("games");
dbCollection = database.GetCollection<IGame>("games");
if (loadGames == true)
{
LoadGamesFromDb();
Expand All @@ -140,7 +140,7 @@ public void LoadGamesFromDb()
logger.Info("Loading games from db");
games.Clear();

foreach (var game in dbGames.FindAll())
foreach (var game in dbCollection.FindAll())
{
games.Add(game);
}
Expand All @@ -155,7 +155,7 @@ public void LoadGamesFromDb(Settings settings)

games.Clear();

foreach (var game in dbGames.FindAll())
foreach (var game in dbCollection.FindAll())
{
if (game.Provider == Provider.Steam && !settings.SteamSettings.IntegrationEnabled)
{
Expand Down Expand Up @@ -204,7 +204,7 @@ public void AddGame(IGame game)

lock (fileLock)
{
dbGames.Insert(game);
dbCollection.Insert(game);
}

games.Add(game);
Expand Down Expand Up @@ -234,7 +234,7 @@ public void DeleteGame(IGame game)
{
DeleteImageSafe(game.Icon, game);
DeleteImageSafe(game.Image, game);
dbGames.Delete(game.Id);
dbCollection.Delete(game.Id);
}

var existingGame = games.FirstOrDefault(a => a.Id == game.Id);
Expand Down Expand Up @@ -283,6 +283,18 @@ public MemoryStream GetFileStream(string id)
}
}

public void SaveFile(string id, string path)
{
CheckDbState();

var file = Database.FileStorage.FindById(id);

lock (fileLock)
{
file.SaveAs(path, true);
}
}

/// <summary>
/// Deletes image from database only if it's not used by any object.
/// </summary>
Expand All @@ -296,9 +308,9 @@ public void DeleteImageSafe(string id, IGame game)
}

CheckDbState();
dbGames = database.GetCollection<IGame>("games");
dbCollection = database.GetCollection<IGame>("games");

foreach (var gm in dbGames.FindAll())
foreach (var gm in dbCollection.FindAll())
{
if (gm.Id == game.Id)
{
Expand Down Expand Up @@ -330,7 +342,7 @@ public void UpdateGameInDatabase(IGame game)

lock (fileLock)
{
dbGames.Update(game);
dbCollection.Update(game);

// Update loaded instance of a game
var loadedGame = Games.First(a => a.Id == game.Id);
Expand Down Expand Up @@ -407,7 +419,7 @@ public void UpdateInstalledGames(Provider provider)

foreach (var newGame in installedGames)
{
var existingGame = dbGames.FindAll().FirstOrDefault(a => a.ProviderId == newGame.ProviderId && a.Provider == provider);
var existingGame = dbCollection.FindAll().FirstOrDefault(a => a.ProviderId == newGame.ProviderId && a.Provider == provider);

if (existingGame == null)
{
Expand Down Expand Up @@ -444,14 +456,14 @@ public void UpdateInstalledGames(Provider provider)
}
}

UpdateGameInDatabase(existingGame);

// Game may have been not installed prviously and may not be loaded currently
var loaded = Games.FirstOrDefault(a => a.ProviderId == existingGame.ProviderId && a.Provider == existingGame.Provider) != null;
if (!loaded)
{
Games.Add(existingGame);
}

UpdateGameInDatabase(existingGame);
}
}

Expand Down Expand Up @@ -504,10 +516,16 @@ public void UpdateOwnedGames(Provider provider)
}

// Delete games that are no longer in library
foreach (IGame dbGame in dbGames.FindAll().Where(a => a.Provider == provider))
{
foreach (IGame dbGame in dbCollection.FindAll().Where(a => a.Provider == provider))
{
if (importedGames.FirstOrDefault(a => a.ProviderId == dbGame.ProviderId) == null)
{
// Except games that are installed, in case that game is part of free weekend, beta or similar events
if (dbGame.IsInstalled)
{
continue;
}

logger.Info("Removing game {0} which is no longer in {1} library", dbGame.ProviderId, dbGame.Provider);
DeleteGame(dbGame);
}
Expand Down
10 changes: 5 additions & 5 deletions source/Playnite/Diagnostic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ namespace Playnite
{
public static class Diagnostic
{
private static void AddFolderToZip(ZipArchive archive, string zipRoot, string path, string filter)
private static void AddFolderToZip(ZipArchive archive, string zipRoot, string path, string filter, SearchOption searchOption)
{
IEnumerable<string> files;

if (filter.Contains('|'))
{
var filters = filter.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
files = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories).Where(a =>
files = Directory.EnumerateFiles(path, "*.*", searchOption).Where(a =>
{
return filters.Contains(Path.GetExtension(a));
});
}
else
{
files = Directory.EnumerateFiles(path, filter, SearchOption.AllDirectories);
files = Directory.EnumerateFiles(path, filter, searchOption);
}

foreach (var file in files)
Expand Down Expand Up @@ -73,7 +73,7 @@ public static void CreateDiagPackage(string path)
var originContentPath = Path.Combine(Providers.Origin.OriginPaths.DataPath, "LocalContent");
if (Directory.Exists(originContentPath))
{
AddFolderToZip(archive, "Origin", originContentPath, ".dat|.mfst");
AddFolderToZip(archive, "Origin", originContentPath, ".dat|.mfst", SearchOption.AllDirectories);
}

// GOG data
Expand All @@ -88,7 +88,7 @@ public static void CreateDiagPackage(string path)
foreach (var folder in (new SteamLibrary()).GetLibraryFolders())
{
var appsFolder = Path.Combine(folder, "steamapps");
AddFolderToZip(archive, "Steam", appsFolder, "appmanifest*");
AddFolderToZip(archive, "Steam", appsFolder, "appmanifest*", SearchOption.TopDirectoryOnly);
}
}

Expand Down
5 changes: 5 additions & 0 deletions source/Playnite/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ public static void DeleteFolder(string path)
Directory.Delete(path, true);
}
}

public static string GetSafeFilename(string filename)
{
return string.Join("_", filename.Split(Path.GetInvalidFileNameChars()));
}
}
}
Loading

0 comments on commit fd7cab0

Please sign in to comment.