Skip to content

Commit

Permalink
Added proper ppx subfile exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
bbepis committed Nov 13, 2017
1 parent 1563e75 commit d626ea2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 28 deletions.
40 changes: 16 additions & 24 deletions Plugins/SB3UtilityPPx/FormPPx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public partial class FormPPx : DockContent, EditedContent
public string FormVariable { get; protected set; }
public ppxEditor Editor { get; protected set; }
public string EditorVar { get; protected set; }
public string ParserVar { get; protected set; }

List<ListView> subfileListViews = new List<ListView>();

Expand Down Expand Up @@ -114,11 +113,11 @@ public FormPPx(string path, string variable)
}

FormVariable = variable;

EditorVar = Gui.Scripting.GetNextVariable("ppxEditor");

ParserVar = Gui.Scripting.GetNextVariable("ppParser");
EditorVar = Gui.Scripting.GetNextVariable("ppEditor");

Editor = new ppxEditor(path);
//Editor = new ppxEditor(path);
Editor = (ppxEditor)Gui.Scripting.RunScript(EditorVar + " = ppxEditor(path=\"" + path + "\")");

/*
object result = Gui.Scripting.RunScript(ParserVar + " = OpenPP(path=\"" + path + "\")");
Expand All @@ -136,7 +135,7 @@ public FormPPx(string path, string variable)
}
*/

Text = Path.GetFileName(path);
Text = Path.GetFileName(path);
ToolTipText = path;
ShowHint = DockState.Document;

Expand All @@ -147,8 +146,6 @@ public FormPPx(string path, string variable)
subfileListViews.Add(imageSubfilesList);
subfileListViews.Add(soundSubfilesList);
subfileListViews.Add(otherSubfilesList);

InitSubfileLists(true);

foreach (string archive in Editor.Archive.Files.Select(x => x.ArchiveName).Distinct())
{
Expand All @@ -159,10 +156,11 @@ public FormPPx(string path, string variable)
}

}
comboBoxArchives.SelectedIndex = 0;
comboBoxArchives.SelectedIndexChanged += new EventHandler(comboBoxArchives_SelectedIndexChanged);
comboBoxArchives.SelectedIndex = 0;
InitSubfileLists(true);

this.FormClosing += new FormClosingEventHandler(FormPP_FormClosing);
this.FormClosing += new FormClosingEventHandler(FormPP_FormClosing);
Gui.Docking.ShowDockContent(this, Gui.Docking.DockFiles, ContentCategory.Archives);

keepBackupToolStripMenuItem.Checked = (bool)Gui.Config["KeepBackupOfPP"];
Expand Down Expand Up @@ -224,7 +222,6 @@ private void FormPP_FormClosing(object sender, FormClosingEventArgs e)
ChildParserVars.Clear();
Gui.Scripting.Variables.Remove(FormVariable);
Gui.Scripting.Variables.Remove(EditorVar);
Gui.Scripting.Variables.Remove(ParserVar);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -328,8 +325,8 @@ private void InitSubfileLists(bool opening)
}
else
{
List<ExternalTool> toolList;
/*
List<ExternalTool> toolList;
if (!ext.EndsWith(".lst") && !ppEditor.ExternalTools.TryGetValue(ext.ToUpper(), out toolList))
{
item.BackColor = Color.LightCoral;
Expand Down Expand Up @@ -832,18 +829,15 @@ void ShowBlockingDialog(string path, BackgroundWorker worker)

private void reopenToolStripMenuItem_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
/*
try
{
string opensFileVar = Gui.Scripting.GetNextVariable("opensPP");
Gui.Scripting.RunScript(opensFileVar + " = FormPP(path=\"" + Editor.Parser.FilePath + "\", variable=\"" + opensFileVar + "\")", false);
string opensFileVar = Gui.Scripting.GetNextVariable("opensPPx");
Gui.Scripting.RunScript(opensFileVar + " = FormPPx(path=\"" + Editor.Archive.Filename + "\", variable=\"" + opensFileVar + "\")", false);
}
catch (Exception ex)
{
Utility.ReportException(ex);
}
*/
}

private void newSourceFormatToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -1243,11 +1237,9 @@ private void exportPPToolStripMenuItem_Click(object sender, EventArgs e)

private void exportSubfilesToolStripMenuItem_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
/*
try
{
folderBrowserDialog1.SelectedPath = Path.GetDirectoryName(this.Editor.Parser.FilePath);
folderBrowserDialog1.SelectedPath = Path.GetDirectoryName(this.Editor.Archive.Filename);
folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;

ListView subfilesList = null;
Expand Down Expand Up @@ -1278,17 +1270,17 @@ private void exportSubfilesToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (ListViewItem item in subfilesList.SelectedItems)
{
IWriteFile subfile = (IWriteFile)item.Tag;
Gui.Scripting.RunScript("ExportSubfile(parser=" + ParserVar + ", name=\"" + subfile.Name + "\", path=\"" + folderBrowserDialog1.SelectedPath + @"\" + subfile.Name + "\")");
}
ISubfile subfile = (ISubfile)item.Tag;
ArchiveFileSource source = subfile.Source as ArchiveFileSource;
Gui.Scripting.RunScript(EditorVar + ".ExportSubfile(arcname=\"" + source.ArchiveName + "\", name=\"" + source.Name + "\", path=\"" + folderBrowserDialog1.SelectedPath + @"\" + subfile.Name + "\")");
}
}
}
}
catch (Exception ex)
{
Utility.ReportException(ex);
}
*/
}

private void closeToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
38 changes: 34 additions & 4 deletions Plugins/SB3UtilityPPx/ppxEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ public void AddSubfile(string path, bool replace)
public void AddSubfiles(string path, bool replace)
{
throw new NotImplementedException();

/*
foreach (string file in Directory.EnumerateFiles(Path.GetDirectoryName(path), Path.GetFileName(path)))
{
AddSubfile(file, replace);
}
*/
}

[Plugin]
Expand Down Expand Up @@ -185,9 +186,20 @@ public ISubfile GetSubfile(string archiveName, string name)
return Archive.Files.FirstOrDefault(x => x.ArchiveName == archiveName && x.Name == name);
}

public List<ISubfile> GetSubfiles(string archiveName)
public IList<ISubfile> GetSubfiles(string archiveName)
{
return Archive.Files.Where(x => x.ArchiveName == archiveName).Select(x => (ISubfile)x).ToList();
var files = Archive.Files.Where(x => x.ArchiveName == archiveName).ToList();

for (int i = 0; i < files.Count; i++)
{
if (files[i].Type != ArchiveFileType.XggAudio)
using (var decoder = PPeX.Encoders.EncoderFactory.GetDecoder(Stream.Null, Archive, files[i].Type))
{
files[i] = new ArchiveSubfile(files[i].Source as ArchiveFileSource, decoder.NameTransform(files[i].Name));
}
}

return files;
}

[Plugin]
Expand All @@ -200,7 +212,25 @@ public Stream ReadSubfile(string archiveName, string name)
throw new Exception("Couldn't find the subfile " + archiveName + "/" + name);
}

return file.GetRawStream();
return (file.Source as ArchiveFileSource).GetRawStream();
}

[Plugin]
public void ExportSubfile(string arcname, string name, string path)
{
var subfile = GetSubfile(arcname, name);

using (FileStream fs = new FileStream(path, FileMode.Create))
if (subfile.Type != ArchiveFileType.XggAudio)
{
using (Stream stream = subfile.GetRawStream())
stream.CopyTo(fs);
}
else
{
using (Stream stream = (subfile.Source as ArchiveFileSource).GetRawStream())
stream.CopyTo(fs);
}
}

[Plugin]
Expand Down

0 comments on commit d626ea2

Please sign in to comment.