Skip to content

Commit

Permalink
combined both non-steam import functions into one.
Browse files Browse the repository at this point in the history
fixed crash if there were two shortcut entries in screenshots.vdf with the same name
  • Loading branch information
[email protected] committed May 1, 2014
1 parent 332456a commit 94a60f0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Depressurizer/CDlgUpdateProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protected override void Finish() {
if ((!ignoreExternal) && (SteamId != 0))
{
int newItems, removedItems;
Fetched += data.IntegrateNonSteamGameList(SteamId, overwrite, ignore, out newItems, out removedItems);
Fetched += data.ImportNonSteamGames(SteamId, overwrite, ignore, false, true, out newItems, out removedItems);
Added += newItems;
Removed = removedItems;
}
Expand Down
6 changes: 3 additions & 3 deletions Depressurizer/Depressurizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>0.4.2.0</ApplicationVersion>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>0.4.5.1</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down Expand Up @@ -278,7 +278,7 @@
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 y x64%29</ProductName>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
Expand Down
50 changes: 45 additions & 5 deletions Depressurizer/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ public int ImportSteamFile(long SteamId, SortedSet<int> ignore, bool ignoreDlc,
int result = ImportSteamFile(filePath, ignore, ignoreDlc);
if (!ignoreExternal)
{
result += ImportNonSteamGames(SteamId, ignore);
int newItems, removedItems;
result += ImportNonSteamGames(SteamId, true, ignore, true, false, out newItems, out removedItems);
}
return result;
}
Expand Down Expand Up @@ -593,6 +594,7 @@ public void SaveSteamFile( string filePath, bool discardMissing ) {

#region Non-Steam game file handling

/* this had too much in common with the other loading function to maintain both
/// <summary>
/// Loads all non-steam games into the game list and sets their categories to match the loaded config file
/// </summary>
Expand Down Expand Up @@ -694,6 +696,7 @@ private int ImportNonSteamGames( long SteamId, SortedSet<int> ignore )
}
return result;
}
*/

/// <summary>
/// Loads in games from an node containing a list of games.
Expand Down Expand Up @@ -888,7 +891,9 @@ private bool LoadShortcutGames(long SteamId, out Dictionary<string, int> shortcu
{
int gameId = (int)(ulongId >> 32);
string gameName = (string)shortcutPair.Value.NodeData;
shortcutGames.Add(gameName, gameId);
if( !shortcutGames.ContainsKey( gameName ) ) {
shortcutGames.Add(gameName, gameId);
}
}
else
{
Expand Down Expand Up @@ -924,13 +929,20 @@ private bool LoadShortcutGames(long SteamId, out Dictionary<string, int> shortcu
/// <param name="ignore">List of identifiers of games to be ignored</param>
/// <param name="newItems">Returns number of new games integrated</param>
/// <returns>Returns number of external games located</returns>
public int IntegrateNonSteamGameList(long SteamId, bool overWrite, SortedSet<int> ignore, out int newItems, out int removedItems)
public int ImportNonSteamGames(long SteamId, bool overWrite, SortedSet<int> ignore, bool loadCategories, bool removeOthers, out int newItems, out int removedItems)
{
newItems = 0;
removedItems = 0;
if (SteamId <= 0) return 0;
int loadedGames = 0;

SortedSet<int> existingNonSteamGames = new SortedSet<int>();
if( removeOthers ) {
foreach( int id in Games.Keys ) {
if( id < 0 ) existingNonSteamGames.Add( id );
}
}

Dictionary<string, int> shortcutgames;
if (LoadShortcutGames(SteamId, out shortcutgames))
{
Expand Down Expand Up @@ -966,15 +978,43 @@ public int IntegrateNonSteamGameList(long SteamId, bool overWrite, SortedSet<int
loadedGames++;
if (isNew)
newItems++;

if( loadCategories ) {
Game gameEntry = this.Games[shortcutgames[gameName]];
string cat0 = null, cat1 = null;
VdfFileNode tagsNode = attrGame.GetNodeAt( new string[] { "tags" }, false );
if( ( tagsNode != null ) && ( tagsNode.NodeType == ValueType.Array ) &&
( tagsNode.NodeArray.Count > 0 ) && ( tagsNode.NodeArray.ContainsKey( "0" ) ) ) {
VdfFileNode vdfCat = tagsNode.NodeArray["0"];
if( vdfCat.NodeType == ValueType.Value ) {
cat0 = vdfCat.NodeData.ToString();
}
if( tagsNode.NodeArray.ContainsKey( "1" ) ) {
vdfCat = tagsNode.NodeArray["1"];
if( vdfCat.NodeType == ValueType.Value ) {
cat1 = vdfCat.NodeData.ToString();
}
}
}
gameEntry.Favorite = ( ( cat0 == "favorite" ) || ( cat1 == "favorite" ) );
if( cat0 != "favorite" ) {
gameEntry.Category = GetCategory( cat0 );
} else {
gameEntry.Category = GetCategory( cat1 );
}

}

}
existingNonSteamGames.Remove(shortcutgames[gameName]);
shortcutgames.Remove(gameName);
}
}
}
// Remove external games which have been deleted from Steam client
foreach (KeyValuePair<string, int> shortcutpair in shortcutgames)
foreach (int idToRemove in existingNonSteamGames)
{
if (RemoveGame(shortcutpair.Value))
if (RemoveGame(idToRemove))
removedItems++;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Depressurizer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ You should have received a copy of the GNU General Public License
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion( "0.4.5" )]
[assembly: AssemblyFileVersion( "0.4.5" )]
[assembly: AssemblyVersion( "0.4.5.1" )]
[assembly: AssemblyFileVersion( "0.4.5.1" )]

0 comments on commit 94a60f0

Please sign in to comment.