Пример #1
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;
}
Пример #2
0
unsigned ps3pad_read()
{
    int n;

    padActParam actparam;

    unsigned butt = 0;

    pad_alive = 0;

    static int count = 16;
    static u64 sec, nsec;
    count++;

    if(count > 15)
    {
        sysGetCurrentTime(&sec, &nsec);
        count = 0;

        if(pad_last_time == 0)
            pad_last_time = sec;

        if(iTimeoutByInactivity)
        {
            if((sec - pad_last_time) > (iTimeoutByInactivity * 3600))
            {
                if(DrawDialogYesNoTimer("System will be shutdown in two minutes by inactivity\nDo you want to abort the countdown?", 120000.0f) != 1)
                {
                    fun_exit();
                    sys_shutdown();
                    exit(0);
                }
                else
                    pad_last_time = 0;
            }
        }

        u32 temp = 0;
        u32 temp2 = 0;

        sys_game_get_temperature(0, &temp);
        sys_game_get_temperature(1, &temp2);

        if((temp >= 80 || temp2 >= 80))
        {
            if(!hot_temp_alarm) hot_temp_alarm = sec;
        } else
            hot_temp_alarm = 0;

        if(hot_temp_alarm && (sec - hot_temp_alarm) > 90)
        {
            DrawDialogOKTimer("WARNING: CPU/RSX Temperature is too high!\nSystem will be shutdown in 10 seconds\n", 10000.0f);
            fun_exit();
            sys_shutdown();
            exit(0);
        }
    }

    sysUtilCheckCallback();

    ioPadGetInfo(&padinfo);

    for(n = 0; n < MAX_PADS; n++)
    {
        if(padinfo.status[n])
        {
            ioPadGetData(n, &paddata);
            pad_alive = 1;
            butt = (paddata.button[2] << 8) | (paddata.button[3] & 0xff);

            /* Analog stick management */
            if (paddata.button[6] < 0x10)
                butt |= BUTTON_LEFT;
            else if (paddata.button[6] > 0xe0)
                butt |= BUTTON_RIGHT;

            if (paddata.button[7] < 0x10)
                butt |= BUTTON_UP;
            else if (paddata.button[7] > 0xe0)
                butt |= BUTTON_DOWN;

            if(butt) pad_last_time = sec;

            break;
        }
    }


    if(!pad_alive) butt = 0;
    else
    {
        actparam.small_motor = 0;
        actparam.large_motor = 0;

        if(rumble1_on)
        {
            actparam.large_motor = 255;

            rumble1_on++;

            if(rumble1_on > 15) rumble1_on = 0;
        }

        if(rumble2_on)
        {
            actparam.small_motor = 1;

            rumble2_on++;

            if(rumble2_on > 10) rumble2_on = 0;
        }

        last_rumble = n;

        ioPadSetActDirect(n, &actparam);
    }

    temp_pad = butt;

    new_pad = temp_pad & (~old_pad); old_pad = temp_pad;

    return butt;
}