コード例 #1
0
ファイル: module.c プロジェクト: DC-SWAT/DreamShell
void BiosFlasher_OnOperationProgress(OperationState_t state, float progress)
{
	char msg[64];	// TODO: Check overflow
	memset(msg, 0, sizeof(msg));
	switch(state)
	{
		case eErasing:
			sprintf(msg, "Erasing: %d%%", (int)(progress * 100));
		break;

		case eWriting:
			sprintf(msg, "Writing: %d%%", (int)(progress * 100));
		break;

		case eReading:
			sprintf(msg, "Reading: %d%%", (int)(progress * 100));
		break;

		case eNone:
		case eCompare:
		break;
	};

	GUI_LabelSetText(self.m_LabelProgress, msg);
	GUI_ProgressBarSetPosition(self.m_ProgressBar, progress);
}
コード例 #2
0
ファイル: module.c プロジェクト: i-rom/DreamShell
static int rip_sec(int tn,int first,int count,int type,char *dst_file, int disc_type){

double percent,percent_last=0.0;
maple_device_t *cont;
cont_state_t *state;
file_t hnd;
int secbyte = (type == 4 ? 2048 : 2352) , i , count_old=count, bad=0, cdstat, readi;
uint8 *buffer = (uint8 *)memalign(32, SEC_BUF_SIZE * secbyte);
	
	GUI_WidgetMarkChanged(self.app->body);
//	ds_printf("Track %d		First %d	Count %d	Type %d\n",tn,first,count,type);
/*	if (secbyte == 2048) cdrom_set_sector_size (secbyte);
	else _cdrom_reinit (1);
*/
	cdrom_set_sector_size (secbyte);
	
	if ((hnd = fs_open(dst_file,O_WRONLY | O_TRUNC | O_CREAT)) == FILEHND_INVALID) {
		ds_printf("Error open file %s\n" ,dst_file); 
		cdrom_spin_down(); free(buffer); 
		return CMD_ERROR;
		}
	
	LockVideo();
	
	while(count) {
	
		int nsects = count > SEC_BUF_SIZE ? SEC_BUF_SIZE : count;
		count -= nsects;
		
		
		while((cdstat=cdrom_read_sectors(buffer, first, nsects)) != ERR_OK ) {
			if (atoi(GUI_TextEntryGetText(self.num_read)) == 0) break;
			readi++ ;
			if (readi > 5) break ;
			thd_sleep(200);
		}
			readi = 0;
		if (cdstat != ERR_OK) {
			if (!GUI_WidgetGetState(self.bad)) {
				UnlockVideo();
				GUI_ProgressBarSetPosition(self.read_error, 1.0);
				for(;;) {
					cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
					
					if(!cont) continue;
					state = (cont_state_t *)maple_dev_status(cont);
					
					if(!state) continue;
					if(state->buttons & CONT_A) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0);
						GUI_WidgetMarkChanged(self.app->body); 
						ds_printf("DS_ERROR: Can't read sector %ld\n", first); 
						free(buffer); 
						fs_close(hnd); 
						return CMD_ERROR;
					} else if(state->buttons & CONT_B) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0);
						GUI_WidgetMarkChanged(self.app->body); 
						break;
					} else if(state->buttons & CONT_Y) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0); 
						GUI_WidgetSetState(self.bad, 1);
						GUI_WidgetMarkChanged(self.app->body); 
						break;
					}
				}
			}
			// Ошибка, попробуем по одному
			uint8 *pbuffer = buffer;
			LockVideo();
			for(i = 0; i < nsects; i++) {
				
				while((cdstat=cdrom_read_sectors(pbuffer, first, 1)) != ERR_OK ) {
				readi++ ;
				if (readi > atoi(GUI_TextEntryGetText(self.num_read))) break ;
				if (readi == 1 || readi == 6 || readi == 11 || readi == 16 || readi == 21 || readi == 26 || readi == 31 || readi == 36 || readi == 41 || readi == 46) cdrom_reinit();
				thd_sleep(200);
				}
				readi = 0;
				
				if (cdstat != ERR_OK) {
					// Ошибка, заполним нулями и игнорируем
					UnlockVideo();
					cdrom_reinit();
					memset(pbuffer, 0, secbyte);
					bad++;
					ds_printf("DS_ERROR: Can't read sector %ld\n", first);
					LockVideo();
				}
			
				pbuffer += secbyte;
				first++;
			}
		
		} else {
			// Все ок, идем дальше
			first += nsects;
		}
	
		if(fs_write(hnd, buffer, nsects * secbyte) < 0) {
			// Ошибка записи, печально, прерываем процесс
			UnlockVideo();
			free(buffer);
			fs_close(hnd);
			return CMD_ERROR;
		}
		UnlockVideo();
		percent = 1-(float)(count) / count_old;
		if ((percent = ((int)(percent*100 + 0.5))/100.0) > percent_last) {
		percent_last = percent;
		GUI_ProgressBarSetPosition(self.pbar, percent);
		LockVideo();
		}
	}
UnlockVideo();
free(buffer);
fs_close(hnd);
ds_printf("%d Bad sectors on track\n", bad);
return CMD_OK;
}
コード例 #3
0
ファイル: module.c プロジェクト: i-rom/DreamShell
void gd_ripper_StartRip() {
	file_t fd;
	CDROM_TOC toc ;
	int status, disc_type ,cdcr ,start ,s_end ,nsec ,type ,tn ,session,terr=0;
	char dst_folder[MAX_FN_LEN];
	char dst_file[MAX_FN_LEN];
	char riplabel[64];
	char text[MAX_FN_LEN];
	uint64 stoptimer , starttimer , riptime;
	
	starttimer = timer_ms_gettime64 (); // timer
	cdrom_reinit();
	snprintf(text ,MAX_FN_LEN,"%s", GUI_TextEntryGetText(self.gname));
	if(GUI_WidgetGetState(self.sd_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/sd/%s", text);
	}else if(GUI_WidgetGetState(self.hdd_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/ide/%s", text);
	}else if(GUI_WidgetGetState(self.net_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/net/%s", text);
	}
//ds_printf("Dst file1 %s\n" ,dst_folder);	
getstatus:	
	if((cdcr = cdrom_get_status(&status, &disc_type)) != ERR_OK) {
		switch (cdcr){
			case ERR_NO_DISC :
				ds_printf("DS_ERROR: Disk not inserted\n");
				return;
			case ERR_DISC_CHG :
				cdrom_reinit();
				goto getstatus;
			case CD_STATUS_BUSY :
				thd_sleep(200);
				goto getstatus;
			case CD_STATUS_SEEKING :
				thd_sleep(200);
				goto getstatus;
			case CD_STATUS_SCANNING :
				thd_sleep(200);
				goto getstatus;
			default:
				ds_printf("DS_ERROR: GD-rom error\n");
				return;
		}
	}
	if (disc_type == CD_CDROM_XA){
	rname:
			snprintf(dst_file,MAX_FN_LEN, "%s.iso", dst_folder);
			if ((fd=fs_open(dst_file , O_RDONLY)) != FILEHND_INVALID) {
				fs_close(fd); strcpy(dst_file,"\0"); 
				strcat(dst_folder , "0"); 
				goto rname ;
			} else disc_type = 1;
	} else if (disc_type == CD_GDROM){
	rname1:
			if ((fd=fs_open (dst_folder , O_DIR)) != FILEHND_INVALID) {
				fs_close(fd); 
				strcat(dst_folder , "0"); 
				goto rname1 ;
			} else {strcpy(dst_file,"\0");
			snprintf(dst_file,MAX_FN_LEN,"%s", dst_folder); 
			disc_type = 2; 
			fs_mkdir(dst_file);
			}
			
			while(cdrom_read_toc(&toc, 1) != CMD_OK) { 
				terr++;
				cdrom_reinit();
				if (terr > 100){
				ds_printf("DS_ERROR: Toc read error for gdlast\n");
				fs_rmdir(dst_folder); 
				return; 
				}
			}
			terr=0;
			self.lastgdtrack = TOC_TRACK(toc.last);
	} else {
			ds_printf("DS_ERROR: This is not game disk\nInserted %d disk\n",disc_type);
			return;
	}
//ds_printf("Dst file %s\n" ,dst_file);
	
	for (session=0; session < disc_type; session++) {
		cdrom_set_sector_size(2048);
		while(cdrom_read_toc(&toc, session) != CMD_OK) {
			terr++; 
			if(terr==5) cdrom_reinit(); 
			thd_sleep(500); 
			if (terr > 10) { 
				ds_printf("DS_ERROR: Toc read error\n");
			if (disc_type == 1) {
				if(fs_unlink(dst_file) != 0) 
				ds_printf("Error delete file: %s\n" ,dst_file);
			}else {
					if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
						ds_printf("Error folder '%s' not found\n" ,dst_folder); 
						return;
					}
					dirent_t *dir;
					while ((dir = fs_readdir(fd))){
						if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
						strcpy(dst_file,"\0");
						snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
						fs_unlink(dst_file);
					}
					fs_close(fd);
					fs_rmdir(dst_folder);
				} 
				return; 
			}
		}
		terr = 0;
		int first = TOC_TRACK(toc.first);
		int last = TOC_TRACK(toc.last);
		for (tn=first; tn <= last; tn++ ) {
			if (disc_type == 1) tn = last;
			type = TOC_CTRL(toc.entry[tn-1]);
			if (disc_type == 2) {
				strcpy(dst_file,"\0"); 
				snprintf(dst_file,MAX_FN_LEN,"%s/track%02d.%s", dst_folder, tn, (type == 4 ? "iso" : "raw"));
			}
			
			start = TOC_LBA(toc.entry[tn-1]);
			s_end = TOC_LBA((tn == last ? toc.leadout_sector : toc.entry[tn]));
			nsec = s_end - start;
			
			if (disc_type == 1 && type == 4) nsec -= 2 ;
			else if (session==1 && tn != last && type != TOC_CTRL(toc.entry[tn])) nsec -= 150;
			else if (session==0 && type == 4) nsec -= 150;
			
			if (disc_type == 2 && session == 0) {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Track %d of %d\n",tn ,self.lastgdtrack );
			} else if (disc_type == 2 && session == 1 && tn != self.lastgdtrack) {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Track %d of %d\n",tn ,self.lastgdtrack );
			} else {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Last track\n");
			}
			
			GUI_LabelSetText(self.track_label, riplabel);
			
			if (rip_sec(tn, start, nsec, type, dst_file, disc_type) != CMD_OK) {
				GUI_LabelSetText(self.track_label, " ");
				stoptimer = timer_ms_gettime64 (); // timer
				GUI_ProgressBarSetPosition(self.pbar, 0.0);
				cdrom_spin_down();
				if (disc_type == 1) {
					if(fs_unlink(dst_file) != 0) ds_printf("Error delete file: %s\n" ,dst_file);
				} else {
					if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
						ds_printf("Error folder '%s' not found\n" ,dst_folder); 
						return;
					}
					
					dirent_t *dir;
					while ((dir = fs_readdir(fd))){
						if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
						strcpy(dst_file,"\0");
						snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
						fs_unlink(dst_file);
					}
					fs_close(fd);
					fs_rmdir(dst_folder);
				}
				return ;
			}
			GUI_LabelSetText(self.track_label, " ");
			GUI_ProgressBarSetPosition(self.pbar, 0.0);
		}
	}
	GUI_LabelSetText(self.track_label, " ");
	GUI_WidgetMarkChanged(self.app->body);
	if (disc_type == 2){
		if (gdfiles(dst_folder, dst_file, text) != CMD_OK){
			cdrom_spin_down();
			if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
				ds_printf("Error folder '%s' not found\n" ,dst_folder); 
				return;
			}
			
			dirent_t *dir;
			
			while ((dir = fs_readdir(fd))){
				if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
				strcpy(dst_file,"\0");
				snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
				fs_unlink(dst_file);
			}
			fs_close(fd);
			fs_rmdir(dst_folder);
			return;	
		}
		
		
	}
	GUI_ProgressBarSetPosition(self.pbar, 0.0);
	cdrom_spin_down();
	stoptimer = timer_ms_gettime64 (); // timer
	riptime = stoptimer - starttimer;
	int ripmin = riptime / 60000 ;
	int ripsec = riptime % 60 ;
	ds_printf("DS_OK: End ripping. Save at %d:%d\n",ripmin,ripsec);
}