Skip to content

Commit 37fc636

Browse files
author
BuildOne Robotics
committed
Added OneDrive cloud save and Windows build
1 parent 388e1b1 commit 37fc636

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

CadWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<Button Content="▭ Rectangle" Width="100" Margin="5" Click="Rectangle_Click"/>
3030
<Button Content="⭕ Circle" Width="80" Margin="5" Click="Circle_Click"/>
3131
<Button Content="🗑️ Clear" Width="80" Margin="5" Click="Clear_Click"/>
32+
<Button Content="💾 Save" Width="80" Margin="5" Click="Save_Click"/>
3233
</StackPanel>
3334
</Border>
3435

CadWindow.xaml.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
using System;
2+
using System.IO;
13
using System.Windows;
24
using System.Windows.Input;
35
using System.Windows.Media;
6+
using System.Windows.Media.Imaging;
47
using System.Windows.Shapes;
58

69
namespace BluePrintOne
@@ -21,6 +24,7 @@ public CadWindow()
2124
private void Rectangle_Click(object sender, RoutedEventArgs e) => currentTool = "Rectangle";
2225
private void Circle_Click(object sender, RoutedEventArgs e) => currentTool = "Circle";
2326
private void Clear_Click(object sender, RoutedEventArgs e) => DrawCanvas.Children.Clear();
27+
private void Save_Click(object sender, RoutedEventArgs e) => SaveToCloud();
2428

2529
private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
2630
{
@@ -84,5 +88,30 @@ private void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
8488
isDrawing = false;
8589
currentShape = null;
8690
}
91+
92+
private void SaveToCloud()
93+
{
94+
var oneDrivePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\OneDrive";
95+
var savePath = Directory.Exists(oneDrivePath) ? oneDrivePath : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
96+
savePath = Path.Combine(savePath, "BluePrintOne");
97+
98+
if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
99+
100+
var fileName = $"Drawing_{DateTime.Now:yyyyMMdd_HHmmss}.png";
101+
var fullPath = Path.Combine(savePath, fileName);
102+
103+
var renderBitmap = new RenderTargetBitmap((int)DrawCanvas.ActualWidth, (int)DrawCanvas.ActualHeight, 96, 96, PixelFormats.Pbgra32);
104+
renderBitmap.Render(DrawCanvas);
105+
106+
var encoder = new PngBitmapEncoder();
107+
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
108+
109+
using (var file = File.Create(fullPath))
110+
{
111+
encoder.Save(file);
112+
}
113+
114+
MessageBox.Show($"Saved to: {fullPath}", "Saved Successfully", MessageBoxButton.OK, MessageBoxImage.Information);
115+
}
87116
}
88117
}

RUN.bat

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
@echo off
2-
echo Starting BluePrintOne...
3-
dotnet run
2+
echo Building BluePrintOne for Windows...
3+
dotnet publish -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true
4+
if exist "bin\Release\net8.0-windows\win-x64\publish\BluePrintOne.exe" (
5+
echo.
6+
echo Running BluePrintOne...
7+
start "" "bin\Release\net8.0-windows\win-x64\publish\BluePrintOne.exe"
8+
) else (
9+
echo Build failed!
10+
)
11+
pause

0 commit comments

Comments
 (0)