mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-08-20 17:09:19 +08:00
Support for saving files outside of RPFs in MetaForm, ModelForm and RelForm
This commit is contained in:
parent
ff93caafcd
commit
f98a7c8411
@ -343,7 +343,6 @@ namespace CodeWalker.Forms
|
|||||||
//(currently just return false and revert to XML file save)
|
//(currently just return false and revert to XML file save)
|
||||||
|
|
||||||
if (!(exploreForm?.EditMode ?? false)) return false;
|
if (!(exploreForm?.EditMode ?? false)) return false;
|
||||||
if (rpfFileEntry?.Parent == null) return false;
|
|
||||||
|
|
||||||
byte[] data = null;
|
byte[] data = null;
|
||||||
|
|
||||||
@ -409,34 +408,56 @@ namespace CodeWalker.Forms
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rpfFileEntry.Path.ToLowerInvariant().StartsWith("mods"))
|
if (rpfFileEntry?.Parent != null)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("This file is NOT located in the mods folder - Are you SURE you want to save this file?\r\nWARNING: This could cause permanent damage to your game!!!", "WARNING: Are you sure about this?", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
if (!rpfFileEntry.Path.ToLowerInvariant().StartsWith("mods"))
|
||||||
{
|
{
|
||||||
return false;//that was a close one
|
if (MessageBox.Show("This file is NOT located in the mods folder - Are you SURE you want to save this file?\r\nWARNING: This could cause permanent damage to your game!!!", "WARNING: Are you sure about this?", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return false;//that was a close one
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!(exploreForm?.EnsureRpfValidEncryption(rpfFileEntry.File) ?? false)) return false;
|
||||||
|
|
||||||
|
var newentry = RpfFile.CreateFile(rpfFileEntry.Parent, rpfFileEntry.Name, data);
|
||||||
|
if (newentry != rpfFileEntry)
|
||||||
|
{ }
|
||||||
|
rpfFileEntry = newentry;
|
||||||
|
|
||||||
|
exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer...
|
||||||
|
|
||||||
|
modified = false;
|
||||||
|
|
||||||
|
StatusLabel.Text = metaFormat.ToString() + " file saved successfully at " + DateTime.Now.ToString();
|
||||||
|
|
||||||
|
return true; //victory!
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Error saving file to RPF! The RPF archive may be corrupted...\r\n" + ex.ToString(), "Really Bad Error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(rpfFileEntry?.Path))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (!(exploreForm?.EnsureRpfValidEncryption(rpfFileEntry.File) ?? false)) return false;
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllBytes(rpfFileEntry.Path, data);
|
||||||
|
|
||||||
var newentry = RpfFile.CreateFile(rpfFileEntry.Parent, rpfFileEntry.Name, data);
|
exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer...
|
||||||
if (newentry != rpfFileEntry)
|
|
||||||
{ }
|
|
||||||
rpfFileEntry = newentry;
|
|
||||||
|
|
||||||
exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer...
|
modified = false;
|
||||||
|
|
||||||
modified = false;
|
StatusLabel.Text = metaFormat.ToString() + " file saved successfully at " + DateTime.Now.ToString();
|
||||||
|
|
||||||
StatusLabel.Text = metaFormat.ToString() + " file saved successfully at " + DateTime.Now.ToString();
|
return true; //victory!
|
||||||
|
}
|
||||||
return true; //victory!
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
MessageBox.Show("Error saving file to filesystem!\r\n" + ex.ToString(), "File I/O Error");
|
||||||
{
|
}
|
||||||
MessageBox.Show("Error saving file to RPF! The RPF archive may be corrupted...\r\n" + ex.ToString(), "Really Bad Error");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -1223,7 +1223,7 @@ namespace CodeWalker.Forms
|
|||||||
if (string.IsNullOrEmpty(FilePath))
|
if (string.IsNullOrEmpty(FilePath))
|
||||||
{
|
{
|
||||||
if (!editMode) saveAs = true;
|
if (!editMode) saveAs = true;
|
||||||
if (rpfFileEntry?.Parent == null) saveAs = true;
|
if (rpfFileEntry == null) saveAs = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1251,6 +1251,7 @@ namespace CodeWalker.Forms
|
|||||||
|
|
||||||
if (SaveFileDialog.ShowDialog() != DialogResult.OK) return;
|
if (SaveFileDialog.ShowDialog() != DialogResult.OK) return;
|
||||||
fn = SaveFileDialog.FileName;
|
fn = SaveFileDialog.FileName;
|
||||||
|
FilePath = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1335,12 +1336,18 @@ namespace CodeWalker.Forms
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(fn))
|
||||||
|
{
|
||||||
|
fn = rpfFileEntry?.Path;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.WriteAllBytes(fn, fileBytes);
|
File.WriteAllBytes(fn, fileBytes);
|
||||||
|
|
||||||
fileName = Path.GetFileName(fn);
|
fileName = Path.GetFileName(fn);
|
||||||
FilePath = fn;
|
|
||||||
|
exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer...
|
||||||
|
|
||||||
StatusLabel.Text = fileName + " saved successfully at " + DateTime.Now.ToString();
|
StatusLabel.Text = fileName + " saved successfully at " + DateTime.Now.ToString();
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,6 @@ namespace CodeWalker.Forms
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (!(exploreForm?.EditMode ?? false)) return false;
|
if (!(exploreForm?.EditMode ?? false)) return false;
|
||||||
if (rpfFileEntry?.Parent == null) return false;
|
|
||||||
|
|
||||||
byte[] data = null;
|
byte[] data = null;
|
||||||
|
|
||||||
@ -219,34 +218,56 @@ namespace CodeWalker.Forms
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rpfFileEntry.Path.ToLowerInvariant().StartsWith("mods"))
|
if (rpfFileEntry?.Parent != null)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("This file is NOT located in the mods folder - Are you SURE you want to save this file?\r\nWARNING: This could cause permanent damage to your game!!!", "WARNING: Are you sure about this?", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
if (!rpfFileEntry.Path.ToLowerInvariant().StartsWith("mods"))
|
||||||
{
|
{
|
||||||
return false;//that was a close one
|
if (MessageBox.Show("This file is NOT located in the mods folder - Are you SURE you want to save this file?\r\nWARNING: This could cause permanent damage to your game!!!", "WARNING: Are you sure about this?", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return false;//that was a close one
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!(exploreForm?.EnsureRpfValidEncryption(rpfFileEntry.File) ?? false)) return false;
|
||||||
|
|
||||||
|
var newentry = RpfFile.CreateFile(rpfFileEntry.Parent, rpfFileEntry.Name, data);
|
||||||
|
if (newentry != rpfFileEntry)
|
||||||
|
{ }
|
||||||
|
rpfFileEntry = newentry;
|
||||||
|
|
||||||
|
exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer...
|
||||||
|
|
||||||
|
modified = false;
|
||||||
|
|
||||||
|
StatusLabel.Text = metaFormat.ToString() + " file saved successfully at " + DateTime.Now.ToString();
|
||||||
|
|
||||||
|
return true; //victory!
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Error saving file to RPF! The RPF archive may be corrupted...\r\n" + ex.ToString(), "Really Bad Error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(rpfFileEntry?.Path))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (!(exploreForm?.EnsureRpfValidEncryption(rpfFileEntry.File) ?? false)) return false;
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllBytes(rpfFileEntry.Path, data);
|
||||||
|
|
||||||
var newentry = RpfFile.CreateFile(rpfFileEntry.Parent, rpfFileEntry.Name, data);
|
exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer...
|
||||||
if (newentry != rpfFileEntry)
|
|
||||||
{ }
|
|
||||||
rpfFileEntry = newentry;
|
|
||||||
|
|
||||||
exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer...
|
modified = false;
|
||||||
|
|
||||||
modified = false;
|
StatusLabel.Text = metaFormat.ToString() + " file saved successfully at " + DateTime.Now.ToString();
|
||||||
|
|
||||||
StatusLabel.Text = metaFormat.ToString() + " file saved successfully at " + DateTime.Now.ToString();
|
return true; //victory!
|
||||||
|
}
|
||||||
return true; //victory!
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
MessageBox.Show("Error saving file to filesystem!\r\n" + ex.ToString(), "File I/O Error");
|
||||||
{
|
}
|
||||||
MessageBox.Show("Error saving file to RPF! The RPF archive may be corrupted...\r\n" + ex.ToString(), "Really Bad Error");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user