Skip to content

Commit

Permalink
Merge pull request #58 from cwensley/fix-loading-animated-from-comman…
Browse files Browse the repository at this point in the history
…d-line

Fix loading animated documents from the command line
  • Loading branch information
cwensley authored Sep 14, 2022
2 parents b84785c + fa69ae0 commit 7271073
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 42 deletions.
12 changes: 6 additions & 6 deletions Source/Pablo.Interface/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,8 @@ void InternalLoadFile(string fileName, Stream stream, Format format, bool editMo
/**
var bufferedStream = new MemoryStream();
stream.WriteTo(bufferedStream);
stream.Close ();
stream.Close();
bufferedStream.Position = 0;
/**/
var bufferedStream = new BufferedStream(stream, 20 * 1024);

Expand Down Expand Up @@ -840,7 +841,7 @@ void Document_Loaded(object sender, EventArgs e)
{
if (loadingStream != null)
{
// loadingStream.Dispose();
loadingStream.Dispose();
loadingStream = null;
PabloApplication.Instance.Invoke(delegate
{
Expand Down Expand Up @@ -869,10 +870,9 @@ public bool LoadFile(string fileName, bool hasSavePermissions, bool setFileList

if (File.Exists(fileName))
{
using (var stream = File.OpenRead(fileName))
{
return LoadFile(fileName, stream, null, editMode ?? EditMode, setFileList, hasSavePermissions);
}
// do not dispose, we may need to load in the background for animated documents.
var stream = File.OpenRead(fileName);
return LoadFile(fileName, stream, null, editMode ?? EditMode, setFileList, hasSavePermissions);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public virtual void PreLoad(Stream stream, Format format, Handler handler)
public virtual void Load(string fileName, Format format, Handler handler)
{
this.FileName = fileName;
var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); // can't dispose here if we load in background!
var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); // can't dispose here if we load in background!
Load(stream, format, handler);
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Pablo/Formats/Animated/AnimatedDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private void Load()
{
if (bs != null)
bs.Close();
if (stream != null)
stream.Close();
// if (stream != null)
// stream.Close();
bs = null;
stream = null;
}
Expand Down
17 changes: 4 additions & 13 deletions Source/Pablo/Formats/Animated/BaudStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,12 @@ public long Baud
TickWait = (value > 0) ? (long)(((TimeSpan.TicksPerSecond * 1.2) / (value / 8))) : 0;
}
}

public override bool CanRead
{
get { return true; }
}

public override bool CanSeek
{
get { return false; }
}
public override bool CanRead => stream.CanRead;

public override bool CanWrite
{
get { return false; }
}
public override bool CanSeek => stream.CanSeek;

public override bool CanWrite => false;

public long TickWait
{
Expand Down
12 changes: 6 additions & 6 deletions Source/Pablo/Formats/Rip/FormatRip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public void Load (Stream stream, RipDocument document, RipHandler handler)
*/
if (document.AnimateView && Application.Instance != null) {
document.BGI.DelayDraw = true; // for faster animation
Application.Instance.Invoke (delegate {
//lastEnableZoom = handler.EnableZoom;
#if DESKTOP
//handler.EnableZoom = false;
#endif
});
// Application.Instance.Invoke (delegate {
// //lastEnableZoom = handler.EnableZoom;
// #if DESKTOP
// //handler.EnableZoom = false;
// #endif
// });
}

try {
Expand Down
15 changes: 3 additions & 12 deletions Source/Pablo/Sauce/SauceStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,11 @@ public SauceStream(Stream stream)
}
else Sauce = null;
}
public override bool CanRead
{
get { return true; }
}
public override bool CanRead => stream.CanRead;

public override bool CanSeek
{
get { return true; }
}
public override bool CanSeek => stream.CanSeek;

public override bool CanWrite
{
get { return false; }
}
public override bool CanWrite => false;

public override void Flush() { stream.Flush(); }

Expand Down
5 changes: 3 additions & 2 deletions Source/PabloDraw/CommandHandlers/ConvertCommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ public override bool Process(ProcessCommandLineArgs args)
sw2.Stop ();
args.Writer.WriteLine ("Convertion rate: {0}, total seconds: {1}", iters / sw2.Elapsed.TotalSeconds, sw2.Elapsed.TotalSeconds);
/**/
if (!Directory.Exists(Path.GetDirectoryName(outFile)))
Directory.CreateDirectory(Path.GetDirectoryName(outFile));
var outDir = Path.GetDirectoryName(outFile);
if (!string.IsNullOrEmpty(outDir) && !Directory.Exists(outDir))
Directory.CreateDirectory(outDir);

using (var destinationStream = new FileStream(outFile, FileMode.Create, FileAccess.Write))
{
Expand Down

0 comments on commit 7271073

Please sign in to comment.