Exemplo n.º 1
0
int CXCCRA2MapUpdaterApp::update()
{
	int error = 0;
	try
	{
		CWaitCursor wait;
		CInternetSession is;
		CHttpFile* f = reinterpret_cast<CHttpFile*>(is.OpenURL("http://xccu.sourceforge.net/ra2_maps/official.ucf"));
		if (!f)
			error = 1;
		else
		{
			string s;
			while (1)
			{
				int cb_p = f->GetLength();
				if (!cb_p)
					break;
				char* p = new char[cb_p + 1];
				f->Read(p, cb_p);
				p[cb_p] = 0;
				s += p;
				delete[] p;
			}
			f->Close();
			Cvirtual_tfile f;
			f.load_data(Cvirtual_binary(s.c_str(), s.length()));
			while (!f.eof())
			{
				Cmulti_line l = f.read_line();
				Cfname fname = xcc_dirs::get_dir(game_ra2) + l.get_next_line('=') + ".mmx";
				if (!fname.exists())
				{
					string version = l.get_next_line(',');
					string link = l.get_next_line(',');
					error = download_update(link, fname);
					if (error)
					{
						delete_file(fname);
						MessageBox(NULL, "Error retrieving update.", NULL, MB_ICONERROR);
						error = 0;
					}
				}
			}
		}
	}
	catch (CInternetException*)
	{
		error = 1;
	}
	if (error)
		MessageBox(NULL, "Error querying for update.", NULL, MB_ICONERROR);
	return error;
}
Exemplo n.º 2
0
int game_update(char *title_id) 
{
    char id[10];

    char version[6];
    char ver_app[6];
    char system[8];

    int list[128][2];

    int max_list = 0;

    int ret;

    //sprintf(temp_buffer, "http://www.covers-examples.com/ps3/%s.jpg", id);
    //sprintf(temp_buffer + 1024, "%s/temp.jpg", self_path);

    //download_file(temp_buffer, temp_buffer + 1024, 0, NULL);

    if(DrawDialogYesNo("Want you update the Game?") != 1) return 0;

    memcpy(id, title_id, 4);
    id[4] = title_id[5]; id[5] = title_id[6]; id[6] = title_id[7]; id[7] = title_id[8]; id[8] = title_id[9]; id[9] = 0;

    strcpy(ver_app, "00.00");
    
    sprintf(temp_buffer, "/dev_hdd0/game/%s/PARAM.SFO", id);
    param_sfo_app_ver(temp_buffer, ver_app);

    sprintf(temp_buffer, "https://a0.ww.np.dl.playstation.net/tpl/np/%s/%s-ver.xml", id, id);
    sprintf(temp_buffer + 1024, "%s/temp.xml", self_path);

    ret = download_update(temp_buffer, temp_buffer + 1024, 0, NULL);

    if(ret < 0) {
        sprintf(temp_buffer, "Error 0x%x downloading XML", ret);
        DrawDialogOK(temp_buffer);
        return 0;
    }

    int file_size = 0;
    u8 *mem = (u8 *) LoadFile(temp_buffer + 1024, &file_size);

    if(!mem || file_size== 0) {
        DrawDialogOK("No update found for this game");
        return 0;
    }

    int n = 0;
    int m, l;
    int k = 0;

    while(n < file_size) {
        if(mem[n] != '<') {n++; continue;}
        if(!strncmp((char *) &mem[n], "/>", 2) || mem[n] == '>') {n++; continue;}
        
        if(strncmp((char *) &mem[n], "<package ", 9)) {n++; continue;}

        n+= 9;
        
        strcpy(version, "00.00");
        strcpy(system,  "00.0000");

        m = locate_xml(mem, n, file_size, "version", &l);
        if(m < 0) goto no_ver; // not found
        if(l > k) k = l;

        m++; l-= m;
        if(l<=0) goto no_ver; // empty 

        strncpy(version, (char *) &mem[m], 5);
        version[5] = 0;

    no_ver:
        m = locate_xml(mem, n, file_size, "url", &l);
        if(m < 0) continue;
        if(l > k) k = l;

        m++; l-= m;
        if(l<=0) continue; // empty 
        if(l>1023) l = 1023;

        strncpy(temp_buffer, (char *) &mem[m], l);
        temp_buffer[l] = 0;

        list[max_list][0] = m;
        list[max_list][1] = l;

        m = locate_xml(mem, n, file_size, "ps3_system_ver", &l);
        if(m < 0) goto no_system; // not found
        if(l > k) k = l;

        m++; l-= m;
        if(l<=0) goto no_system; // empty 

        strncpy(system, (char *) &mem[m], 7);
        system[7] = 0;


    no_system:

        if(strcmp(version, ver_app)<=0) {n = k; continue;}

        char * o = strrchr(temp_buffer, '/');
        if (o) {
            sprintf(temp_buffer + 1024, "Download this update?\n\nVersion: %s for System Ver %s\n\n%s", version, system, o + 1);

            if(DrawDialogYesNo2(temp_buffer + 1024) == 1) {

                max_list++; if(max_list >=128) break;

            } else break; // to avoid download the next package
        }


        n = k;


    }

    int downloaded = 0;

    if(max_list > 0) {

        DrawDialogOKTimer("Downloading the updates\n\nWait to finish", 2000.0f);

        sprintf(temp_buffer + 1024, "%s/PKG", self_path);
        mkdir_secure(temp_buffer + 1024);

        for(n = 0; n < max_list; n++) {
            struct stat s;
            u64 pkg_size = 0;

            strncpy(temp_buffer, (char *) &mem[list[n][0]], list[n][1]);
            temp_buffer[list[n][1]] = 0;

            char * o = strrchr(temp_buffer, '/');
            if (!o) continue;

            sprintf(temp_buffer + 1024, "%s/PKG%s", self_path, o); 

            if(!stat(temp_buffer + 1024, &s)) {downloaded++; continue;} // if exist skip

            // get size
            ret = download_update(temp_buffer, temp_buffer + 1024, 1, &pkg_size);

            if(ret < 0) {
                sprintf(temp_buffer, "Error 0x%x downloading XML", ret);
                DrawDialogOK(temp_buffer);
                free(mem);
                return downloaded;
            }
            
            {
                u32 blockSize;
                u64 freeSize;
                u64 free_hdd0;
                sysFsGetFreeSize("/dev_hdd0/", &blockSize, &freeSize);
                free_hdd0 = ( ((u64)blockSize * freeSize));
                if((pkg_size + 0x40000000LL) >= (s64) free_hdd0) {
                    sprintf(temp_buffer + 3072, "%s\n\n%s\n\n%s%1.2f GB", "Error: no space in HDD0 to copy it", temp_buffer + 1024, "You need ", 
                        ((double) (pkg_size + 0x40000000LL - free_hdd0))/(1024.0*1024.*1024.0));
                    DrawDialogOK(temp_buffer + 3072);
                    free(mem);
                    return downloaded;
                }
            }


            // download

            ret = download_update(temp_buffer, temp_buffer + 1024, 2, &pkg_size);

            if(ret == -0x555) {
                DrawDialogOK(language[GLUTIL_ABORTEDUSER]);
                free(mem);
                return downloaded;
            } else if(ret < 0) {
                sprintf(temp_buffer, "Error 0x%x downloading XML", ret);
                free(mem);
                return downloaded;
            } else downloaded++;


        }
    } else DrawDialogOK("No update found for this game");

    free(mem);

    return downloaded;
}