Exemple #1
0
static bool writeAFile(const MAUtil::String& dir) {
	// find a root path
	printf("Dir: '%s'\n", dir.c_str());
	FileLister fl;
	int res = fl.start(dir.c_str());
	if(res < 0) {
		printf("Error %i\n", res);
		return false;
	}
	MAUtil::String file;
	while(1) {
		res = fl.next(file);
		printf("%i: '%s'\n", res, file.c_str());
		if(res < 0) {
			printf("Error %i\n", res);
			return false;
		}
		if(res == 0) {
			printf("Dir '%s' ends.\n", dir.c_str());
			return false;
		}
		if(file[file.size()-1] == '/') {
			if(tryToWrite(dir + file))
				return true;
			if(writeAFile(dir + file))
				return true;
		}
	}
}
Exemple #2
0
MAUtil::String XML::getLocalPath()
{
	    // Do this here to work around a MoRE bug.
	    FileLister fl;
	    fl.start("/");

	    MAUtil::String path, os;


	    // Try getting the local path.
	    int result = getSystemProperty("mosync.path.local", path);

	    getSystemProperty("mosync.device.OS", os);

	    lprintfln("OS: %s", MAUtil::lowerString(os).c_str());

	    if(MAUtil::lowerString(os).find("android", 0) != -1)
	    {
	    	MAHandle tfile;

	    	path = "/sdcard/Magna Carta/";

	    	tfile = maFileOpen(path.c_str(), MA_ACCESS_READ_WRITE);

	    	lprintfln("File handle: %d", tfile);
	    	lprintfln("File exists: %d", maFileExists(tfile));


	    	if(!maFileExists(tfile))
	    	{
	    		int result = maFileCreate(tfile);

	    		lprintfln("File create code: %d", result);
	    	}

	    	maFileClose(tfile);

	    	lprintfln("Path: %s", path.c_str());

	    	return path;
	    }

	    // If it works, fine.
	    if(result > 0) {
	        //printf("Got local path: %i\n", result);
	        return path;
	    }

	    // Otherwise, get the first root directory.
	    fl.start("");
	    result = fl.next(path);
	    //MAASSERT(result > 0);
	    return path;
}
MAUtil::String SettingsScreen::getLocalPath() {
    // Do this here to work around a MoRE bug.
    FileLister fl;
    fl.start("/");

    MAUtil::String path;
    // Try getting the local path.
    int result = getSystemProperty("mosync.path.local", path);
    // If it works, fine.
    if(result > 0) {
        printf("Got local path: %i\n", result);
        return path + "/";
    }
    printf("local path output %i", result);
    // Otherwise, get the first root directory.
    fl.start("");
    result = fl.next(path);
    MAASSERT(result > 0);
    return path;
}
bool WallpaperDialog::exec()
{
	bool close = false, result = true;

	FileLister fl;
	fl.setFilter(".png");

	string filepath = GMenu2X::getHome() + "/skins/"
	  	+ gmenu2x->confStr["skin"] + "/wallpapers";
	if (fileExists(filepath))
	  fl.setPath(filepath, true);

	filepath = GMENU2X_SYSTEM_DIR "/skins/"
	  	+ gmenu2x->confStr["skin"] + "/wallpapers";
	if (fileExists(filepath)) {
		fl.setPath(filepath, false);
		fl.browse(false);
	}

	if (gmenu2x->confStr["skin"] != "Default") {
		filepath = GMenu2X::getHome() + "/skins/Default/wallpapers";
		if (fileExists(filepath)) {
			fl.setPath(filepath, false);
			fl.browse(false);
		}

		filepath = GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers";
		if (fileExists(filepath)) {
			fl.setPath(filepath, false);
			fl.browse(false);
		}
	}

	vector<string> wallpapers = fl.getFiles();

	DEBUG("Wallpapers: %i\n", wallpapers.size());

	uint i, selected = 0, firstElement = 0, iY;

	ButtonBox buttonbox(gmenu2x);
	buttonbox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Select wallpaper"]));
	buttonbox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Exit"]));

	while (!close) {
		if (selected>firstElement+9) firstElement=selected-9;
		if (selected<firstElement) firstElement=selected;

		//Wallpaper
		gmenu2x->sc[((string)"skin:wallpapers/" + wallpapers[selected]).c_str()]->blit(gmenu2x->s, 0, 0);

		gmenu2x->drawTopBar(gmenu2x->s);
		gmenu2x->drawBottomBar(gmenu2x->s);

		drawTitleIcon("icons/wallpaper.png",true);
		writeTitle("Wallpaper selection");
		writeSubTitle("Select an image from the list, to use as a wallpaper");

		buttonbox.paint(5);

		//Selection
		iY = selected-firstElement;
		iY = 44+(iY*17);
		gmenu2x->s->box(2, iY, 308, 16,	gmenu2x->skinConfColors[COLOR_SELECTION_BG]);

		//Files & Directories
		gmenu2x->s->setClipRect(0,41,311,179);
		for (i=firstElement; i<wallpapers.size() && i<firstElement+10; i++) {
			iY = i-firstElement;
			gmenu2x->s->write(gmenu2x->font, wallpapers[i], 5, 52+(iY*17), ASFont::HAlignLeft, ASFont::VAlignMiddle);
		}
		gmenu2x->s->clearClipRect();

		gmenu2x->drawScrollBar(10,wallpapers.size(),firstElement,44,170);
		gmenu2x->s->flip();

        switch(gmenu2x->input.waitForPressedButton()) {
            case InputManager::CANCEL:
                close = true;
                result = false;
                break;
            case InputManager::UP:
                if (selected == 0) selected = wallpapers.size()-1;
                else selected -= 1;
                break;
            case InputManager::ALTLEFT:
                if ((int)(selected-9) < 0) selected = 0;
                else selected -= 9;
                break;
            case InputManager::DOWN:
                if (selected+1 >= wallpapers.size()) selected = 0;
                else selected += 1;
                break;
            case InputManager::ALTRIGHT:
                if (selected+9 >= wallpapers.size()) selected = wallpapers.size()-1;
                else selected += 9;
                break;
            case InputManager::ACCEPT:
                close = true;
                if (wallpapers.size() > 0)
					wallpaper = gmenu2x->sc.getSkinFilePath("wallpapers/" + wallpapers[selected]);
                else result = false;
            default:
                break;
        }
	}

	for (uint i=0; i<wallpapers.size(); i++)
	  gmenu2x->sc.del("skin:wallpapers/" + wallpapers[i]);

	return result;
}