Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mod Manager] Improvements to Collection Import #317

Merged
merged 5 commits into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 42 additions & 24 deletions FrostyModManager/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
using System.Linq;
using Newtonsoft.Json;
using System.Threading.Tasks;
using System.Linq;
using System.Media;

namespace FrostyModManager
{
Expand Down Expand Up @@ -981,14 +981,19 @@ private void largeScreenshot_MouseDown(object sender, MouseButtonEventArgs e)

private void FrostyWindow_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, true) == true)
if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
{
string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop, true);
InstallMods(filenames);

ICollectionView view = CollectionViewSource.GetDefaultView(availableModsList.ItemsSource);
view.Refresh();
}
else if (e.Data.GetFormats().Any(f => f == "FileContents"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that not write them to the tmp storage and then u should be able to import them anyways?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windows zip doesnt, winrar however does and it will satisfy the first if statement

{
SystemSounds.Hand.Play();
FrostyMessageBox.Show("Cannot import mod files that have not been extracted", "Frosty Mod Manager");
}
}

private void InstallMods(string[] filenames)
Expand All @@ -1000,6 +1005,8 @@ private void InstallMods(string[] filenames)

FrostyTaskWindow.Show("Installing Mods", "", (task) =>
{
List<string> collections = new List<string>();

foreach (string filename in filenames)
{
FileInfo fi = new FileInfo(filename);
Expand All @@ -1010,7 +1017,6 @@ private void InstallMods(string[] filenames)
if (IsCompressed(fi))
{
List<string> mods = new List<string>();
List<string> collections = new List<string>();
List<int> format = new List<int>();
List<string> archives = new List<string>();
int fbpacks = 0;
Expand Down Expand Up @@ -1164,26 +1170,6 @@ private void InstallMods(string[] filenames)
lastInstalledMod = AddMod(fi.FullName, format[i]);
}
}

if (collections.Count > 0)
{
// now actually decompress files
decompressor.OpenArchive(filename);
foreach (CompressedFileInfo compressedFi in decompressor.EnumerateFiles())
{
if (collections.Contains(compressedFi.Filename))
{
decompressor.DecompressToFile(Path.Combine(modsDir.FullName, compressedFi.Filename));
}
}

// and add them to the mod manager
for (int i = 0; i < collections.Count; i++)
{
fi = new FileInfo(Path.Combine(modsDir.FullName, collections[i]));
lastInstalledMod = AddCollection(fi.FullName, 0);
}
}
}
else if (fi.Extension == ".daimod")
{
Expand Down Expand Up @@ -1366,6 +1352,10 @@ private void InstallMods(string[] filenames)
lastInstalledMod = AddMod(fi.FullName, 0);
}
}
else if (fi.Extension == ".fbcollection")
{
collections.Add(fi.Name);
}
else
{
// dont allow any files without fbmod extension
Expand Down Expand Up @@ -1442,13 +1432,41 @@ private void InstallMods(string[] filenames)
fi = new FileInfo(Path.Combine(modsDir.FullName, fi.Name));
lastInstalledMod = AddMod(fi.FullName, newFormat ? 1 : 0);
}

if (collections.Count > 0)
{
if (filename.Contains(".zip"))
{
// now actually decompress files
ZipDecompressor decompressor = new ZipDecompressor();
decompressor.OpenArchive(filename);
foreach (CompressedFileInfo compressedFi in decompressor.EnumerateFiles())
{
if (collections.Contains(compressedFi.Filename))
{
decompressor.DecompressToFile(Path.Combine(modsDir.FullName, compressedFi.Filename));
}
}
}
else if (filename.Contains(".fbcollection"))
{
File.Copy(fi.FullName, Path.Combine(modsDir.FullName, fi.Name));
}
}
}
catch (FrostyModLoadException e)
{
errors.Add(new ImportErrorInfo { error = e.Message, filename = fi.Name });
File.Delete(fi.FullName);
}
}

// add collections to the mod manager
for (int i = 0; i < collections.Count; i++)
{
FileInfo fi = new FileInfo(Path.Combine(modsDir.FullName, collections[i]));
lastInstalledMod = AddCollection(fi.FullName, 0);
}
});

ICollectionView view = CollectionViewSource.GetDefaultView(availableModsList.ItemsSource);
Expand Down Expand Up @@ -2070,4 +2088,4 @@ private void LoadMenuExtensions()
}
}
}
}
}