mirror of
https://github.com/HamletDuFromage/aio-switch-updater.git
synced 2024-12-28 02:16:03 +00:00
Added option to clean up files and tried to add time sync
This commit is contained in:
parent
1bdda3e468
commit
7cfc2b01e5
10 changed files with 319 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,6 +6,7 @@ switch/
|
|||
*.nacp
|
||||
*.nro
|
||||
*.zip
|
||||
*.bin
|
||||
resources/i18n/zh-Hans
|
||||
resources/i18n/zh-Hant
|
||||
resources/i18n/en-GB
|
||||
|
|
|
@ -55,6 +55,16 @@
|
|||
#define UPDATE_BIN_PATH "/bootloader/update.bin"
|
||||
#define REBOOT_PAYLOAD_PATH "/atmosphere/reboot_payload.bin"
|
||||
|
||||
#define AMS_ZIP_PATH "/config/aio-switch-updater/ams.zip"
|
||||
#define APP_ZIP_PATH "/config/aio-switch-updater/app.zip"
|
||||
#define CFW_ZIP_PATH "/config/aio-switch-updater/cfw.zip"
|
||||
#define FW_ZIP_PATH "/config/aio-switch-updater/firmware.zip"
|
||||
#define CHEATS_ZIP_PATH "/config/aio-switch-updater/cheats.zip"
|
||||
#define SIGPATCHES_ZIP_PATH "/config/aio-switch-updater/sigpatches.zip"
|
||||
#define AMS_DIRECTORY_PATH "/config/aio-switch-updater/atmosphere/"
|
||||
#define SEPT_DIRECTORY_PATH "/config/aio-switch-updater/sept/"
|
||||
#define FW_DIRECTORY_PATH "/firmware/"
|
||||
|
||||
#define LISTITEM_HEIGHT 50
|
||||
|
||||
|
||||
|
|
5
include/ntcp.hpp
Normal file
5
include/ntcp.hpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string syncTime();
|
|
@ -11,6 +11,7 @@
|
|||
#include "JC_page.hpp"
|
||||
#include "extract.hpp"
|
||||
#include "utils.hpp"
|
||||
//#include "ntcp.hpp"
|
||||
|
||||
class ToolsTab : public brls::List
|
||||
{
|
||||
|
@ -22,6 +23,8 @@ class ToolsTab : public brls::List
|
|||
brls::ListItem* downloadPayload;
|
||||
brls::ListItem* changelog;
|
||||
brls::ListItem* language;
|
||||
brls::ListItem* cleanUp;
|
||||
brls::ListItem* ntcp;
|
||||
|
||||
brls::StagedAppletFrame* stagedFrame;
|
||||
|
||||
|
|
Binary file not shown.
|
@ -154,6 +154,7 @@
|
|||
"tool_extracting": "Extracting....",
|
||||
"tool_all_done": " All done!",
|
||||
"tool_changelog": "Changelog",
|
||||
"tool_cleanUp": "Clean up downloaded files",
|
||||
|
||||
"utils.cpp":"",
|
||||
"utils_because": "Because of the size of the FW archive, downloading firmwares in Applet Mode is not supported. Please launch the app with full RAM access.",
|
||||
|
|
|
@ -55,6 +55,9 @@ ChangelogPage::ChangelogPage() : AppletFrame(true, true)
|
|||
verTitles.push_back("menus/v1_3_1"_i18n );
|
||||
changes.push_back("menus/v1_3_1_text"_i18n );
|
||||
|
||||
/* verTitles.push_back("menus/v1_3_2"_i18n );
|
||||
changes.push_back("menus/v1_3_2_text"_i18n ); */
|
||||
|
||||
int nbVersions = verTitles.size();
|
||||
items.reserve(nbVersions);
|
||||
for(int i = nbVersions -1 ; i >= 0; i--){
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
namespace i18n = brls::i18n;
|
||||
using namespace i18n::literals;
|
||||
|
||||
TimeServiceType __nx_time_service_type = TimeServiceType_System;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Init the app
|
||||
|
|
254
source/ntcp.cpp
Normal file
254
source/ntcp.cpp
Normal file
|
@ -0,0 +1,254 @@
|
|||
/* This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org>
|
||||
|
||||
Additionally, the ntp_packet struct uses code licensed under the BSD 3-clause. See LICENSE-THIRD-PARTY for more information. */
|
||||
|
||||
#include "ntcp.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <time.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#define NTP_TIMESTAMP_DELTA 2208988800ull
|
||||
|
||||
/* ------------- BEGIN BSD 3-CLAUSE LICENSED CODE-------------------- */
|
||||
// https://www.cisco.com/c/en/us/about/press/internet-protocol-journal/back-issues/table-contents-58/154-ntp.html
|
||||
// Struct adapted from https://github.com/lettier/ntpclient , see LICENSE-THIRD-PARTY for more information.
|
||||
typedef struct
|
||||
{
|
||||
uint8_t li_vn_mode; // li: two bits, leap indicator. vn: three bits, protocol version number. mode: three bits, client mode.
|
||||
|
||||
uint8_t stratum; // Stratum level of the local clock.
|
||||
uint8_t poll; // Maximum interval between successive messages.
|
||||
uint8_t precision; // Precision of the local clock.
|
||||
|
||||
uint32_t rootDelay; // Total round trip delay time.
|
||||
uint32_t rootDispersion; // Max error allowed from primary clock source.
|
||||
uint32_t refId; // Reference clock identifier.
|
||||
|
||||
uint32_t refTm_s; // Reference time-stamp seconds.
|
||||
uint32_t refTm_f; // Reference time-stamp fraction of a second.
|
||||
|
||||
uint32_t origTm_s; // Originate time-stamp seconds.
|
||||
uint32_t origTm_f; // Originate time-stamp fraction of a second.
|
||||
|
||||
uint32_t rxTm_s; // Received time-stamp seconds.
|
||||
uint32_t rxTm_f; // Received time-stamp fraction of a second.
|
||||
|
||||
uint32_t txTm_s; // Transmit time-stamp seconds.
|
||||
uint32_t txTm_f; // Transmit time-stamp fraction of a second.
|
||||
} ntp_packet;
|
||||
/* ------------- END BSD 3-CLAUSE LICENSED CODE-------------------- */
|
||||
|
||||
void serviceCleanup(void)
|
||||
{
|
||||
nifmExit();
|
||||
setsysExit();
|
||||
timeExit();
|
||||
}
|
||||
|
||||
void print(const char *msg)
|
||||
{
|
||||
puts(msg);
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
|
||||
void printWithArgs(const char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
vprintf(msg, args);
|
||||
va_end(args);
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
|
||||
// We need system service access, not just user (the default)
|
||||
|
||||
std::string syncTime()
|
||||
{
|
||||
const char *server_name = "0.pool.ntp.org";
|
||||
const uint16_t port = 123;
|
||||
int sockfd = -1;
|
||||
std::stringstream out;
|
||||
|
||||
int res = 0;
|
||||
time_t tim;
|
||||
|
||||
Result rs = timeInitialize();
|
||||
if(R_FAILED(rs))
|
||||
{
|
||||
//printWithArgs("Failed to init time services, error code %x\n", rs);
|
||||
out << "Failed to init time services, error code " << rs << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
rs = nifmInitialize(NifmServiceType_User);
|
||||
if(R_FAILED(rs))
|
||||
{
|
||||
//printWithArgs("Failed to init nifm services, with error code %x\n", rs);
|
||||
out << "Failed to init nifm services, with error code " << rs << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
NifmInternetConnectionStatus nifmICS;
|
||||
rs = nifmGetInternetConnectionStatus(NULL, NULL, &nifmICS);
|
||||
if(R_FAILED(rs))
|
||||
{
|
||||
//printWithArgs("Failed to get internet connection status, with error code %x\nPlease ensure your console is connected to the internet, and try again.\n", rs);
|
||||
out << "Failed to get internet connection status, with error code " << res << ". Please ensure your console is connected to the internet, and try again." << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if(nifmICS != NifmInternetConnectionStatus_Connected)
|
||||
{
|
||||
//print("You're not connected to the internet. Please run this application again after connecting.");
|
||||
out << "You're not connected to the internet. Please run this application again after connecting." << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
ntp_packet packet;
|
||||
memset(&packet, 0, sizeof(ntp_packet));
|
||||
|
||||
packet.li_vn_mode = (0 << 6) | (4 << 3) | 3; // LI 0 | Client version 4 | Mode 3
|
||||
|
||||
packet.txTm_s = htonl(NTP_TIMESTAMP_DELTA + time(NULL)); // Current networktime on the console
|
||||
|
||||
struct sockaddr_in serv_addr;
|
||||
struct hostent *server;
|
||||
|
||||
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if(sockfd < 0)
|
||||
{
|
||||
//printWithArgs("Failed to open socket with error code %x\n", errno);
|
||||
out << "Failed to open socket with error code " << errno << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
//print("Opened socket");
|
||||
//printWithArgs("Attempting to connect to %s\n", server_name);
|
||||
errno = 0;
|
||||
if((server = gethostbyname(server_name)) == NULL)
|
||||
{
|
||||
//printWithArgs("Gethostbyname failed: %x\n", errno);
|
||||
out << "Gethostbyname failed: " << errno << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
memset(&serv_addr, 0, sizeof(struct sockaddr_in));
|
||||
|
||||
serv_addr.sin_family = AF_INET;
|
||||
|
||||
memcpy((char *)&serv_addr.sin_addr.s_addr, (char *)server->h_addr_list[0], 4);
|
||||
|
||||
serv_addr.sin_port = htons(port);
|
||||
|
||||
errno = 0;
|
||||
if((res = connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0)
|
||||
{
|
||||
//printWithArgs("Connect failed: %x %x\n", res, errno);
|
||||
out << "Connect failed: " << res << " " << errno << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
if((res = send(sockfd, (char *)&packet, sizeof(ntp_packet), 0)) < 0)
|
||||
{
|
||||
//printWithArgs("Error writing to socket: %x %x\n", res, errno);
|
||||
out << "Error writing to socket: " << res << " " << errno << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
printWithArgs("Sent time request with result: %x %x, waiting for response...\n", res, errno);
|
||||
|
||||
errno = 0;
|
||||
if((res = recv(sockfd, (char *)&packet, sizeof(ntp_packet), 0)) < sizeof(ntp_packet))
|
||||
{
|
||||
//printWithArgs("Error reading from socket: %x %x\n", res, errno);
|
||||
out << "Error reading from socket: " << res << " " << errno << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
packet.txTm_s = ntohl(packet.txTm_s);
|
||||
|
||||
tim = (time_t) (packet.txTm_s - NTP_TIMESTAMP_DELTA);
|
||||
|
||||
rs = timeSetCurrentTime(TimeType_NetworkSystemClock, (uint64_t)tim);
|
||||
if(R_FAILED(rs))
|
||||
{
|
||||
//printWithArgs("Failed to set NetworkSystemClock, %x\n", rs);
|
||||
out << "Failed to set NetworkSystemClock " << rs << std::endl;
|
||||
}
|
||||
else
|
||||
out << "Successfully set NetworkSystemClock" << std::endl;
|
||||
|
||||
rs = setsysInitialize();
|
||||
if(R_FAILED(rs))
|
||||
{
|
||||
//printWithArgs("setsysInitialize failed, %x\n", rs);
|
||||
out << "setsysInitialize failed, " << rs << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
bool internetTimeSync;
|
||||
|
||||
rs = setsysIsUserSystemClockAutomaticCorrectionEnabled(&internetTimeSync);
|
||||
if(R_FAILED(rs) || internetTimeSync == false)
|
||||
{
|
||||
//printWithArgs("Unable to detect if internet time sync is enabled, %x\n", rs);
|
||||
out << "Note: internet time sync is not enabled (enabling it will correct the time on the home screen)" << std::endl;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* if(internetTimeSync == false)
|
||||
{
|
||||
print("Internet time sync is not enabled (enabling it will correct the time on the home screen, and this prompt will not appear again).\nPress A to enable internet time sync (and restart the console), or PLUS to quit.");
|
||||
rs = setsysSetUserSystemClockAutomaticCorrectionEnabled(true);
|
||||
if(R_SUCCEEDED(rs))
|
||||
{
|
||||
serviceCleanup();
|
||||
bpcInitialize();
|
||||
bpcRebootSystem();
|
||||
bpcExit();
|
||||
}
|
||||
} */
|
||||
|
||||
done:
|
||||
|
||||
cleanup:
|
||||
if(sockfd != -1)
|
||||
close(sockfd);
|
||||
serviceCleanup();
|
||||
return out.str();
|
||||
}
|
|
@ -31,6 +31,46 @@ ToolsTab::ToolsTab(std::string tag) : brls::List()
|
|||
});
|
||||
rebootPayload->setHeight(LISTITEM_HEIGHT);
|
||||
this->addView(rebootPayload);
|
||||
|
||||
/* ntcp = new brls::ListItem("menus/ntcp"_i18n );
|
||||
ntcp->getClickEvent()->subscribe([&](brls::View* view){
|
||||
std::string res = syncTime();
|
||||
brls::Dialog* dialog = new brls::Dialog(res);
|
||||
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
|
||||
dialog->close();
|
||||
};
|
||||
dialog->addButton("menus/Ok_button"_i18n , callback);
|
||||
dialog->setCancelable(true);
|
||||
dialog->open();
|
||||
|
||||
});
|
||||
ntcp->setHeight(LISTITEM_HEIGHT);
|
||||
this->addView(ntcp); */
|
||||
|
||||
cleanUp = new brls::ListItem("menus/tool_cleanUp"_i18n );
|
||||
cleanUp->getClickEvent()->subscribe([&](brls::View* view){
|
||||
std::filesystem::remove(AMS_ZIP_PATH);
|
||||
std::filesystem::remove(APP_ZIP_PATH);
|
||||
std::filesystem::remove(CFW_ZIP_PATH);
|
||||
std::filesystem::remove(FW_ZIP_PATH);
|
||||
std::filesystem::remove(CHEATS_ZIP_PATH);
|
||||
std::filesystem::remove(SIGPATCHES_ZIP_PATH);
|
||||
std::filesystem::remove_all(AMS_DIRECTORY_PATH);
|
||||
rmdir(AMS_DIRECTORY_PATH);
|
||||
std::filesystem::remove_all(SEPT_DIRECTORY_PATH);
|
||||
rmdir(SEPT_DIRECTORY_PATH);
|
||||
std::filesystem::remove_all(FW_DIRECTORY_PATH);
|
||||
rmdir(FW_DIRECTORY_PATH);
|
||||
brls::Dialog* dialog = new brls::Dialog("menus/All_done"_i18n);
|
||||
brls::GenericEvent::Callback callback = [dialog](brls::View* view) {
|
||||
dialog->close();
|
||||
};
|
||||
dialog->addButton("menus/Ok_button"_i18n , callback);
|
||||
dialog->setCancelable(true);
|
||||
dialog->open();
|
||||
});
|
||||
cleanUp->setHeight(LISTITEM_HEIGHT);
|
||||
this->addView(cleanUp);
|
||||
|
||||
if(!tag.empty() && tag != APP_VERSION){
|
||||
updateApp = new brls::ListItem("menus/tool_update"_i18n + tag +")");
|
||||
|
|
Loading…
Reference in a new issue