Skip to content

Commit

Permalink
no longer crashes immediately on get, but has some more... subtle issues
Browse files Browse the repository at this point in the history
1. downloading is re-enabled, but sometimes just stops working and a hard reboot is needed
2. app refreshing is disabled (which may be why #1 happens), as a result deleting/downloading something won't look like it worked until home is pressed
3. aaaaaaaaaaaaaaaaaaaaaaa
  • Loading branch information
vgmoose committed Jul 1, 2016
1 parent 976ebe5 commit e8475ae
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 115 deletions.
Binary file modified hbas.elf
Binary file not shown.
Binary file modified hbas_dbg.elf
Binary file not shown.
1 change: 0 additions & 1 deletion src/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "system/CThread.h"

extern const char* repoUrl;
//static const char* repoUrl = "192.168.1.103:8000";

class Application : public CThread
{
Expand Down
155 changes: 77 additions & 78 deletions src/menu/HomebrewLaunchWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ HomebrewLaunchWindow::HomebrewLaunchWindow(homebrewButton & thisButton, Homebrew

HomebrewXML metaXml;
bool xmlReadSuccess = metaXml.LoadHomebrewXMLData((homebrewPath + "/meta.xml").c_str());

// if GET or UDPATE, fetch xml from server
if (selectedButton->status == GET || selectedButton->status == UPDATE)
{
Expand Down Expand Up @@ -233,123 +233,122 @@ void HomebrewLaunchWindow::OnFileLoadFinish(GuiElement *element, const std::stri
element->setEffect(EFFECT_FADE, -10, 0);
element->effectFinished.connect(this, &HomebrewLaunchWindow::OnCloseEffectFinish);

if(result > 0)
{
u32 ApplicationMemoryEnd;
asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" : "=r" (ApplicationMemoryEnd));

ELF_DATA_ADDR = ApplicationMemoryEnd;
ELF_DATA_SIZE = result;
Application::instance()->quit(EXIT_SUCCESS);
}
// if(result > 0)
// {
// u32 ApplicationMemoryEnd;
// asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" : "=r" (ApplicationMemoryEnd));
//
// ELF_DATA_ADDR = ApplicationMemoryEnd;
// ELF_DATA_SIZE = result;
// Application::instance()->quit(EXIT_SUCCESS);
// }
}

void HomebrewLaunchWindow::OnDeleteButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
{
std::string removePath = selectedButton->dirPath;

// if the remove path is the whole directory, stop!
if (!removePath.compare(std::string("sd:/wiiu/apps")) || !removePath.compare(std::string("sd:/wiiu/apps/")))
return;
else
{
// remove the files in the directory and the directory
// remove the files in the directory
DirList dirList(removePath, 0, DirList::Files | DirList::CheckSubfolders);
for (int x=0; x<dirList.GetFilecount(); x++)
remove(dirList.GetFilepath(x));

// now remove the directory
rmdir(removePath.c_str());
}

// if (launchWindowTarget != 0)
// removeE(launchWindowTarget);

// close the window
OnBackButtonClick(button, controller, trigger);

// refresh
globalRefreshHomebrewApps();
// pThread = CThread::create(asyncRefreshHomebrewApps, NULL, CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 10);
// pThread->resumeThread();
// refresh main directory (crashes at the moment)
// globalRefreshHomebrewApps();

}

/**
This method is invoked after green is pressed, and is in a separate thread
so that the animation of the progress bar can be controlled.
The main issue with tis function is it needs some variables passed in order
to fetch them. Currently this is done by attaching variables to the singleton
instance of HomebrewWindow, which was set up at start.
**/
static void asyncDownloadTargetedFiles(CThread* thread, void* args)
{

// ProgressWindow * progress = getProgressWindow();
// progress->setProgress(0);
//
// HomebrewLaunchWindow* curLaunchWindow = launchWindowTarget;
//
// std::string mRepoUrl = std::string(repoUrl);
//
// progress->setTitle("Downloading " + sdPathTarget+"/"+binaryTarget + "...");
// FileDownloader::getFile(mRepoUrl+pathTarget+"/"+binaryTarget, sdPathTarget+"/"+binaryTarget, &updateProgress);
//
// progress->setTitle("Downloading " + sdPathTarget+"/meta.xml...");
// FileDownloader::getFile(mRepoUrl+pathTarget+"/meta.xml", sdPathTarget+"/meta.xml", &updateProgress);
//
// progress->setTitle("Downloading " + sdPathTarget+"/icon.png...");
// FileDownloader::getFile(mRepoUrl+pathTarget+"/icon.png", sdPathTarget+"/icon.png", &updateProgress);
//
// curLaunchWindow->removeE(progress);
//
// homebrewWindowTarget = getHomebrewWindow();
//
// // close the window
// homebrewWindowTarget->removeE(curLaunchWindow);
//
// curLaunchWindow->OnBackButtonClick(buttonTarget, controllerTarget, triggerTarget);
//
// // refresh
// Set the progress bar to 0%
ProgressWindow * progress = getProgressWindow();
progress->setProgress(0);

// get the homebrew window, which holds variables we need access to
HomebrewWindow * homebrewWindowTarget = getHomebrewWindow();

// convert the repo url into a std::string
std::string mRepoUrl = std::string(repoUrl);

// three previously stored variables that are used belong to know which files to download
std::string sdPathTarget = homebrewWindowTarget->sdPathTarget;
std::string binaryTarget = homebrewWindowTarget->binaryTarget;
std::string pathTarget = homebrewWindowTarget->pathTarget;

// download the elf to sd card, and update the progres bar description
progress->setTitle("Downloading " + sdPathTarget + "/" + binaryTarget + "...");
FileDownloader::getFile(mRepoUrl+pathTarget+"/"+binaryTarget, sdPathTarget+"/"+binaryTarget, &updateProgress);

// download meta.xml to sd card, and update the progres bar description
progress->setTitle("Downloading " + sdPathTarget+"/meta.xml...");
FileDownloader::getFile(mRepoUrl+pathTarget+"/meta.xml", sdPathTarget+"/meta.xml", &updateProgress);

// download the app image icon for this app. (If the icon download is interrupted,
// HBL may crash when it tries to read it
progress->setTitle("Downloading " + sdPathTarget+"/icon.png...");
FileDownloader::getFile(mRepoUrl+pathTarget+"/icon.png", sdPathTarget+"/icon.png", &updateProgress);

// remove the progress bar
homebrewWindowTarget->removeE(progress);

// refresh main directory (crashes at the moment)
// globalRefreshHomebrewApps();
}

/**
This method is called when the gren GET button is pushed. It is on the main thread, and
spawns another thread to handle the downloading in the background.
**/
void HomebrewLaunchWindow::OnLoadButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
{
// disable the buttons
delBtn.setState(GuiElement::STATE_DISABLED);
loadBtn.setState(GuiElement::STATE_DISABLED);
backBtn.setState(GuiElement::STATE_DISABLED);
// backBtn.setState(GuiElement::STATE_DISABLED);
updateBtn.setState(GuiElement::STATE_DISABLED);
reinstallBtn.setState(GuiElement::STATE_DISABLED);

// setup the paths based on the selected button
std::string path = "/apps/"+selectedButton->shortname;
std::string sdPath = "sd:/wiiu"+path;
CreateSubfolder(sdPath.c_str());
ProgressWindow * progress = getProgressWindow();
append(progress);

std::string fullName = selectedButton->shortname;

// fullNameTarget = fullName;
// binaryTarget = selectedButton->binary;
// pathTarget = path;
// sdPathTarget = sdPath;
// buttonTarget = button;
// controllerTarget = controller;
// triggerTarget = trigger;

// removeETarget = &HomebrewLaunchWindow::removeE;
// create a new directory on sd
CreateSubfolder(sdPath.c_str());

// if (launchWindowTarget != 0)
// removeE(launchWindowTarget);
// launchWindowTarget = this;
// get progress window and homebrew window, add progress to view
ProgressWindow * progress = getProgressWindow();
HomebrewWindow * homebrewWindowTarget = getHomebrewWindow();
homebrewWindowTarget->append(progress);

// store information about the desired files to homebrewWindowTarget, so that
// the thread can access it
homebrewWindowTarget->sdPathTarget = sdPath;
homebrewWindowTarget->pathTarget = path;
homebrewWindowTarget->binaryTarget = selectedButton->binary;

// download target files
// Create a new thread to do the downloading it, so the prgress bar can be updated
CThread * pThread = CThread::create(asyncDownloadTargetedFiles, NULL, CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 10);
pThread->resumeThread();

// struct SYSBrowserArgsIn args = {};
// std::string url = "http://vgmoose.com";
// args.url = url.c_str();
// args.urlSize = url.size();
// SYSSwitchToBrowser(&args);


// u32 ApplicationMemoryEnd;
// asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" : "=r" (ApplicationMemoryEnd));

// HomebrewLoader * loader = HomebrewLoader::loadToMemoryAsync(homebrewLaunchPath, (unsigned char*)ApplicationMemoryEnd);
// loader->setEffect(EFFECT_FADE, 15, 255);
// loader->effectFinished.connect(this, &HomebrewLaunchWindow::OnOpenEffectFinish);
// loader->asyncLoadFinished.connect(this, &HomebrewLaunchWindow::OnFileLoadFinish);
// append(loader);
}
2 changes: 1 addition & 1 deletion src/menu/HomebrewLaunchWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
//typedef void (GuiFrame::*fn)(GuiElement*);
//static fn removeETarget;


class HomebrewLaunchWindow : public GuiFrame, public sigslot::has_slots<>
{
public:
Expand All @@ -37,6 +36,7 @@ class HomebrewLaunchWindow : public GuiFrame, public sigslot::has_slots<>
{
backButtonClicked(this);
}

private:


Expand Down
38 changes: 27 additions & 11 deletions src/menu/HomebrewWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@

#define MAX_BUTTONS_ON_PAGE 4
const char * repoUrl = "http://wiiubru.com/appstore";
//const char* repoUrl = "192.168.1.103:8000";

ProgressWindow* progressWindow;
static HomebrewWindow* thisHomebrewWindow;


void HomebrewWindow::positionHomebrewButton(homebrewButton* button, int index)
{
Expand Down Expand Up @@ -105,19 +108,29 @@ void updateProgress(void *arg, u32 done, u32 total)
progressWindow->setProgress(100.0f* (((f32)done)/((f32)total)));
}

/**
This method updates local apps (and fetches server apps if they haven't been fetched yet)
It refreshes the listing on the "home page" of the app store
**/
void HomebrewWindow::refreshHomebrewApps()
{
// get the 4 different types of app backgrounds
GuiImageData* appButtonImages[4] = { localButtonImgData, updateButtonImgData, installedButtonImgData, getButtonImgData };

// get a list of directories
DirList dirList("sd:/wiiu/apps", ".elf", DirList::Files | DirList::CheckSubfolders);

// remove any existing buttons
for (u32 x=0; x<homebrewButtons.size(); x++)
{
removeE(homebrewButtons[x].button);
}

// clear both arrays
homebrewButtons.clear();
localAppButtons.clear();

// sort the dir list
dirList.SortList();

// load up local apps
Expand Down Expand Up @@ -152,6 +165,7 @@ void HomebrewWindow::refreshHomebrewApps()
// update or installed
homebrewButtons[idx].status = LOCAL;

// load the icon
LoadFileToMem((homebrewPath + "/icon.png").c_str(), &iconData, &iconDataSize);

if(iconData != NULL)
Expand Down Expand Up @@ -197,7 +211,9 @@ void HomebrewWindow::refreshHomebrewApps()

std::istringstream f(fileContents);

// totalLocalApps will represent how many apps aren't on the server
totalLocalApps = homebrewButtons.size();

u32 iterCount = 0;
globalUpdatePosition = true;

Expand All @@ -206,6 +222,7 @@ void HomebrewWindow::refreshHomebrewApps()

std::string shortname;

// very poor xml parsing, to be replaced with json in the future
if (!std::getline(f, shortname)) break;
shortname = shortname.substr(5);
std::string name;
Expand Down Expand Up @@ -236,9 +253,6 @@ void HomebrewWindow::refreshHomebrewApps()
if(slashPos != std::string::npos)
homebrewPath.erase(slashPos);

// u8 * iconData = NULL;
// u32 iconDataSize = 0;

homebrewButtons[idx].dirPath = homebrewPath;

// since we got this app from the net, mark it as a GET
Expand All @@ -258,6 +272,8 @@ void HomebrewWindow::refreshHomebrewApps()

if (addedIndex >= 0)
{
// the logic in here checks if the current app already exists, and if so,
// updates the existing localApp entry rather than continuing to make a new one
homebrewButtons.pop_back();
homebrewButtons[addedIndex].button = new GuiButton(installedButtonImgData->getWidth(), installedButtonImgData->getHeight());
homebrewButtons[addedIndex].image = new GuiImage(appButtonImages[homebrewButtons[addedIndex].status]);
Expand All @@ -271,13 +287,13 @@ void HomebrewWindow::refreshHomebrewApps()

// download app icon
std::string targetIcon;
// std::string targetIconUrl = std::string(repoUrl)+"/apps/" + shortname + "/icon.png";
// bool imageDownloadSuccessful = false;

// try to load file from our memory cache
// this is populated asychronously at app launch
if (cachedIcons.size() > iterCount)
targetIcon = cachedIcons[iterCount];
//FileDownloader::getFile(targetIconUrl, targetIcon);

// if the icon is present, set it to the image
if (!targetIcon.empty())
homebrewButtons[idx].iconImgData = new GuiImageData((u8*)targetIcon.c_str(), targetIcon.size());

Expand Down Expand Up @@ -468,7 +484,7 @@ void HomebrewWindow::OnHomebrewButtonClick(GuiButton *button, const GuiControlle
return;
}

// thisHomebrewWindow = this;
thisHomebrewWindow = this;

bool disableButtons = false;
// return;
Expand Down Expand Up @@ -576,7 +592,7 @@ void refreshHomebrewAppIcons()

}

//HomebrewWindow* getHomebrewWindow()
//{
// return thisHomebrewWindow;
//}
HomebrewWindow* getHomebrewWindow()
{
return thisHomebrewWindow;
}
6 changes: 4 additions & 2 deletions src/menu/HomebrewWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class HomebrewWindow : public GuiFrame, public sigslot::has_slots<>
void fetchThisIcon(int x, std::string targetIconUrl);
void findHomebrewIconAndSetImage(std::string shortname, std::string targetIcon);
int checkIfUpdateOrInstalled(std::string name, std::string version, int totalLocalApps);
std::string binaryTarget;
std::string pathTarget;
std::string sdPathTarget;

private:
void OnOpenEffectFinish(GuiElement *element);
Expand Down Expand Up @@ -113,8 +116,7 @@ class HomebrewWindow : public GuiFrame, public sigslot::has_slots<>
int targetLeftPosition;

};
//extern HomebrewWindow* thisHomebrewWindow;
//extern HomebrewWindow* getHomebrewWindow();
extern HomebrewWindow* getHomebrewWindow();


#endif //_HOMEBREW_WINDOW_H_
Loading

0 comments on commit e8475ae

Please sign in to comment.