(GarOperation): fixed path creation.

This commit is contained in:
morkt 2017-02-05 01:38:54 +04:00
parent f486f19495
commit 5e6c8e4048
2 changed files with 13 additions and 8 deletions

View File

@ -322,7 +322,7 @@ namespace GARbro.GUI
void ExtractEntryAsIs (ArcFile arc, Entry entry) void ExtractEntryAsIs (ArcFile arc, Entry entry)
{ {
using (var input = arc.OpenEntry (entry)) using (var input = arc.OpenEntry (entry))
using (var output = CreateNewFile (entry.Name)) using (var output = CreateNewFile (entry.Name, true))
input.CopyTo (output); input.CopyTo (output);
} }
@ -333,11 +333,10 @@ namespace GARbro.GUI
var src_format = decoder.SourceFormat; // could be null var src_format = decoder.SourceFormat; // could be null
string target_ext = target_format.Extensions.FirstOrDefault() ?? ""; string target_ext = target_format.Extensions.FirstOrDefault() ?? "";
string outname = Path.ChangeExtension (entry.Name, target_ext); string outname = Path.ChangeExtension (entry.Name, target_ext);
outname = ArchiveFormat.CreatePath (outname);
if (src_format == target_format) if (src_format == target_format)
{ {
// source format is the same as a target, copy file as is // source format is the same as a target, copy file as is
using (var output = CreateNewFile (outname)) using (var output = CreateNewFile (outname, true))
decoder.Source.CopyTo (output); decoder.Source.CopyTo (output);
return; return;
} }
@ -346,7 +345,7 @@ namespace GARbro.GUI
{ {
image = AdjustImageOffset (image); image = AdjustImageOffset (image);
} }
using (var outfile = CreateNewFile (outname)) using (var outfile = CreateNewFile (outname, true))
{ {
target_format.Write (outfile, image); target_format.Write (outfile, image);
} }
@ -395,12 +394,11 @@ namespace GARbro.GUI
public void ConvertAudio (string filename, SoundInput input) public void ConvertAudio (string filename, SoundInput input)
{ {
filename = ArchiveFormat.CreatePath (filename);
string source_format = input.SourceFormat; string source_format = input.SourceFormat;
if (GarConvertMedia.CommonAudioFormats.Contains (source_format)) if (GarConvertMedia.CommonAudioFormats.Contains (source_format))
{ {
var output_name = Path.ChangeExtension (filename, source_format); var output_name = Path.ChangeExtension (filename, source_format);
using (var output = CreateNewFile (output_name)) using (var output = CreateNewFile (output_name, true))
{ {
input.Source.Position = 0; input.Source.Position = 0;
input.Source.CopyTo (output); input.Source.CopyTo (output);
@ -409,7 +407,7 @@ namespace GARbro.GUI
else else
{ {
var output_name = Path.ChangeExtension (filename, "wav"); var output_name = Path.ChangeExtension (filename, "wav");
using (var output = CreateNewFile (output_name)) using (var output = CreateNewFile (output_name, true))
AudioFormat.Wav.Write (input, output); AudioFormat.Wav.Write (input, output);
} }
} }

View File

@ -45,8 +45,15 @@ namespace GARbro.GUI
m_title = dialog_title; m_title = dialog_title;
} }
protected Stream CreateNewFile (string filename) /// <summary>
/// Create file <paramref name="filename"/>. Also create path to file if <paramref name="create_path"/> is true.
/// If file aready exists, popup dialog asking for necessary action.
/// WARNING: path to file should be relative, ArchiveFormat.CreatePath strips drive/root specification.
/// </summary>
protected Stream CreateNewFile (string filename, bool create_path = false)
{ {
if (create_path)
filename = GameRes.ArchiveFormat.CreatePath (filename);
FileMode open_mode = FileMode.CreateNew; FileMode open_mode = FileMode.CreateNew;
if (m_duplicate_action.ApplyToAll && if (m_duplicate_action.ApplyToAll &&
m_duplicate_action.Action == ExistingFileAction.Overwrite) m_duplicate_action.Action == ExistingFileAction.Overwrite)