Skip to content

Commit

Permalink
v1.2.0 refactor api classes
Browse files Browse the repository at this point in the history
  • Loading branch information
diabolusss committed Apr 10, 2023
1 parent b567725 commit 9d7e975
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 251 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
https://stackoverflow.com/questions/1449055/disk-space-used-free-total-how-do-i-get-this-in-c
u64 free_space = ((u64)vfs.f_bsize * vfs.f_bfree); // in bytes
I guess the total space would be using vfs.f_blocks;
- TODO access m_prog_func_last_progress from *clientp @see ApiInterfaceImpl

## [1.2.0] - 2023-04-10

### Changed

- REFACTOR# move api methods into classes

## [1.1.9] - 2023-04-08

Expand Down
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(PSL1GHT)),)
$(error "Please set PSL1GHT in your environment. export PSL1GHT=<path>")
$(error "Please set PSL1GHT in your environment. export PSL1GHT=<path>")
else
include $(PSL1GHT)/ppu_rules
endif

include $(PSL1GHT)/ppu_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
Expand All @@ -47,6 +47,8 @@ TITLE := PS3 Cloud Sync
APPID := PSCS00001
CONTENTID := CS0001-$(APPID)_00-0000000000000000

$(eval ZIPPER := $(TARGET)_$(shell mktemp -u XXXXXXX))

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
Expand Down Expand Up @@ -145,6 +147,14 @@ run:

#---------------------------------------------------------------------------------
pkg: $(BUILD) $(OUTPUT).pkg

#---------------------------------------------------------------------------------
tar:
tar cfv $(ZIPPER).tar $(SOURCES)/* \
Makefile
zip:
zip $(ZIPPER).zip $(SOURCES)/* \
Makefile

#---------------------------------------------------------------------------------
else
Expand Down
Binary file modified ps3-cloud-drive.pkg
Binary file not shown.
Binary file modified ps3-cloud-drive.self
Binary file not shown.
4 changes: 2 additions & 2 deletions sfo.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" ?>
<sfo>
<value name="APP_VER" type="string">
01.19
01.20
</value>
<value name="ATTRIBUTE" type="integer">
1
Expand Down Expand Up @@ -34,6 +34,6 @@
PS3CLSC
</value>
<value name="VERSION" type="string">
01.19
01.20
</value>
</sfo>
61 changes: 61 additions & 0 deletions source/ApiInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <sys/systime.h> //sysUsleep
#include "ApiInterface.h"
#include "log.h"

bool APIInterface::ShouldRetryCheck( long response )
{
// HTTP 500 and 503 should be temperory. just wait a bit and retry
if ( response == 500 || response == 503 )
{
debugPrintf("Request failed due to temporary error: %d, retrying in 5 seconds\n",response);

sysUsleep(5);
return true ;
}

// HTTP 401 Unauthorized. the auth token has been expired. refresh it
else if ( response == 401 )
{
debugPrintf("Request failed due to Auth token expired: %d. refreshing token\n",response);

m_auth_token->Refresh() ;
return true ;
}
else
{
debugPrintf("OAuth2 session ok, continue... %d\n",response);
return false ;
}
}

//TODO access m_prog_func_last_progress from *clientp
/*int APIInterface::transferProgress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
{
if(dltotal > 0.0)
{
double curProg = (dlnow / dltotal) * 100;
if(curProg - m_prog_func_last_progress > 1)
{
msgDialogProgressBarInc(MSG_PROGRESSBAR_INDEX1, curProg - m_prog_func_last_progress);
debugPrintf("DOWN: %f of %f P: %f C: %f\r\n", dlnow, dltotal, m_prog_func_last_progress, curProg);
m_prog_func_last_progress = curProg;
}
}
if(ultotal > 0.0)
{
double curProg = (ulnow / ultotal) * 100;
if(curProg - m_prog_func_last_progress > 1)
{
msgDialogProgressBarInc(MSG_PROGRESSBAR_INDEX1, curProg - m_prog_func_last_progress);
debugPrintf("UP: %f of %f P: %f C: %f\r\n", ulnow, ultotal, m_prog_func_last_progress,curProg);
m_prog_func_last_progress = curProg;
}
}
return 0;
}*/
55 changes: 55 additions & 0 deletions source/ApiInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma once

#include <string>
#include <sysutil/msg.h> //msgDialogProgress...

#include "Json.h"
#include "Download.h"
#include "Header.h"

#include "CurlAgent.h"
#include "OAuth2.h"

class APIInterface {
public:
double m_prog_func_last_progress;

const std::string *m_api_key_map;
const std::string m_client_id;
const std::string m_client_secret;
const std::string m_token_url;
const std::string m_device_url;
OAuth2* m_auth_token;
CurlAgent http;

Json m_remote_resource_root;

APIInterface(
std::string _client_id,
std::string _client_secret,
std::string _token_url,
std::string _device_url
):

m_client_id(_client_id),
m_client_secret(_client_secret),
m_token_url(_token_url),
m_device_url(_device_url)
{}

void init(){
m_auth_token = new OAuth2(m_token_url, m_device_url, m_client_id, m_client_secret, m_api_key_map);
}

bool ShouldRetryCheck( long response );
//TODO *clientp - possible to pass api or just pointer to double status; @see https://github.com/curl/curl/issues/806
//int transferProgress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);

//api specific methods
virtual Json checkIfRemoteResourceExists(std::string resourceTitle,std::string mimeType,std::string parentId) = 0;
virtual Json::Array getResourcesUnderFolder(std::string parentId) = 0;
virtual bool downloadFile(std::string localPath, std::string fileId) = 0;
virtual void downloadChanges(int *dialog_action) = 0;
virtual Json uploadFile(std::string path, std::string filename, std::string mimeType, std::string parentId, std::string fileId = "") = 0;
virtual Json uploadDirectory(std::string dirName, std::string parentId) = 0;
};
Loading

0 comments on commit 9d7e975

Please sign in to comment.