int Playlog_Update(const char * ID, const u16 * title) { if(!ID || !title) return -1; //If not started from SystemMenu, create playlog Playlog_Create(); s32 fd = -1, res = -1; u32 sum = 0; u8 i; //Open play_rec.dat fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); if(fd == -106) { //In case the play_rec.dat wasn´t found create one and try again int ret = Playlog_Create(); if(ret < 0) return ret; fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); } if(fd < 0) return res; PlayRec * playrec_buf = memalign(32, ALIGN32(sizeof(PlayRec))); //! Should be 32 byte aligned if(!playrec_buf) { IOS_Close(fd); return res; } memset(playrec_buf, 0, sizeof(PlayRec)); u64 stime = getWiiTime(); playrec_buf->ticks_boot = stime; playrec_buf->ticks_last = stime; //Update channel name and ID memcpy(playrec_buf->name, title, 84); memcpy(playrec_buf->title_id, ID, 6); //Calculate and update checksum for(i = 0; i < 31; i++) sum += playrec_buf->data[i]; playrec_buf->checksum = sum; //Write play_rec.dat if(IOS_Write(fd, playrec_buf, sizeof(PlayRec)) == sizeof(PlayRec)) res = 0; IOS_Close(fd); free(playrec_buf); return res; }
int Playlog_Update(const char ID[6], const u8 title[84]) { gprintf("Update Play log\n"); u32 sum = 0; u8 i; //Open play_rec.dat s32 playrec_fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); if(playrec_fd == -106) { gprintf("IOS_Open error ret: %i\n",playrec_fd); IOS_Close(playrec_fd); //In case the play_rec.dat wasn´t found create one and try again if(ISFS_CreateFile(PLAYRECPATH,0,3,3,3) < 0 ) goto error_2; playrec_fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); if(playrec_fd < 0) goto error_2; } else if(playrec_fd < 0) goto error_2; u64 stime = getWiiTime(); playrec_buf.ticks_boot = stime; playrec_buf.ticks_last = stime; //Update channel name and ID memcpy(playrec_buf.name, title, 84); strcpy(playrec_buf.title_id, ID); memset(playrec_buf.padding2, 0, 18); //Calculate and update checksum for(i=0; i<31; i++) sum += playrec_buf.data[i]; playrec_buf.checksum=sum; //Write play_rec.dat if(IOS_Write(playrec_fd, &playrec_buf, sizeof(playrec_buf)) != sizeof(playrec_buf)) goto error_1; IOS_Close(playrec_fd); return 0; error_1: gprintf("error_1\n"); IOS_Close(playrec_fd); error_2: gprintf("error_2\n"); return -1; }