mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-09-09 19:55:18 -05:00
Improved content-based batch rename tool + minor Narc.cs improvement
This commit is contained in:
@@ -301,8 +301,9 @@ namespace DSPRE {
|
||||
if (!di.Exists || di.GetFiles().Length == 0) {
|
||||
Narc opened = Narc.Open(paths.packedPath);
|
||||
|
||||
if (opened is null)
|
||||
if (opened is null) {
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
|
||||
opened.ExtractToFolder(paths.unpackedPath);
|
||||
}
|
||||
@@ -314,8 +315,9 @@ namespace DSPRE {
|
||||
if (gameDirs.TryGetValue(id, out (string packedPath, string unpackedPath) paths)) {
|
||||
Narc opened = Narc.Open(paths.packedPath);
|
||||
|
||||
if (opened is null)
|
||||
if (opened is null) {
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
|
||||
opened.ExtractToFolder(paths.unpackedPath);
|
||||
}
|
||||
|
||||
@@ -8842,7 +8842,7 @@ namespace DSPRE {
|
||||
if (dr.Equals(DialogResult.Yes)) {
|
||||
List<string> enumerationFile = new List<string> {
|
||||
"#============================================================================",
|
||||
"# File enumeration definition",
|
||||
"# File enumeration definition for folder " + "\"" + d.Name + "\"",
|
||||
"#============================================================================"
|
||||
};
|
||||
int initialLength = enumerationFile.Count;
|
||||
@@ -8865,15 +8865,26 @@ namespace DSPRE {
|
||||
|
||||
if (b[0] == 'B' && b[3] == '0') { //B**0
|
||||
ushort nameOffset;
|
||||
|
||||
destName = dirNameOnly + "\\"; //Full filename can be changed
|
||||
nameOffset = (ushort)(52 + (4 * (BitConverter.ToUInt16(b, 0xE) - 1)));
|
||||
|
||||
if (b[1] == 'T' && b[2] == 'X') { //BTX0
|
||||
destName = fileNameOnly; //Filename can't be changed, only extension
|
||||
} else {
|
||||
destName = dirNameOnly + "\\"; //Full filename can be changed
|
||||
#if false
|
||||
nameOffset += 0xEC;
|
||||
#else
|
||||
destName = fileNameOnly;
|
||||
#endif
|
||||
}
|
||||
|
||||
nameOffset = (ushort) ( 52 + (4 * (BitConverter.ToUInt16(b, 0xE) - 1)) );
|
||||
destName += Encoding.UTF8.GetString(DSUtils.ReadFromFile(f.FullName, nameOffset, 16)).TrimEnd(new char[] { (char)0 });
|
||||
string nameRead = Encoding.UTF8.GetString(DSUtils.ReadFromFile(f.FullName, nameOffset, 16)).TrimEnd(new char[] { (char)0 });
|
||||
|
||||
if (nameRead.Length <= 0 || nameRead.IndexOfAny(Path.GetInvalidPathChars()) >= 0 ) {
|
||||
destName = fileNameOnly; //Filename can't be changed, only extension
|
||||
} else {
|
||||
destName += nameRead;
|
||||
}
|
||||
|
||||
destName += ".ns";
|
||||
for (int i = 0; i < 3; i++) {
|
||||
magic += Char.ToLower((char)b[i]);
|
||||
@@ -8902,7 +8913,7 @@ namespace DSPRE {
|
||||
}
|
||||
|
||||
destName = MakeUniqueName(destName, fileNameOnly = null, dirNameOnly);
|
||||
File.Move(f.FullName, destName);
|
||||
File.Move(f.FullName, Path.Combine(Path.GetDirectoryName(f.FullName), Path.GetFileName(destName)));
|
||||
|
||||
enumerationFile.Add(Path.GetFileName(destName));
|
||||
}
|
||||
@@ -8916,7 +8927,7 @@ namespace DSPRE {
|
||||
|
||||
SaveFileDialog sf = new SaveFileDialog {
|
||||
Filter = "List File (*.txt; *.list)|*.txt;*.list",
|
||||
FileName = "enum.list"
|
||||
FileName = d.Name + ".list"
|
||||
};
|
||||
if (sf.ShowDialog(this) != DialogResult.OK) {
|
||||
MessageBox.Show("Operation cancelled.", "User discarded operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
@@ -8947,7 +8958,13 @@ namespace DSPRE {
|
||||
|
||||
int append = 1;
|
||||
|
||||
while (File.Exists(fileName)) {
|
||||
//string[] files = Directory.GetFiles(Path.GetDirectoryName(fileName));
|
||||
//while (!files.Any(x => x.Equals(fileName, StringComparison.InvariantCultureIgnoreCase))) {
|
||||
// string tmp = fileNameOnly + "(" + (append++) + ")";
|
||||
// fileName = Path.Combine(dirNameOnly, tmp + extension);
|
||||
//}
|
||||
|
||||
while (File.Exists(Path.Combine(dirNameOnly, fileName)) ) {
|
||||
string tmp = fileNameOnly + "(" + (append++) + ")";
|
||||
fileName = Path.Combine(dirNameOnly, tmp + extension);
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ namespace NarcAPI {
|
||||
bw.Close();
|
||||
}
|
||||
|
||||
public void ExtractToFolder(String dirPath) {
|
||||
if ( string.IsNullOrEmpty(dirPath) ) {
|
||||
public void ExtractToFolder(String dirPath, string extension = null) {
|
||||
if ( string.IsNullOrWhiteSpace(dirPath) ) {
|
||||
MessageBox.Show("Dir path + \"" + dirPath + "\" is invalid.", "Can't create directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
@@ -148,7 +148,7 @@ namespace NarcAPI {
|
||||
}
|
||||
|
||||
Parallel.For(0, Elements.Length, i => {
|
||||
string path = Path.Combine(dirPath, i.ToString("D4"));
|
||||
string path = Path.Combine(dirPath, i.ToString("D4") + (string.IsNullOrWhiteSpace(extension) ? "" : extension) );
|
||||
using (BinaryWriter wr = new BinaryWriter(File.Create(path))) {
|
||||
long len = Elements[i].Length;
|
||||
byte[] buffer = new byte[len];
|
||||
|
||||
Reference in New Issue
Block a user