chore: offload img folder to appdata

This commit is contained in:
2026-03-03 13:58:33 +01:00
parent 808b0c4720
commit fe5d22a811
4 changed files with 15 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36414.22
# Visual Studio Version 18
VisualStudioVersion = 18.3.11520.95 d18.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarManagerV3", "CarManagerV3\CarManagerV3.csproj", "{93CA258B-A645-41A8-A24F-59036ABC173F}"
EndProject

View File

@@ -1,6 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<OutputType>WinExe</OutputType>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
@@ -20,6 +22,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<ApplicationIcon>CarMgm_Icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Compile Update="Forms\Components\CarCard.cs">
@@ -41,4 +44,7 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="CarMgm_Icon.ico" />
</ItemGroup>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

View File

@@ -8,12 +8,15 @@ namespace CarManagerV3
/// </summary>
internal class ImageManager
{
private static string _imagePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CarManagerV3\\images";
/// <summary>
/// Initializes the image folder by creating it if it does not exist.
/// </summary>
public static void InitializeImageFolder()
{
string path = "images";
string path = _imagePath;
if (!System.IO.Directory.Exists(path))
{
@@ -31,7 +34,7 @@ namespace CarManagerV3
/// <returns>The image path for this Car.</returns>
public static string GetImagePath(Car car)
{
string basePath = "images/";
string basePath = $"{_imagePath}/";
string fileName = $"{car.Make}_{car.Model}_{car.Year}_{car.Color}.png";
return basePath + fileName;
}
@@ -60,7 +63,7 @@ namespace CarManagerV3
}
try
{
return Image.FromFile("images/no_image_available.png");
return Image.FromFile($"{_imagePath}/no_image_available.png");
}
catch (Exception ex)
{
@@ -97,7 +100,7 @@ namespace CarManagerV3
catch
{
// if error, use fallback image no_image_available.png
System.IO.File.Copy("images/no_image_available.png", path);
//System.IO.File.Copy($"{_imagePath}/no_image_available.png", path);
}
}