Example #1
0
void save_tiles(Fl_Widget*,void*){
	if(!currentProject->containsData(pjHaveTiles)){
		currentProject->haveMessage(pjHaveTiles);
		return;
	}
	fileType_t type=askSaveType();
	int clipboard;
	if(type){
		clipboard=clipboardAsk();
		if(clipboard==2)
			return;
	}else
		clipboard=0;
	bool pickedFile;
	if(clipboard)
		pickedFile=true;
	else
		pickedFile=load_file_generic("Pick a location to save tiles",true);
	if(pickedFile){
		int compression=compressionAsk();
		if(compression<0)
			return;
		currentProject->tileC->save(the_file.c_str(),type,clipboard,compression);
	}
}
Example #2
0
filereader::filereader(const char*title,bool relptr,unsigned offbits,bool be){
	char*fname;
	if(title)
		fname=loadsavefile(title);
	else
		fname=loadsavefile();
	if(fname){
		char*ext=(char*)fl_filename_ext(fname);
		ext=strdup(ext);
		for(char*p=ext;*p;++p)
			*p=tolower(*p);
		fileType_t def=tBinary;
		if(!strcmp(ext,".asm"))
			def=tASM;
		else if(!strcmp(ext,".bex"))
			def=tBEX;
		else if(!strcmp(ext,".h"))
			def=tCheader;
		free(ext);
		fileType_t tp=askSaveType(false,def);
		if(tp==tCancle){
			amt=0;
			free(fname);
			return;
		}
		struct stat st;
		FILE*fp=fopen(fname,tp==tBinary?"rb":"r");
		if(!fp){
			fl_alert("An error has occurred: %s",strerror(errno));
			amt=0;
			return;
		}
		if(fstat(fileno(fp),&st)!=0){
			fl_alert("An error has occurred: %s",strerror(errno));
			amt=0;
			fclose(fp);
			return;
		}
		char*tmp=(char*)malloc(st.st_size);
		fread(tmp,1,st.st_size,fp);
		fclose(fp);
		//This is handled by Lua code so the user can modify the behavior of this function with ease
		lua_getglobal(Lconf,"filereaderProcessText");
		lua_pushinteger(Lconf,tp);
		lua_pushboolean(Lconf,relptr);
		lua_pushinteger(Lconf,offbits);
		lua_pushboolean(Lconf,be);
		lua_pushlstring(Lconf,tmp,st.st_size);//Lua makes a copy of the string
		lua_pushstring(Lconf,fname);
		free(fname);
		free(tmp);
		runLuaFunc(Lconf,6,1);
		size_t len=lua_rawlen(Lconf,-1);
		if(len){
			lenTotal=0;
			amt=len;
			for(size_t i=1;i<=len;++i){
				lua_rawgeti(Lconf,-1,i);
				//Get its name
				lua_rawgeti(Lconf,-1,1);
				names.emplace_back(lua_tostring(Lconf,-1));
				lua_pop(Lconf,1);
				//Get its data
				lua_rawgeti(Lconf,-1,2);
				size_t ln;
				const char*src=lua_tolstring(Lconf,-1,&ln);
				void*dst=malloc(ln);
				memcpy(dst,src,ln);
				lens.push_back(ln);
				dat.push_back(dst);
				lenTotal+=ln;
				lua_pop(Lconf,2);
			}
		}else
			amt=0;
		lua_pop(Lconf,1);
	}else
		amt=0;
}