Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Cleaning up zip/disk exporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Mar 7, 2020
1 parent 410243e commit ca3fdca
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 103 deletions.
20 changes: 17 additions & 3 deletions Disks/RunnerTools/LoadTool/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ function Init()
mode = "ejecting"
totalFrames = #currentAnimation
loopKeyframe = totalFrames - 2

-- Start the unload process
StartUnload()

elseif(ReadMetadata("showDiskAnimation") == "true") then
mode = "inserting"
currentAnimation = insertAnimation
Expand Down Expand Up @@ -200,10 +204,20 @@ function Update(timeDelta)
-- Increment frame by 1
frame = frame + 1

if(mode == "ejecting" and frame == 15) then
if(mode == "ejecting") then

-- if(frame == 8 and UnloadProgress() < 99) then

-- frame = 1
-- print("UnloadProgress", UnloadProgress())

-- Once disk is ejected, it needs to load the next game
mode = "loading"
-- else
if(frame == 15) then

EndUnload()
-- Once disk is ejected, it needs to load the next game
mode = "loading"
end

end

Expand Down
2 changes: 2 additions & 0 deletions Runners/PixelVision8/Runner/Exporters/ColorPaletteExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using PixelVision8.Engine.Chips;

Expand Down Expand Up @@ -90,6 +91,7 @@ public void Dispose()
exporter = null;
}

public Dictionary<string, object> Response => exporter.Response;
public byte[] bytes => exporter.bytes;

public string fileName => exporter.fileName;
Expand Down
2 changes: 2 additions & 0 deletions Runners/PixelVision8/Runner/Exporters/SpriteExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// Shawn Rakowski - @shwany
//

using System.Collections.Generic;
using Microsoft.Xna.Framework;
using PixelVision8.Engine;
using PixelVision8.Engine.Chips;
Expand Down Expand Up @@ -79,6 +80,7 @@ public void Dispose()
exporter = null;
}

public Dictionary<string, object> Response => exporter.Response;
public byte[] bytes => exporter.bytes;

public string fileName => exporter.fileName;
Expand Down
6 changes: 0 additions & 6 deletions Runners/PixelVision8/Runner/Exporters/ZipDiskExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ public class ZipDiskExporter : AbstractExporter
private ZipFileSystem zipFileSystem;
private WorkspaceService workspaceService;

public Dictionary<string, object> Response = new Dictionary<string, object>
{
{"success", false},
{"message", ""}
};

public ZipDiskExporter(string fileName, WorkspaceService workspaceService) : base(fileName)
{

Expand Down
6 changes: 0 additions & 6 deletions Runners/PixelVision8/Runner/Exporters/ZipExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ public class ZipExporter : AbstractExporter
protected int CurrentFile;
protected ZipOutputStream Archive;
protected byte[] Buffer;

protected int compressionLevel;

public Dictionary<string, object> Response = new Dictionary<string, object>
{
{"success", false},
{"message", ""}
};

public ZipExporter(string fileName, IFileLoadHelper fileLoadHelper, Dictionary<WorkspacePath, WorkspacePath> srcFiles, int compressionLevel = 4) : base(fileName)
{
Expand Down
57 changes: 41 additions & 16 deletions Runners/PixelVision8/Runner/PixelVision8Runner.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// Copyright (c) Jesse Freeman, Pixel Vision 8. All rights reserved.
//
//
// Copyright (c) Jesse Freeman, Pixel Vision 8. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) except for a few
// portions of the code. See LICENSE file in the project root for full
// license information. Third-party libraries used by Pixel Vision 8 are
// under their own licenses. Please refer to those libraries for details
// portions of the code. See LICENSE file in the project root for full
// license information. Third-party libraries used by Pixel Vision 8 are
// under their own licenses. Please refer to those libraries for details
// on the license they use.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
//
// Jesse Freeman - @JesseFreeman
// Christina-Antoinette Neofotistou @CastPixel
// Christer Kaitila - @McFunkypants
Expand Down Expand Up @@ -97,7 +97,7 @@ public PixelVision8Runner()
// throw new NotImplementedException();
}



// public List<string> loadHistory = new List<string>();
// protected List<Dictionary<string, string>> metaDataHistory = new List<Dictionary<string, string>>();
Expand Down Expand Up @@ -147,7 +147,7 @@ protected override void CreateWorkspaceService()
)
);

// Pass the new service back to the base class
// Pass the new service back to the base class
workspaceService = workspaceServicePlus;

serviceManager.AddService(typeof(WorkspaceService).FullName, workspaceService);
Expand Down Expand Up @@ -199,7 +199,7 @@ protected override void ConfigureWorkspace()
WorkspacePath.Root.AppendDirectory("User"),
new PhysicalFileSystem(documentsPath)));

// Mount the workspace drive
// Mount the workspace drive
workspaceServicePlus.MountWorkspace(workspaceName);

workspaceServicePlus.RebuildWorkspace();
Expand All @@ -212,12 +212,12 @@ public override void ActivateEngine(IEngine engine)
// Save a reference to the controller chip so we can listen for special key events
controllerChip = engine.ControllerChip;



// Activate the game
base.ActivateEngine(engine);


}

public void EjectDisk(string path)
Expand Down Expand Up @@ -531,7 +531,7 @@ public void MountDisk(string path)
{
// If we are running this disk clear the previous history
loadHistory.Clear();

// Run the disk
AutoRunGameFromDisk(diskName);

Expand Down Expand Up @@ -629,7 +629,8 @@ public override void ConfigureEngine(Dictionary<string, string> metaData = null)
// Inject the PV8 runner special global function
luaScript.Globals["IsExporting"] = new Func<bool>(ExportService.IsExporting);
luaScript.Globals["ReadExportPercent"] = new Func<int>(ExportService.ReadExportPercent);
luaScript.Globals["ReadExportMessage"] = new Func<string>(ExportService.ReadExportMessage);
luaScript.Globals["ReadExportMessage"] =
new Func<Dictionary<string, object>>(ExportService.ReadExportMessage);
luaScript.Globals["ShutdownSystem"] = new Action(ShutdownSystem);
luaScript.Globals["QuitCurrentTool"] = (QuitCurrentToolDelagator) QuitCurrentTool;
luaScript.Globals["RefreshActionKeys"] = new Action(RefreshActionKeys);
Expand Down Expand Up @@ -680,6 +681,30 @@ public override void ConfigureEngine(Dictionary<string, string> metaData = null)
// Force the lua script to use this boot done logic instead
luaScript.Globals["BootDone"] = new Action<bool>(BootDone);
}

if (mode == RunnerMode.Loading)
{
luaScript.Globals["StartUnload"] = new Action(StartUnload);
luaScript.Globals["UnloadProgress"] = new Func<int>(UnloadProgress);
luaScript.Globals["EndUnload"] = new Action(EndUnload);
}
}

protected void StartUnload()
{
Console.WriteLine("StartUnload");
}

protected int UnloadProgress()
{
Console.WriteLine("UnloadProgress");

return 0;
}

protected void EndUnload()
{
Console.WriteLine("EndUnload");
}

public override void RunGame()
Expand Down Expand Up @@ -709,7 +734,7 @@ public override void RunGame()
metaData["showEjectAnimation"] = ejectingDisk.ToString().ToLower();
else
metaData.Add("showEjectAnimation", ejectingDisk.ToString().ToLower());

if (metaData.ContainsKey("showDiskAnimation"))
metaData["showDiskAnimation"] = mountingDisk.ToString().ToLower();
else
Expand Down Expand Up @@ -917,4 +942,4 @@ public void StopRecording()

private delegate void QuitCurrentToolDelagator(Dictionary<string, string> metaData, string tool = null);
}
}
}
23 changes: 18 additions & 5 deletions Runners/PixelVision8/Runner/Services/ExportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// Shawn Rakowski - @shwany
//

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
Expand Down Expand Up @@ -45,7 +46,7 @@ public class ExportService : AbstractService

public Dictionary<string, byte[]> files = new Dictionary<string, byte[]>();

protected string message;
protected Dictionary<string, object> message = new Dictionary<string, object>();
private IEngine targetEngine;
private int totalParsers;

Expand All @@ -67,7 +68,7 @@ public int ReadExportPercent()
return (int) (percent * 100);
}

public string ReadExportMessage()
public Dictionary<string, object> ReadExportMessage()
{
return message;
}
Expand Down Expand Up @@ -245,10 +246,10 @@ private void WorkerExportSteps(object sender, DoWorkEventArgs e)
{
NextExporter();
}
catch
catch (Exception exception)
{
// DisplayError(RunnerGame.ErrorCode.Exception, new Dictionary<string, string>(){{"@{error}",exception.Message}}, exception);
// throw;
Console.WriteLine(exception);
// throw;
}

Thread.Sleep(1);
Expand All @@ -263,6 +264,16 @@ public void WorkerExporterCompleted(object sender, RunWorkerCompletedEventArgs e
workspaceService.SaveExporterFiles(files);

files.Clear();

// Aggregate all Get all the messages
foreach (var exporter in exporters)
{
foreach (var response in exporter.Response)
{
message.Add(exporter.GetType().Name + "_" + response.Key, response.Value);
}
}

}

exporting = false;
Expand Down Expand Up @@ -300,6 +311,8 @@ public void Reset()
currentParserID = 0;
totalSteps = 0;
currentStep = 0;
message.Clear();

}

#endregion
Expand Down
60 changes: 38 additions & 22 deletions Runners/PixelVision8/Runner/Services/LuaServicePlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,39 +261,55 @@ public long FileSize(WorkspacePath workspacePath)

public Dictionary<string, object> CreateDisk(string name, Dictionary<WorkspacePath, WorkspacePath> files, WorkspacePath dest, int maxFileSize = 512)
{

var fileLoader = new WorkspaceFileLoadHelper(workspace);

dest = workspace.UniqueFilePath(dest.AppendDirectory("Build")).AppendPath(name + ".pv8");
var diskExporter = new DiskExporter(dest.Path, fileLoader, files, maxFileSize);

diskExporter.CalculateSteps();

while (diskExporter.completed == false)
{
diskExporter.NextStep();
}

try
if (((PixelVision8Runner) runner).ExportService is ExportService exportService)
{
if ((bool)diskExporter.Response["success"])
{
workspace.SaveExporterFiles(new Dictionary<string, byte[]>() { { diskExporter.fileName, diskExporter.bytes } });

// Update the response
diskExporter.Response["success"] = true;
diskExporter.Response["message"] = "A new build was created in " + dest + ".";
diskExporter.Response["path"] = dest.Path;
}


((PixelVision8Runner) runner).ExportService.Reset();

((PixelVision8Runner) runner).ExportService.AddExporter(diskExporter);

((PixelVision8Runner) runner).ExportService.StartExport();

// diskExporter.CalculateSteps();
//
// while (diskExporter.completed == false)
// {
// diskExporter.NextStep();
// }
//
// try
// {
// if ((bool)diskExporter.Response["success"])
// {
// workspace.SaveExporterFiles(new Dictionary<string, byte[]>() { { diskExporter.fileName, diskExporter.bytes } });

// Update the response
diskExporter.Response["success"] = true;
diskExporter.Response["message"] = "A new build was created in " + dest + ".";
diskExporter.Response["path"] = dest.Path;
}
catch (Exception e)
else
{
Console.WriteLine(e);
diskExporter.Response["success"] = false;
diskExporter.Response["message"] = "Unable to create a build for '" + name + "'. " + e.Message;

diskExporter.Response["message"] = "Couldn't find the service to save a disk.";
}
// }
//
//
// }
// catch (Exception e)
// {
// Console.WriteLine(e);
// diskExporter.Response["success"] = false;
// diskExporter.Response["message"] = "Unable to create a build for '" + name + "'. " + e.Message;
//
// }

//
// // Create a path to the temp directory for the builds
Expand Down
3 changes: 1 addition & 2 deletions Runners/PixelVision8/Runner/Services/WorkspaceServicePlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ICSharpCode.SharpZipLib.Zip;
using PixelVision8.Engine;
using PixelVision8.Engine.Chips;
using PixelVision8.Runner.Exporters;
Expand Down Expand Up @@ -293,7 +292,7 @@ public override void ShutdownSystem()
public void EjectDisk(WorkspacePath filePath)
{
RemoveDisk(filePath);

// What happens when there are no disks
if (TotalDisks > 1)
try
Expand Down

0 comments on commit ca3fdca

Please sign in to comment.