Skip to content

Commit

Permalink
fix(ui): Fix export of embedded definition
Browse files Browse the repository at this point in the history
This was completely broken before in multiple ways.

Fixes #30
Fixes 33
  • Loading branch information
jcoliz committed Jul 7, 2024
1 parent 6251642 commit 5033b21
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 34 deletions.
6 changes: 3 additions & 3 deletions LogoSlideMaker.Lib/Export/ExportPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ public ExportPipeline(Definition __definition)
renderEngine = new(definition.Render, imageCache);
}

public async Task LoadAndMeasureAsync(string basePath)
public async Task LoadAndMeasureAsync(string? basePath)
{
imageCache.BaseDirectory = basePath;
await imageCache.LoadAsync(definition.Logos.Select(x => x.Value.Path));
}

public void Save(string? templatePath, string outputPath, string? dataVersion)
public void Save(Stream? templateStream, string outputPath, string? dataVersion)
{
// Open template or create new presentation
var pres = !string.IsNullOrWhiteSpace(templatePath) ? new Presentation(templatePath) : new Presentation();
var pres = templateStream is not null ? new Presentation(templateStream) : new Presentation();

// If there isn't a specified variant, default to an EMPTY one
// TODO: Perhaps better to do this on LOAD
Expand Down
4 changes: 2 additions & 2 deletions LogoSlideMaker.Lib/Export/ImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ private async Task<byte[]> LoadImageAsync(string filename)
Stream? stream = null;
if (BaseDirectory is null)
{
var names = Assembly.GetExecutingAssembly()!.GetManifestResourceNames();
var names = Assembly.GetEntryAssembly()!.GetManifestResourceNames();
var resource = names.Where(x => x.Contains($".{filename}")).Single();
stream = Assembly.GetExecutingAssembly()!.GetManifestResourceStream(resource);
stream = Assembly.GetEntryAssembly()!.GetManifestResourceStream(resource);
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions LogoSlideMaker.WinUi/LogoSlideMaker.WinUi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<None Remove="Sample\wine-local.png" />
<None Remove="Sample\wine-svgrepo-com.svg" />
<None Remove="Sample\wine.png" />
<None Remove="Sample\template.pptx" />
</ItemGroup>

<ItemGroup>
Expand All @@ -56,6 +57,7 @@
<EmbeddedResource Include="Sample\wine-local.png" />
<EmbeddedResource Include="Sample\wine-svgrepo-com.svg" />
<EmbeddedResource Include="Sample\wine.png" />
<EmbeddedResource Include="Sample\template.pptx" />
</ItemGroup>

<ItemGroup>
Expand Down
23 changes: 5 additions & 18 deletions LogoSlideMaker.WinUi/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,29 +224,16 @@ private async void DoExport_Click(object _, RoutedEventArgs __)
{
try
{
// Will save this out as powerpoint file
// Get the default output file from the viewmodel
var path = viewModel.OutputPath;
if (path is null)
{
// TODO: Should disable 'Export' app button when output path is null

logger.LogError("Unable to export to empty path");

return;
}

// Bring up a save picker to let user have ultimate decision on file
var picker = new FileSavePicker()
{
SuggestedFileName = Path.GetFileName(path),
DefaultFileExtension = Path.GetExtension(path),
SuggestedFileName = Path.GetFileName(viewModel.OutputPath ?? viewModel.LastOpenedFilePath ?? "logo-slides.pptx"),
SettingsIdentifier = "Common"
};
picker.FileTypeChoices.Add("PowerPoint Files", [".pptx"]);

// Associate the HWND with the file picker
WinRT.Interop.InitializeWithWindow.Initialize(picker, hWnd);
InitializeWithWindow.Initialize(picker, hWnd);

var file = await picker.PickSaveFileAsync();
if (file != null)
Expand All @@ -258,18 +245,18 @@ private async void DoExport_Click(object _, RoutedEventArgs __)
// TODO: Also should get this off the UI thread! :(
await viewModel.ExportToAsync(outPath);

logger.LogInformation("OpenFile: OK exported {path}", path);
logger.LogInformation("Export: OK {path}", outPath);
}
else
{
logger.LogDebug("OpenFile: No file chosen");
logger.LogDebug("Export: No file chosen");
}

// TODO: Give user option to launch the ppt (would be nice)
}
catch (Exception ex)
{
logger.LogError(ex, "Export failed");
logger.LogError(ex, "Export: Failed");
}
}

Expand Down
Binary file modified LogoSlideMaker.WinUi/Sample/template.pptx
Binary file not shown.
20 changes: 15 additions & 5 deletions LogoSlideMaker.WinUi/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,20 +466,30 @@ public async Task ExportToAsync(string outPath)
}
var exportPipeline = new ExportPipeline(_definition);

var directory = Path.GetDirectoryName(LastOpenedFilePath)!;
var directory = LastOpenedFilePath is not null ? Path.GetDirectoryName(LastOpenedFilePath) : null;

// TODO: Would be much better to do this when the definition is LOADED, because we'll
// already be on a loading screen at that point!
await exportPipeline.LoadAndMeasureAsync(directory);

var templateStream = default(Stream);
var templatePath = _definition.Files?.Template?.Slides;
if (templatePath is not null)
{
templatePath = Path.Combine(directory, templatePath);
if (templatePath is not null)
{
if (directory is not null)
{
templatePath = Path.Combine(directory, templatePath);
templateStream = File.OpenRead(templatePath);
}
else
{
templateStream = OpenEmbeddedFile(templatePath);
}
}

// TODO: Need a way to inject version (How are we even going to GET it??)
exportPipeline.Save(templatePath, outPath, null);
exportPipeline.Save(templateStream, outPath, null);
templateStream?.Dispose();
}

#endregion
Expand Down
3 changes: 2 additions & 1 deletion LogoSlideMaker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
// EXPORT
//

exportPipeline.Save(definitions.Files.Template.Slides, definitions.Files.Output, options.Version);
using var templateStream = definitions.Files.Template.Slides is not null ? File.OpenRead(definitions.Files.Output) : null;
exportPipeline.Save(templateStream, definitions.Files.Output, options.Version);

//
// LISTING
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Or how many disparate technology components you've leverage in your own solution
Logo Slide Maker is a Windows Desktop application to build, preview, and generate PowerPoint presentations containing
logos with text. It can also be run from a terminal window.

## Installing

Head over to the [Releases](https://github.com/jcoliz/LogoSlideMaker/releases) section to download the latest MSIX for your architecture. Before installing it the first time,
you'll need to download and trust the matching certificate file (.cer). In the future, the app will be available in the Microsoft Store.

## Getting Started

Here's the basic getting started guide:
Expand All @@ -17,10 +22,9 @@ Here's the basic getting started guide:
1. Open the TOML file in the app to preview.
1. Make changes to the TOML as needed to fulfil your vision, and reload to update the preview with your changes.
1. If you have multiple slides defined, view each slide individually, using Previous and Next commands.
1. Once you're happy, export the slides to a PowerPoint presentation

## Unfinished Business
1. Once you're happy, export the slides to a PowerPoint presentation.

For now, the only way to use the tool is to clone this repo and build it yourself. In the future, fully built versions will be available in the Microsoft Store.
## Roadmap

For more details, please see the [Issues](https://github.com/jcoliz/LogoSlideMaker/issues) section of this repo for a full list of functionality envisioned for the future.
For details on future planned features, please visit the [Issues](https://github.com/jcoliz/LogoSlideMaker/issues) section. Feel free to file an issue there to report a
bug or suggest a new feature.

0 comments on commit 5033b21

Please sign in to comment.