blueskythlikesclouds / MikuMikuLibrary

Format library and file editor for Hatsune Miku: Project DIVA games
MIT License
195 stars 45 forks source link

Successive compressed farc single file exports outputs empty files #13

Closed samyuu closed 4 years ago

samyuu commented 5 years ago

After single file exporting one file inside a compressed farc, successive single file exports are created but not successfully written to resulting in empty output files.

https://github.com/blueskythlikesclouds/MikuMikuLibrary/blob/98d6f18bf659f25368c6a677586cd040c71a83c5/MikuMikuModel/Nodes/IO/StreamNode.cs#L21-L24 does not copy any data. For both the first file being exported and successive ones, Data.CanSeek evaluates to false but the stream's position is already set to 0 so that is not the issue. Trying out

byte[] buffer = new byte[Data.Length];
Data.Read(buffer, 0, buffer.Length);

also leaves the buffer empty despite the Data's EntryStream.CanRead property returning true. I am unsure as to why this happens.

blueskythlikesclouds commented 5 years ago

I think I know. Whenever a new entry gets added to the view, the archive's underlying stream seeks out of previous entry's scope. Since seeking in compressed streams isn't supported, StreamView cannot correct underlying stream's position, causing it to read data out of its bounds.

By this logic, the latest entry added to the view should be extracted correctly, because the position of the archive's underlying stream will be where the latest entry starts.

However, this is just an assumption. At the moment, I cannot check if this is actually the case.

blueskythlikesclouds commented 4 years ago

Fixed as of ee5cb85