Skip to content

Commit 9e1708d

Browse files
committed
preliminary file saving code
1 parent f976ab5 commit 9e1708d

File tree

10 files changed

+146
-134
lines changed

10 files changed

+146
-134
lines changed

data/images/launchMenuBox.png

257 KB
Loading

hbas.elf

271 KB
Binary file not shown.

hbas_dbg.elf

275 KB
Binary file not shown.

src/gui/GuiButton.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ void GuiButton::update(GuiController * c)
282282
clearState(STATE_CLICKED, c->chan);
283283
}
284284
heldTrigger = NULL;
285-
// clearState(STATE_HELD, c->chan);
286-
// released(this, c, trigger[i]);
285+
clearState(STATE_HELD, c->chan);
286+
released(this, c, trigger[i]);
287287
}
288288
}
289289
}

src/menu/HomebrewLaunchWindow.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,31 @@
2121
#include "utils/HomebrewXML.h"
2222
#include "Application.h"
2323
#include "dynamic_libs/sys_functions.h"
24+
#include "network/FileDownloader.h"
2425

25-
HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiImageData * iconImgData)
26+
HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiImageData * iconImgData, std::string & shortname)
2627
: GuiFrame(0, 0)
2728
, buttonClickSound(Resources::GetSound("button_click.mp3"))
2829
, backgroundImgData(Resources::GetImageData("launchMenuBox.png"))
2930
, backgroundImg(backgroundImgData)
3031
, buttonImgData(Resources::GetImageData("button.png"))
3132
, iconImage(iconImgData)
32-
, titleText((char*)NULL, 42, glm::vec4(1.0f))
33-
, versionText("Version:", 32, glm::vec4(1.0f))
34-
, versionValueText((char*)NULL, 32, glm::vec4(1.0f))
35-
, authorText("Author:", 32, glm::vec4(1.0f))
36-
, authorValueText((char*)NULL, 32, glm::vec4(1.0f))
37-
, descriptionText((char*)NULL, 28, glm::vec4(1.0f))
38-
, loadBtnLabel("Load", 32, glm::vec4(1.0f))
33+
, titleText((char*)NULL, 42, glm::vec4(0,0,0, 1))
34+
, versionText("Version:", 32, glm::vec4(0,0,0, 1))
35+
, versionValueText((char*)NULL, 32, glm::vec4(0,0,0, 1))
36+
, authorText("Author:", 32, glm::vec4(0,0,0, 1))
37+
, authorValueText((char*)NULL, 32, glm::vec4(0,0,0, 1))
38+
, descriptionText((char*)NULL, 28, glm::vec4(0,0,0, 1))
39+
, loadBtnLabel("Download", 32, glm::vec4(1.0f))
3940
, loadImg(buttonImgData)
4041
, loadBtn(loadImg.getWidth(), loadImg.getHeight())
41-
, backBtnLabel("Back", 32, glm::vec4(1.0f))
42+
, backBtnLabel("Close", 32, glm::vec4(1.0f))
4243
, backImg(buttonImgData)
4344
, backBtn(backImg.getWidth(), backImg.getHeight())
4445
, touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
4546
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
4647
, homebrewLaunchPath(launchPath)
48+
, homebrewLaunchName(shortname)
4749
{
4850
width = backgroundImg.getWidth();
4951
height = backgroundImg.getHeight();
@@ -180,6 +182,9 @@ void HomebrewLaunchWindow::OnLoadButtonClick(GuiButton *button, const GuiControl
180182
{
181183
backBtn.setState(GuiElement::STATE_DISABLED);
182184
loadBtn.setState(GuiElement::STATE_DISABLED);
185+
186+
FileDownloader::getFile("http://wiiubru.com/appstore/apps/"+homebrewLaunchName+"/boot.elf", "sd:/wiiu/apps/"+homebrewLaunchName+"/boot.elf", 0);
187+
183188

184189
// struct SYSBrowserArgsIn args = {};
185190
// std::string url = "http://vgmoose.com";

src/menu/HomebrewLaunchWindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class HomebrewLaunchWindow : public GuiFrame, public sigslot::has_slots<>
2424
{
2525
public:
26-
HomebrewLaunchWindow(const std::string & launchPath, GuiImageData * iconImgData);
26+
HomebrewLaunchWindow(const std::string & launchPath, GuiImageData * iconImgData, std::string & shortname);
2727
virtual ~HomebrewLaunchWindow();
2828

2929

@@ -66,6 +66,7 @@ class HomebrewLaunchWindow : public GuiFrame, public sigslot::has_slots<>
6666
GuiTrigger wpadTouchTrigger;
6767

6868
const std::string homebrewLaunchPath;
69+
const std::string homebrewLaunchName;
6970
};
7071

7172
#endif //_HOMEBREW_LAUNCHER_WINDOW_H_

src/menu/HomebrewWindow.cpp

Lines changed: 104 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -173,105 +173,110 @@ HomebrewWindow::HomebrewWindow(int w, int h)
173173
std::string fileContents;
174174
std::string targetUrl = std::string("http://wiiubru.com/appstore/directory.yaml");
175175
FileDownloader::getFile(targetUrl, fileContents);
176-
177176
std::istringstream f(fileContents);
178-
std::string shortname;
179-
std::getline(f, shortname);
180-
shortname = shortname.substr(5);
181-
std::string name;
182-
std::getline(f, name);
183-
name = name.substr(2);
184-
std::string author;
185-
std::getline(f, author);
186-
author = author.substr(2);
187-
std::string desc;
188-
std::getline(f, desc);
189-
desc = desc.substr(2);
190-
std::string binary;
191-
std::getline(f, binary);
192-
binary = binary.substr(2);
193-
194-
int idx = homebrewButtons.size();
195-
homebrewButtons.resize(homebrewButtons.size() + 1);
196-
197-
// file path
198-
homebrewButtons[idx].execPath = "n";
199-
homebrewButtons[idx].iconImgData = NULL;
200-
201-
std::string homebrewPath = homebrewButtons[idx].execPath;
202-
size_t slashPos = homebrewPath.rfind('/');
203-
if(slashPos != std::string::npos)
204-
homebrewPath.erase(slashPos);
205-
206-
u8 * iconData = NULL;
207-
u32 iconDataSize = 0;
208-
209-
homebrewButtons[idx].dirPath = homebrewPath;
210-
211-
// since we got this app from the sd card, mark it local for now.
212-
// if we see it later on the server, update its status appropriately to
213-
// update or installed
214-
homebrewButtons[idx].status = GET;
215-
216-
// download app list from wiiubru
217-
std::string targetIcon;
218-
std::string targetIconUrl = std::string("http://wiiubru.com/appstore/apps/" + shortname + "/icon.png");
219-
FileDownloader::getFile(targetIconUrl, targetIcon);
220-
221-
// if(targetIcon != NULL)
222-
// {
223-
homebrewButtons[idx].iconImgData = new GuiImageData((u8*)targetIcon.c_str(), targetIcon.size());
224-
// free(iconData);
225-
// }
226-
227-
const float cfImageScale = 1.0f;
228-
229-
homebrewButtons[idx].iconImg = new GuiImage(homebrewButtons[idx].iconImgData);
230-
homebrewButtons[idx].iconImg->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
231-
homebrewButtons[idx].iconImg->setPosition(60, 0);
232-
homebrewButtons[idx].iconImg->setScale(cfImageScale);
233-
234-
HomebrewXML metaXml;
235177

236-
// bool xmlReadSuccess = metaXml.LoadHomebrewXMLData((homebrewPath + "/meta.xml").c_str());
237-
238-
const char *cpName = name.c_str();
239-
const char *cpDescription = desc.c_str();
240-
241-
if(strncmp(cpName, "sd:/wiiu/apps/", strlen("sd:/wiiu/apps/")) == 0)
242-
cpName += strlen("sd:/wiiu/apps/");
243-
244-
homebrewButtons[idx].nameLabel = new GuiText(cpName, 32, glm::vec4(0, 0, 0, 1));
245-
homebrewButtons[idx].nameLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
246-
homebrewButtons[idx].nameLabel->setMaxWidth(350, GuiText::SCROLL_HORIZONTAL);
247-
homebrewButtons[idx].nameLabel->setPosition(256 + 80, 20);
248-
249-
homebrewButtons[idx].descriptionLabel = new GuiText(cpDescription, 32, glm::vec4(0, 0, 0, 1));
250-
homebrewButtons[idx].descriptionLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
251-
homebrewButtons[idx].descriptionLabel->setMaxWidth(350, GuiText::SCROLL_HORIZONTAL);
252-
homebrewButtons[idx].descriptionLabel->setPosition(256 + 80, -20);
253-
254-
homebrewButtons[idx].button = new GuiButton(installedButtonImgData->getWidth(), installedButtonImgData->getHeight());
255-
256-
// set the right image for the status
257-
homebrewButtons[idx].image = new GuiImage(appButtonImages[homebrewButtons[idx].status]);
258-
homebrewButtons[idx].image->setScale(0.9f);
259-
260-
homebrewButtons[idx].button->setImage(homebrewButtons[idx].image);
261-
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].nameLabel, 0);
262-
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].descriptionLabel, 1);
263-
homebrewButtons[idx].button->setIcon(homebrewButtons[idx].iconImg);
264-
float fXOffset = 0;
265-
float fYOffset = scrollOffY + (homebrewButtons[idx].image->getHeight() + 20.0f) * 1.5f - (homebrewButtons[idx].image->getHeight() + 20) * (idx);
266-
homebrewButtons[idx].button->setPosition(currentLeftPosition + fXOffset, fYOffset);
267-
homebrewButtons[idx].button->setTrigger(&touchTrigger);
268-
homebrewButtons[idx].button->setTrigger(&wpadTouchTrigger);
269-
homebrewButtons[idx].button->setEffectGrow();
270-
// homebrewButtons[idx].button->setSoundClick(buttonClickSound);
271-
homebrewButtons[idx].button->clicked.connect(this, &HomebrewWindow::OnHomebrewButtonClick);
272-
273-
append(homebrewButtons[idx].button);
274-
178+
// int loops = 0;
179+
// int i2;
180+
while (true)
181+
{
182+
std::string shortname;
183+
184+
if (!std::getline(f, shortname)) break;
185+
shortname = shortname.substr(5);
186+
std::string name;
187+
std::getline(f, name);
188+
name = name.substr(2);
189+
std::string author;
190+
std::getline(f, author);
191+
author = author.substr(2);
192+
std::string desc;
193+
std::getline(f, desc);
194+
desc = desc.substr(2);
195+
std::string binary;
196+
std::getline(f, binary);
197+
binary = binary.substr(2);
198+
199+
int idx = homebrewButtons.size();
200+
homebrewButtons.resize(homebrewButtons.size() + 1);
201+
202+
// file path
203+
homebrewButtons[idx].execPath = "";
204+
homebrewButtons[idx].iconImgData = NULL;
205+
206+
std::string homebrewPath = homebrewButtons[idx].execPath;
207+
size_t slashPos = homebrewPath.rfind('/');
208+
if(slashPos != std::string::npos)
209+
homebrewPath.erase(slashPos);
210+
211+
u8 * iconData = NULL;
212+
u32 iconDataSize = 0;
213+
214+
homebrewButtons[idx].dirPath = homebrewPath;
215+
216+
// since we got this app from the sd card, mark it local for now.
217+
// if we see it later on the server, update its status appropriately to
218+
// update or installed
219+
homebrewButtons[idx].status = GET;
220+
homebrewButtons[idx].shortname = shortname;
221+
// download app list from wiiubru
222+
std::string targetIcon;
223+
std::string targetIconUrl = std::string("http://wiiubru.com/appstore/apps/" + shortname + "/icon.png");
224+
FileDownloader::getFile(targetIconUrl, targetIcon);
225+
226+
// if(targetIcon != NULL)
227+
// {
228+
homebrewButtons[idx].iconImgData = new GuiImageData((u8*)targetIcon.c_str(), targetIcon.size());
229+
// free(iconData);
230+
// }
231+
232+
const float cfImageScale = 1.0f;
233+
234+
homebrewButtons[idx].iconImg = new GuiImage(homebrewButtons[idx].iconImgData);
235+
homebrewButtons[idx].iconImg->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
236+
homebrewButtons[idx].iconImg->setPosition(60, 0);
237+
homebrewButtons[idx].iconImg->setScale(cfImageScale);
238+
239+
HomebrewXML metaXml;
240+
241+
// bool xmlReadSuccess = metaXml.LoadHomebrewXMLData((homebrewPath + "/meta.xml").c_str());
242+
243+
const char *cpName = name.c_str();
244+
const char *cpDescription = desc.c_str();
245+
246+
if(strncmp(cpName, "sd:/wiiu/apps/", strlen("sd:/wiiu/apps/")) == 0)
247+
cpName += strlen("sd:/wiiu/apps/");
248+
249+
homebrewButtons[idx].nameLabel = new GuiText(cpName, 32, glm::vec4(0, 0, 0, 1));
250+
homebrewButtons[idx].nameLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
251+
homebrewButtons[idx].nameLabel->setMaxWidth(350, GuiText::SCROLL_HORIZONTAL);
252+
homebrewButtons[idx].nameLabel->setPosition(256 + 80, 20);
253+
254+
homebrewButtons[idx].descriptionLabel = new GuiText(cpDescription, 32, glm::vec4(0, 0, 0, 1));
255+
homebrewButtons[idx].descriptionLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
256+
homebrewButtons[idx].descriptionLabel->setMaxWidth(350, GuiText::SCROLL_HORIZONTAL);
257+
homebrewButtons[idx].descriptionLabel->setPosition(256 + 80, -20);
258+
259+
homebrewButtons[idx].button = new GuiButton(installedButtonImgData->getWidth(), installedButtonImgData->getHeight());
260+
261+
// set the right image for the status
262+
homebrewButtons[idx].image = new GuiImage(appButtonImages[homebrewButtons[idx].status]);
263+
homebrewButtons[idx].image->setScale(0.9f);
264+
265+
homebrewButtons[idx].button->setImage(homebrewButtons[idx].image);
266+
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].nameLabel, 0);
267+
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].descriptionLabel, 1);
268+
homebrewButtons[idx].button->setIcon(homebrewButtons[idx].iconImg);
269+
float fXOffset = 0;
270+
float fYOffset = scrollOffY + (homebrewButtons[idx].image->getHeight() + 20.0f) * 1.5f - (homebrewButtons[idx].image->getHeight() + 20) * (idx);
271+
homebrewButtons[idx].button->setPosition(currentLeftPosition + fXOffset, fYOffset);
272+
homebrewButtons[idx].button->setTrigger(&touchTrigger);
273+
homebrewButtons[idx].button->setTrigger(&wpadTouchTrigger);
274+
homebrewButtons[idx].button->setEffectGrow();
275+
// homebrewButtons[idx].button->setSoundClick(buttonClickSound);
276+
homebrewButtons[idx].button->clicked.connect(this, &HomebrewWindow::OnHomebrewButtonClick);
277+
278+
append(homebrewButtons[idx].button);
279+
}
275280

276281
// while (std::getline(f, line)) {
277282
// if (!strncmp(str, substr, strlen("app: "))) {
@@ -359,13 +364,13 @@ void HomebrewWindow::OnLaunchBoxCloseClick(GuiElement *element)
359364
void HomebrewWindow::OnHomebrewButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
360365
{
361366
bool disableButtons = false;
362-
return;
367+
// return;
363368

364369
for(u32 i = 0; i < homebrewButtons.size(); i++)
365370
{
366371
if(button == homebrewButtons[i].button)
367372
{
368-
HomebrewLaunchWindow * launchBox = new HomebrewLaunchWindow(homebrewButtons[i].execPath, homebrewButtons[i].iconImgData);
373+
HomebrewLaunchWindow * launchBox = new HomebrewLaunchWindow(homebrewButtons[i].execPath, homebrewButtons[i].iconImgData, homebrewButtons[i].shortname);
369374
launchBox->setEffect(EFFECT_FADE, 10, 255);
370375
launchBox->setState(GuiElement::STATE_DISABLED);
371376
launchBox->setPosition(0.0f, 30.0f);

src/menu/HomebrewWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class HomebrewWindow : public GuiFrame, public sigslot::has_slots<>
3939
GuiText *descriptionLabel;
4040
GuiImageData *iconImgData;
4141
GuiImage *iconImg;
42+
std::string shortname;
4243
int status;
4344
std::string dirPath;
4445
} homebrewButton;

src/network/FileDownloader.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,28 @@ bool FileDownloader::getFile(const std::string & downloadUrl, std::string & file
4444
return result;
4545
}
4646

47-
//bool FileDownloader::getFile(const std::string & downloadUrl, const std::string & outputPath, ProgressCallback callback, void *arg)
48-
//{
49-
// curl_private_data_t private_data;
50-
// private_data.progressCallback = callback;
51-
// private_data.progressArg = arg;
52-
// private_data.buffer = 0;
53-
// private_data.filesize = 0;
54-
// private_data.file = new CFile(outputPath.c_str(), CFile::WriteOnly);
55-
//
56-
// if(!private_data.file->isOpen())
57-
// {
58-
// delete private_data.file;
59-
// log_printf("Can not write to file %s\n", outputPath.c_str());
60-
// return false;
61-
// }
62-
//
63-
// bool result = internalGetFile(downloadUrl, &private_data);
64-
//
65-
// private_data.file->close();
66-
// delete private_data.file;
67-
// return result;
68-
//}
47+
bool FileDownloader::getFile(const std::string & downloadUrl, const std::string & outputPath, ProgressCallback callback, void *arg)
48+
{
49+
curl_private_data_t private_data;
50+
private_data.progressCallback = callback;
51+
private_data.progressArg = arg;
52+
private_data.buffer = 0;
53+
private_data.filesize = 0;
54+
private_data.file = new CFile(outputPath.c_str(), CFile::WriteOnly);
55+
56+
if(!private_data.file->isOpen())
57+
{
58+
delete private_data.file;
59+
log_printf("Can not write to file %s\n", outputPath.c_str());
60+
return false;
61+
}
62+
63+
bool result = internalGetFile(downloadUrl, &private_data);
64+
65+
private_data.file->close();
66+
delete private_data.file;
67+
return result;
68+
}
6969

7070

7171
bool FileDownloader::internalGetFile(const std::string & downloadUrl, curl_private_data_t * private_data)

src/network/FileDownloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FileDownloader
2626
typedef void (*ProgressCallback)(void *arg, u32 done, u32 total);
2727

2828
static bool getFile(const std::string & downloadUrl, std::string & fileBuffer, ProgressCallback callback = 0, void *arg = 0);
29-
// static bool getFile(const std::string & downloadUrl, const std::string & outputPath, ProgressCallback callback = 0, void *arg = 0);
29+
static bool getFile(const std::string & downloadUrl, const std::string & outputPath, ProgressCallback callback = 0, void *arg = 0);
3030
private:
3131
typedef struct
3232
{

0 commit comments

Comments
 (0)