-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp_logic.cpp
More file actions
200 lines (172 loc) · 7.38 KB
/
Copy pathapp_logic.cpp
File metadata and controls
200 lines (172 loc) · 7.38 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#define UNICODE // Ensure UNICODE is defined
#include "app_logic.h"
#include <windows.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <CommCtrl.h>
#include <fstream>
#include <commdlg.h>
#include <shlobj.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
// Helper function to convert std::wstring to std::string
std::string WStringToString(const std::wstring& wstr) {
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
std::string str(sizeNeeded, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], sizeNeeded, NULL, NULL);
return str;
}
// Helper function to execute a system command
bool executeCommand(const std::wstring& command) {
int result = _wsystem(command.c_str());
return result == 0;
}
void downloadFeedArchives(HWND hWnd, HWND hProgressBar, const std::wstring& feedUrl) {
std::wstring curlPath = L"bin\\curl.exe";
std::wstring outputFile = L"archives/feed_archive.zip";
std::wstring command = curlPath + L" -o " + outputFile + L" " + feedUrl;
// Set progress bar range and style for smooth progress (optional, safe to call multiple times)
if (hProgressBar) {
SendMessage(hProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
LONG_PTR style = GetWindowLongPtr(hProgressBar, GWL_STYLE);
SetWindowLongPtr(hProgressBar, GWL_STYLE, style | PBS_SMOOTH);
SendMessage(hProgressBar, PBM_SETPOS, 10, 0); // Start at 10%
}
// Simulate progress (optional, for visual feedback)
if (hProgressBar) SendMessage(hProgressBar, PBM_SETPOS, 30, 0);
int result = _wsystem(command.c_str());
if (result == 0) {
if (hProgressBar) {
SendMessage(hProgressBar, PBM_SETPOS, 100, 0); // Set to 100% on success
}
MessageBoxW(hWnd, L"Feed archives downloaded successfully.", L"Success", MB_OK);
} else {
if (hProgressBar) {
SendMessage(hProgressBar, PBM_SETPOS, 0, 0); // Reset on failure
}
MessageBoxW(hWnd, L"Failed to download feed archives.", L"Error", MB_ICONERROR);
}
}
void runTranscriber(const std::wstring& audioFilePath) {
std::wstring command = L"transcriber_tool.exe " + audioFilePath + L" > transcription.txt";
if (executeCommand(command)) {
MessageBoxW(NULL, L"Transcription completed successfully. Output saved to transcription.txt.", L"Info", MB_OK);
} else {
MessageBoxW(NULL, L"Failed to transcribe the audio file.", L"Error", MB_ICONERROR);
}
}
void trimSilence(const std::wstring& inputFile, const std::wstring& outputFile) {
std::wstring command = L"ffmpeg -i " + inputFile + L" -af silenceremove=1:0:-50dB " + outputFile;
if (executeCommand(command)) {
MessageBoxW(NULL, L"Silence trimmed successfully.", L"Info", MB_OK);
} else {
MessageBoxW(NULL, L"Failed to trim silence from the audio file.", L"Error", MB_ICONERROR);
}
}
void combineFiles(const std::wstring& outputFile, const std::vector<std::wstring>& inputFiles) {
std::wstring tempFileList = L"file_list.txt";
FILE* fileList = _wfopen(tempFileList.c_str(), L"w");
if (!fileList) {
MessageBoxW(NULL, L"Failed to create temporary file list.", L"Error", MB_ICONERROR);
return;
}
for (const auto& inputFile : inputFiles) {
fwprintf(fileList, L"file '%s'\n", inputFile.c_str());
}
fclose(fileList);
std::wstring command = L"ffmpeg -f concat -safe 0 -i " + tempFileList + L" -c copy " + outputFile;
if (executeCommand(command)) {
MessageBoxW(NULL, L"Files combined successfully.", L"Info", MB_OK);
} else {
MessageBoxW(NULL, L"Failed to combine files.", L"Error", MB_ICONERROR);
}
_wremove(tempFileList.c_str()); // Clean up temporary file
}
void listAvailableArchives(HWND hWnd, const std::wstring& feedUrl) {
std::wstring curlPath = L"bin\\curl.exe";
std::wstring tempFile = L"archives/temp_page.html";
std::wstring command = curlPath + L" -o " + tempFile + L" " + feedUrl;
if (_wsystem(command.c_str()) == 0) {
std::wifstream inputFile(tempFile);
if (!inputFile) {
MessageBoxW(hWnd, L"Failed to open the downloaded page.", L"Error", MB_ICONERROR);
return;
}
std::wstring line;
std::wstring archivesList = L"Available Archives:\n";
while (std::getline(inputFile, line)) {
size_t pos = line.find(L".zip");
if (pos != std::wstring::npos) {
size_t start = line.rfind(L"\"", pos);
size_t end = line.find(L"\"", pos);
if (start != std::wstring::npos && end != std::wstring::npos) {
archivesList += line.substr(start + 1, end - start - 1) + L"\n";
}
}
}
inputFile.close();
MessageBoxW(hWnd, archivesList.c_str(), L"Archives", MB_OK);
} else {
MessageBoxW(hWnd, L"Failed to fetch the webpage.", L"Error", MB_ICONERROR);
}
_wremove(tempFile.c_str()); // Clean up temporary file
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
static Gdiplus::Image* backgroundImage = nullptr;
switch (message) {
case WM_CREATE: {
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
backgroundImage = Gdiplus::Image::FromFile(L"bin\\bkg-demo.jpg");
break;
}
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
Gdiplus::Graphics graphics(hdc);
if (backgroundImage) {
graphics.DrawImage(backgroundImage, 0, 0, 1920, 1080);
}
Gdiplus::SolidBrush buttonBrush(Gdiplus::Color(255, 0, 122, 204));
graphics.FillRectangle(&buttonBrush, 100, 200, 300, 100);
graphics.FillRectangle(&buttonBrush, 100, 350, 300, 100);
graphics.FillRectangle(&buttonBrush, 100, 500, 300, 100);
Gdiplus::FontFamily fontFamily(L"Segoe UI");
Gdiplus::Font font(&fontFamily, 24, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
Gdiplus::SolidBrush textBrush(Gdiplus::Color(255, 255, 255, 255));
graphics.DrawString(L"List Archives", -1, &font, Gdiplus::PointF(120, 220), &textBrush);
graphics.DrawString(L"Download Archives", -1, &font, Gdiplus::PointF(120, 370), &textBrush);
graphics.DrawString(L"Transcribe Audio", -1, &font, Gdiplus::PointF(120, 520), &textBrush);
EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY: {
delete backgroundImage;
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
void presentOptions(HWND hWnd) {
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WindowProc;
wc.hInstance = GetModuleHandle(NULL);
wc.lpszClassName = L"ModernUI";
RegisterClass(&wc);
HWND hMainWnd = CreateWindowEx(
0, L"ModernUI", L"FeedFetcher", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 1920, 1080,
NULL, NULL, GetModuleHandle(NULL), NULL);
ShowWindow(hMainWnd, SW_SHOWMAXIMIZED);
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}