-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
151 lines (130 loc) · 4.53 KB
/
Program.cs
File metadata and controls
151 lines (130 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Windows.Forms;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using FacebookPanoPrepper.Forms;
using FacebookPanoPrepper.Services;
using FacebookPanoPrepper.Models;
using System.Text.Json;
namespace FacebookPanoPrepper;
static class Program
{
[STAThread]
static void Main(string[] args)
{
var services = ConfigureServices();
if (args.Contains("--gui") || args.Length == 0)
{
ApplicationConfiguration.Initialize(); // Add this line
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try
{
var form = services.GetRequiredService<MainForm>();
Application.Run(form);
}
catch (Exception ex)
{
MessageBox.Show($"Error initializing application: {ex.Message}\n\n{ex.StackTrace}",
"Initialization Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
else
{
var processor = services.GetRequiredService<ImageProcessingService>();
RunConsoleMode(args, processor);
}
}
private static IServiceProvider ConfigureServices()
{
var services = new ServiceCollection();
// Ensure Windows Forms context is initialized
if (Application.OpenForms.Count == 0)
{
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
}
// Load settings if they exist
Settings settings;
if (File.Exists("settings.json"))
{
try
{
string json = File.ReadAllText("settings.json");
settings = JsonSerializer.Deserialize<Settings>(json) ?? new Settings();
}
catch (Exception)
{
settings = new Settings();
}
}
else
{
settings = new Settings();
}
// Create ProcessingOptions from Settings
var options = new ProcessingOptions(settings);
services.AddLogging(builder =>
{
builder.AddConsole();
builder.AddDebug();
});
services.AddSingleton(settings); // Add Settings to DI
services.AddSingleton(options); // Add ProcessingOptions to DI
services.AddSingleton<ImageProcessingService>();
services.AddTransient<MainForm>();
return services.BuildServiceProvider();
}
private static void RunConsoleMode(string[] args, ImageProcessingService processor)
{
Console.WriteLine("Facebook Pano Prepper - Console Mode");
Console.WriteLine("===================================");
if (args.Length < 1)
{
Console.WriteLine("Usage: FacebookPanoPrepper <folder_path>");
return;
}
string folderPath = args[0];
if (!Directory.Exists(folderPath))
{
Console.WriteLine("Error: Folder not found!");
return;
}
var files = Directory.GetFiles(folderPath, "*.*")
.Where(f => new[] { ".jpg", ".jpeg" }
.Contains(Path.GetExtension(f).ToLower()))
.ToList();
if (!files.Any())
{
Console.WriteLine("No JPEG images found in the specified folder.");
return;
}
Console.WriteLine($"Found {files.Count} image(s) to process.");
foreach (var file in files)
{
Console.WriteLine($"\nProcessing: {Path.GetFileName(file)}");
try
{
var outputPath = Path.Combine(
Path.GetDirectoryName(file) ?? string.Empty,
"360_" + Path.GetFileName(file)
);
var progress = new Progress<int>(percent =>
{
Console.Write($"\rProgress: {percent}%");
});
var report = processor.ProcessImageAsync(file, outputPath, progress).Result;
Console.WriteLine(report.GetSummary());
}
catch (Exception ex)
{
Console.WriteLine($"Error processing {Path.GetFileName(file)}: {ex.Message}");
}
}
Console.WriteLine("\nProcessing complete!");
}
}