/********************************************************************************* * Networkthread for background network initialize and update check with idle prio *********************************************************************************/ static void * networkinitcallback(void *arg) { while (1) { if (!checkincomming && networkHalt) LWP_SuspendThread(networkthread); Initialize_Network(); if (networkinitialized == true && updatechecked == false) { if (CheckUpdate() > 0) updateavailable = true; //suspend thread updatechecked = true; networkHalt = true; } if (checkincomming) NetworkWait(); usleep(100000); } return NULL; }
/**************************************************************************** * Mount one SMB Share ****************************************************************************/ bool ConnectSMBShare(int client) { if(client < 0 || client >= MAXSMBUSERS) return false; if(firstRun) { if(!IsNetworkInit()) Initialize_Network(); for(int i = 0; i < MAXSMBUSERS; i++) SMB_Mounted[i] = false; firstRun = false; } if(SMB_Mounted[client]) return true; bool result = false; char mountname[10]; char User[50]; char Password[50]; char SMBName[50]; char Host[50]; //don't let tinysmb modify the settings strings sprintf(mountname, "smb%i", client+1); strcpy(Host, Settings.SMBUser[client].Host); strcpy(User, Settings.SMBUser[client].User); strcpy(Password, Settings.SMBUser[client].Password); strcpy(SMBName, Settings.SMBUser[client].SMBName); if(strcmp(Host, "") != 0) { if(smbInitDevice(mountname, User, Password, SMBName, Host)) { result = true; SMB_Mounted[client] = true; } } return result; }
int WiiSave::Download(std::string ID) { if(ID.empty()) return -1; //! Check Network if (!IsNetworkInit()) { ManageProgressStop(); ManageButtons * connect = new ManageButtons(tr("No network connection"), tr("Do you want to connect?"), tr("Yes"), tr("Cancel")); connect->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); connect->SetPosition(-6, 75); connect->SetEffect(EFFECT_FADE, 20); mainWindow->Append(connect); ResumeGui(); while (connect->GetEffect()) usleep(50); while(!connect->GetChoice()) usleep(50); connect->SetEffect(EFFECT_FADE, -20); while (connect->GetEffect()) usleep(50); HaltGui(); mainWindow->Remove(connect); ResumeGui(); if(connect->GetChoice() == 1) { StartManageProgress(tr("Initializing Network")); Initialize_Network(); ManageProgressStop(); } delete connect; if (!IsNetworkInit()) return -2; StartManageProgress(tr("Downloading saveslist:"), "www.wiisave.com"); } //! Generate gameUrl std:: string WiiSaveListURL("http://wiisave.com/savegamecode_xml.php?gamecode="); WiiSaveListURL += ID.substr(0, 3); //! Check Connection if(!CheckConnection(WiiSaveListURL.c_str())) { ManageProgressStop(); return -3; } //! Check Region std::string Region; switch (ID[3]) { case 'E': Region = "E - USA / Canada"; break; case 'J': Region = "J - Japanese"; break; case 'W': Region = "J - Japanese";//Region = "NTSC T"; break; case 'K': Region = "J - Japanese";//Region = "NTSC K"; break; default: case 'P': case 'D': case 'F': case 'I': case 'S': case 'H': case 'U': case 'X': case 'Y': case 'Z': Region = "P - European / Other / PAL"; break; } //! Get list WiiSave_List * SaveList = new WiiSave_List(WiiSaveListURL.c_str()); ManageProgressStop(); if (!SaveList->GetCount()) { delete SaveList; return -4; } if (!SaveList->FilterList(Region)) { delete SaveList; return -5; } //! open browser & select save WiiSaveBrowser * SaveBrowser = new WiiSaveBrowser(SaveList); mainWindow->Append(SaveBrowser); SaveBrowser->Show(); int selected = SaveBrowser->GetSelectedSave(); delete SaveBrowser; if (selected < 0) { delete SaveList; return -10; } //! select download destination ManageButtons * path = new ManageButtons(tr("Select a target path."), tr("Be carrefull, present files can be overwritten"), tr("OK")); path->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); path->SetPosition(-6, 75); path->SetEffect(EFFECT_FADE, 20); mainWindow->Append(path); ResumeGui(); while (path->GetEffect()) usleep(50); while(!path->GetChoice()) usleep(50); path->SetEffect(EFFECT_FADE, -20); while (path->GetEffect()) usleep(50); HaltGui(); mainWindow->Remove(path); delete path; ResumeGui(); if( selectBrowser(Settings.BrowserPath.c_str(), PATH) != 2 ) { delete SaveList; return -10; } //! download file std::string filepath = Settings.TmpPath; filepath += "/"; filepath += SaveList->GetFilteredFilename(selected); if( WiiSave::InternalDownload(SaveList->GetFilteredDownloadLink(selected), filepath) < 0) { delete SaveList; return -6; } delete SaveList; //! check file type char destID[5]; std::string srcfilepath; bool isSgmgxSave = false; bool isDataBin = false; std::string tmpDest = filepath.substr(0, filepath.rfind("/")+1); tmpDest += "tmpExtract"; std::string fileext = filepath.substr(filepath.rfind(".")); if( !Settings.FileExtensions.CompareArchive(fileext.c_str()) ) //! Archive { StartManageProgress(tr("Extracting files...")); //! extract files ArchiveHandle * Archive = new ArchiveHandle(filepath.c_str()); Archive->ExtractAll(tmpDest.c_str()); delete Archive; RemoveFile(filepath.c_str()); //! check save type DirList * dirList = new DirList(tmpDest.c_str(), ".bin" , DirList::Files | DirList::Dirs | DirList::CheckSubfolders); for(int i = 0; i < dirList->GetFilecount(); i++) { if(!strcmp(dirList->GetFilename(i), "banner.bin")) { isSgmgxSave = true; srcfilepath = dirList->GetFilepath(i); break; } std::string name(dirList->GetFilename(i)); fileext = name.substr(name.rfind(".")); if( !Settings.FileExtensions.CompareBinaryFiles(fileext.c_str()) ) { SaveInfos * infos = GetSaveInfos(dirList->GetFilepath(i)); if(infos) { isDataBin = true; srcfilepath = dirList->GetFilepath(i); memcpy(destID, infos->ID, 5); delete infos; break; } } } delete dirList; ManageProgressStop(); } else //! check for data.bin file { StartManageProgress(tr("Verifying file...")); SaveInfos * infos = GetSaveInfos(filepath); if(infos) { isDataBin = true; srcfilepath = filepath; memcpy(destID, infos->ID, 5); delete infos; } ManageProgressStop(); } if(!isDataBin && !isSgmgxSave) //! supported files not found { RemoveFile(filepath.c_str()); RemoveDirectory(tmpDest.c_str()); return -7; } //! write files StartManageProgress(tr("Writing files...")); if(isSgmgxSave) { std::string srcfolder = srcfilepath.substr(0, srcfilepath.rfind("/")); DirList * dirList = new DirList(srcfolder.c_str(), NULL , DirList::Files | DirList::Dirs); srcfolder = srcfolder.substr(srcfolder.rfind("/")); std::string finaldest = Settings.TmpPath; finaldest += srcfolder; CreateSubfolder(finaldest.c_str()); for(int i = 0; i < dirList->GetFilecount(); i++) { if(IsDir(i)) CopyDirectory(dirList->GetFilepath(i), finaldest.c_str()); else CopyFile(dirList->GetFilepath(i), fmt("%s/%s", finaldest.c_str(), dirList->GetFilename(i))); } delete dirList; } else if(isDataBin) { std::string finaldest = Settings.TmpPath; finaldest += "/"; finaldest += destID; CreateSubfolder(finaldest.c_str()); finaldest += "/data.bin"; CopyFile(srcfilepath.c_str(), finaldest.c_str()); } RemoveFile(filepath.c_str()); RemoveDirectory(tmpDest.c_str()); ManageProgressStop(); return 1; }
string checkUpdatePrompt() { GuiWindow promptWindow(520,360); promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); promptWindow.SetPosition(0, -10); GuiImageData dialogBox(Theme.dialog_background); GuiImage dialogBoxImg(&dialogBox); GuiImageData btnOutline(Theme.button_small); GuiImage btn1Img(&btnOutline); GuiImageData btnOutlineOver(Theme.button_small_focus); GuiImage btn1ImgOver(&btnOutlineOver); // ok button GuiText backTxt(tr("OK"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255}); GuiImage backImg(&btnOutline); GuiImage backImgOver(&btnOutlineOver); GuiButton back(btnOutline.GetWidth(), btnOutline.GetHeight()); GuiTrigger trigA; trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); back.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); back.SetPosition(0, -25); back.SetLabel(&backTxt); back.SetImage(&backImg); back.SetImageOver(&backImgOver); back.SetTrigger(&trigA); back.SetState(STATE_SELECTED); GuiText titleTxt(tr("Update"), 26, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255}); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt.SetPosition(0, 40); GuiText msgTxt(tr("Initialise network..."), 22, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255}); msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); promptWindow.Append(&dialogBoxImg); promptWindow.Append(&titleTxt); promptWindow.Append(&msgTxt); HaltGui(); mainWindow->SetState(STATE_DISABLED); mainWindow->Append(&promptWindow); mainWindow->ChangeFocus(&promptWindow); ResumeGui(); string rev = "NULL"; // berprfen, ob netzwerk initialisiert wird Initialize_Network(); if(!IsNetworkInit()) { msgTxt.SetText(tr("No network connection")); bool stop = false; promptWindow.Append(&back); while(!stop) { usleep(100); if(back.GetState() == STATE_CLICKED) stop = true; } promptWindow.Remove(&back); } else { string revs = CheckNewVersions(); if(revs == "error") { msgTxt.SetText(tr("Error while reading file")); bool stop = false; promptWindow.Append(&back); while(!stop) { usleep(100); if(back.GetState() == STATE_CLICKED) stop = true; } promptWindow.Remove(&back); } else rev = choiceRev(revs); } HaltGui(); mainWindow->Remove(&promptWindow); mainWindow->SetState(STATE_DEFAULT); ResumeGui(); return rev; }