Skip to content
Permalink
Browse files

[skip ci] GSDumpGui: Only reload dumps and dlls separately if their r…

…espective settings change, make config portable, autodetect dump/dll folder. (#2926)

- Add simple logging infrastructure and further improve the existing one
- Delegate loading of dlls and dumps into dedicated loader classes
- Adjust user interaction to restrict updates to only relevant parts
- Gsdx dlls (dumps) are only reloaded when a new path for gsdx dlls (dumps) was given. That means dlls are not reloaded just because the dumps path was changed or another dump was selected
- When GSDumpGui can not find the specified settings folder or there is no setting saved so far it will look into the directory of the currently running application (however as before only exactly in the directory and not in subdirectories)
- Further decouple model, view and 'controller' logic.
- Restrict directory checks to application basepath instead of current directory as current directly is changed at too man places
- Avoid some minor memory leaks by disposing some disposable elements

Note: Net framework requirement has been increased to 4.0 to run/compile the application.
  • Loading branch information...
willkuer authored and lightningterror committed Apr 15, 2019
1 parent 773be7b commit 1414d64b185cd212e94d554116250dceafb72f9a
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2009-2019 PCSX2 Dev Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace GSDumpGUI.Forms.Entities
{
public sealed class GsDlls : GsFiles<GsFile> { }
}
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2009-2019 PCSX2 Dev Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.IO;

namespace GSDumpGUI.Forms.Entities
{
public sealed class GsDumpFile : GsFile
{
public FileInfo PreviewFile { get; set; }
}
}
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2009-2019 PCSX2 Dev Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.IO;

namespace GSDumpGUI.Forms.Entities
{
public sealed class GsDumps : GsFiles<GsDumpFile>
{
private FileInfo GsDumpPreviewFile { get; set; }
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2009-2019 PCSX2 Dev Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.IO;

namespace GSDumpGUI.Forms.Entities
{
public class GsFile
{
public FileInfo File { get; set; }
public string DisplayText { get; set; }
}
}
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2009-2019 PCSX2 Dev Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.ComponentModel;

namespace GSDumpGUI.Forms.Entities
{
public abstract class GsFiles<TUnderlying>
where TUnderlying : GsFile
{
private int _selectedFileIndex = -1;

public class SelectedIndexUpdatedEventArgs
{
public SelectedIndexUpdatedEventArgs(int formerIndex, int updatedIndex)
{
FormerIndex = formerIndex;
UpdatedIndex = updatedIndex;
}

public int FormerIndex { get; }
public int UpdatedIndex { get; }
}

public delegate void SelectedIndexUpdateEventHandler(object sender, SelectedIndexUpdatedEventArgs args);

public event SelectedIndexUpdateEventHandler OnIndexUpdatedEvent;
public BindingList<TUnderlying> Files { get; } = new BindingList<TUnderlying>();

public int SelectedFileIndex
{
get
{
return _selectedFileIndex;
}
set
{
var oldValue = _selectedFileIndex;
_selectedFileIndex = value;
OnIndexUpdatedEvent?.Invoke(this, new SelectedIndexUpdatedEventArgs(oldValue, value));
}
}

public bool IsSelected => SelectedFileIndex != -1 && Files.Count > SelectedFileIndex;

public TUnderlying Selected
{
get
{
return SelectedFileIndex >= 0 ? Files[SelectedFileIndex] : null;
}
set
{
SelectedFileIndex = Files.IndexOf(value);
}
}
}
}
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2009-2019 PCSX2 Dev Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.IO;
using System.Linq;

namespace GSDumpGUI.Forms.Helper
{
public class FolderWithFallBackFinder : IFolderWithFallBackFinder
{
public DirectoryInfo GetViaPatternWithFallback(string defaultDir, string filePattern, params string[] fallBackFolder)
{
if (!string.IsNullOrWhiteSpace(defaultDir))
return new DirectoryInfo(defaultDir);

DirectoryInfo gsdxDllDirectory;
if (TryGetExistingDirectory(fallBackFolder, filePattern, out gsdxDllDirectory))
return gsdxDllDirectory;
return new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
}

private static bool TryGetExistingDirectory(string[] relativePaths, string pattern, out DirectoryInfo validDirectory)
{
if (relativePaths == null)
throw new ArgumentNullException(nameof(relativePaths));
foreach (var relativePath in relativePaths)
{

var candidate = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, relativePath));
if (candidate.Exists && candidate.GetFiles(pattern).Any())
{
validDirectory = candidate;
return true;
}
}

validDirectory = null;
return false;
}
}
}
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2009-2011 Ferreri Alessio
* Copyright (C) 2009-2019 PCSX2 Dev Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Collections.Generic;
using System.IO;
using GSDumpGUI.Forms.Entities;

namespace GSDumpGUI.Forms.Helper
{
public class GsDumpFinder : IGsDumpFinder
{
private readonly ILogger _logger;

public GsDumpFinder(ILogger logger)
{
_logger = logger;
}

public IEnumerable<GsDumpFile> GetValidGsdxDumps(DirectoryInfo directory)
{
var dumps = directory.GetFiles("*.gs", SearchOption.TopDirectoryOnly);

foreach (var dump in dumps)
{
int crc;
using (var fileStream = File.Open(dump.FullName, FileMode.Open))
{
using (var br = new BinaryReader(fileStream))
{
crc = br.ReadInt32();
br.Close();
}
}

var extensions = new[] {".png", ".bmp"};
var dumpPreview = default(FileInfo);
foreach (var extension in extensions)
{
var imageFile = new FileInfo(Path.ChangeExtension(dump.FullName, extension));
if (!imageFile.Exists)
continue;
dumpPreview = imageFile;
break;
}

_logger.Information($"Identified Dump for game ({crc:X}) with filename '{dump}'");
yield return new GsDumpFile
{
DisplayText = dump.Name + " | CRC : " + crc.ToString("X"),
File = dump,
PreviewFile = dumpPreview
};
}
}
}
}
Oops, something went wrong.

0 comments on commit 1414d64

Please sign in to comment.
You can’t perform that action at this time.