Fix wrong #ifdefs
[kugel-rb.git] / utils / MTP / sendfirm_win.c
blobc16a7ab68b9eeea77070bfb50b84db8580f0e696
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 Maurus Cuelenaere
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #define LPWSTR wchar_t*
24 #include <stdio.h>
25 #include <string.h>
26 #include <stddef.h>
27 #include <stdlib.h>
28 #include <wchar.h>
29 #include <stdbool.h>
31 extern __declspec(dllimport) bool send_fw(LPWSTR file, int filesize, void (*callback)(unsigned int progress, unsigned int max));
33 void usage(void)
35 fprintf(stderr, "usage: sendfirm <local filename>\n");
38 int filesize(char* filename)
40 FILE* fd;
41 int tmp;
42 fd = fopen(filename, "r");
43 if(fd == NULL)
45 fprintf(stderr, "Error while opening %s!\n", filename);
46 return -1;
48 fseek(fd, 0, SEEK_END);
49 tmp = ftell(fd);
50 fclose(fd);
51 return tmp;
54 void callback(unsigned int progress, unsigned int max)
56 unsigned int normalized = progress*1000/max;
57 printf("Progress: %d.%d%%\r", normalized/10, normalized%10);
58 fflush(stdout);
61 int main(int argc, char **argv)
63 if (argc < 2)
65 usage();
66 return 1;
69 wchar_t *tmp;
71 tmp = (LPWSTR)malloc(strlen(argv[1])*2+1);
72 mbstowcs(tmp, argv[1], strlen(argv[1])*2+1);
74 wprintf(tmp);
75 printf("\n");
77 fprintf(stdout, "Sending firmware...\n");
79 if(send_fw(tmp, filesize(argv[1]), &callback))
80 fprintf(stdout, "Firmware sent successfully!\n");
81 else
82 fprintf(stdout, "Error occured during sending!\n");
84 free(tmp);
86 exit(0);