| 110 | } |
| 111 | |
| 112 | int FCEUNET_SendFile(uint8 cmd, char *fn) |
| 113 | { |
| 114 | uint32 len; |
| 115 | uLongf clen; |
| 116 | char *buf, *cbuf; |
| 117 | FILE *fp; |
| 118 | struct stat sb; |
| 119 | |
| 120 | if(!(fp=FCEUD_UTF8fopen(fn,"rb"))) return(0); |
| 121 | |
| 122 | FCEUX_fstat(fileno(fp),&sb); |
| 123 | len = sb.st_size; |
| 124 | buf = (char*)FCEU_dmalloc(len); //mbg merge 7/17/06 added cast |
| 125 | if ( fread(buf, 1, len, fp) != static_cast<size_t>(len) ) |
| 126 | { |
| 127 | FCEU_printf("Warning: FCEUNET_SendFile failed to load complete file.\n"); |
| 128 | } |
| 129 | fclose(fp); |
| 130 | |
| 131 | cbuf = (char*)FCEU_dmalloc(4 + len + len / 1000 + 12); //mbg merge 7/17/06 added cast |
| 132 | FCEU_en32lsb((uint8*)cbuf, len); //mbg merge 7/17/06 added cast |
| 133 | compress2((uint8*)cbuf + 4, &clen, (uint8*)buf, len, 7); //mbg merge 7/17/06 added casts |
| 134 | free(buf); |
| 135 | |
| 136 | //printf("Sending file: %s, %d, %d\n",fn,len,clen); |
| 137 | |
| 138 | len = clen + 4; |
| 139 | |
| 140 | if(!FCEUNET_SendCommand(cmd,len)) |
| 141 | { |
| 142 | free(cbuf); |
| 143 | return(0); |
| 144 | } |
| 145 | if(!FCEUD_SendData(cbuf, len)) |
| 146 | { |
| 147 | NetError(); |
| 148 | free(cbuf); |
| 149 | return(0); |
| 150 | } |
| 151 | free(cbuf); |
| 152 | |
| 153 | return(1); |
| 154 | } |
| 155 | |
| 156 | static FILE *FetchFile(uint32 remlen) |
| 157 | { |
no test coverage detected