generated from WerWolv/Tesla-Template
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.cpp
More file actions
107 lines (91 loc) · 3.06 KB
/
main.cpp
File metadata and controls
107 lines (91 loc) · 3.06 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
/*
* Copyright (c) 2020 Behemoth
*
* This file is part of ShareNX.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define TESLA_INIT_IMPL
#include <curl/curl.h>
#include "gui_error.hpp"
#include "gui_main.hpp"
#include "image_item.hpp"
#define R_INIT(cmd, message) \
rc = cmd; \
if (R_FAILED(rc)) { \
msg = message; \
return; \
}
constexpr const SocketInitConfig sockConf = {
.tcp_tx_buf_size = 0x800,
.tcp_rx_buf_size = 0x800,
.tcp_tx_buf_max_size = 0x25000,
.tcp_rx_buf_max_size = 0x25000,
.udp_tx_buf_size = 0,
.udp_rx_buf_size = 0,
.sb_efficiency = 1,
.num_bsd_sessions = 0,
.bsd_service_type = BsdServiceType_Auto,
};
static u8 img[THUMB_SIZE];
class ShareOverlay : public tsl::Overlay {
private:
Result rc = 0;
const char *msg = nullptr;
CapsAlbumFileId fileId;
public:
virtual void initServices() override {
R_INIT(socketInitialize(&sockConf), "Failed to init socket!")
R_INIT(capsaInitialize(), "Failed to init capture service!");
u64 size;
rc = capsaGetLastOverlayScreenShotThumbnail(&this->fileId, &size, img, THUMB_SIZE);
if (R_FAILED(rc) || size == 0 || this->fileId.application_id == 0) {
msg = "No screenshot taken!";
return;
}
u8 *work = new (std::nothrow) u8[WORK_SIZE];
if (work == nullptr) {
msg = "Out of memory!";
return;
}
tsl::hlp::ScopeGuard work_guard([work] { delete[] work; });
u64 w, h;
rc = capsaLoadAlbumScreenShotThumbnailImage(&w, &h, &this->fileId, img, THUMB_SIZE, work, WORK_SIZE);
if (R_FAILED(rc) || w != THUMB_WIDTH || h != THUMB_HEIGHT) {
msg = "CapSrv error!";
return;
}
if (CURLE_OK != curl_global_init(CURL_GLOBAL_DEFAULT)) {
msg = "curl_global_init error!";
}
}
virtual void exitServices() override {
curl_global_cleanup();
capsaExit();
socketExit();
}
virtual void onShow() override {}
virtual void onHide() override {}
virtual std::unique_ptr<tsl::Gui> loadInitialGui() override {
if (R_FAILED(rc)) {
return std::make_unique<ErrorGui>(rc);
} else if (msg != nullptr) {
return std::make_unique<ErrorGui>(msg);
} else {
return std::make_unique<MainGui>(this->fileId, img);
}
}
};
int main(int argc, char **argv) {
return tsl::loop<ShareOverlay>(argc, argv);
}