Translation update done using Pootle.
[gammu.git] / gammu / nokia.c
blob9977cf10e418c3c45dc331d2298a09a266d322a0
1 #define _GNU_SOURCE /* For strcasestr */
2 #include <string.h>
4 #include "../helper/locales.h"
6 #include <gammu.h>
7 #include <stdlib.h>
8 #include <ctype.h>
10 #ifdef GSM_ENABLE_NOKIA_DCT3
11 # include "depend/nokia/dct3.h"
12 # include "depend/nokia/dct3trac/wmx.h"
13 #endif
14 #ifdef GSM_ENABLE_NOKIA_DCT4
15 # include "depend/nokia/dct4.h"
16 #endif
18 #include "nokia.h"
19 #include "common.h"
20 #include "files.h"
22 #include "../helper/formats.h"
23 #include "../helper/printing.h"
24 #include "../helper/string.h"
26 #if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
27 void NokiaComposer(int argc UNUSED, char *argv[])
29 GSM_Error error;
30 GSM_Ringtone ringtone;
31 gboolean started;
32 int i,j;
33 GSM_RingNote *Note;
34 GSM_RingNoteDuration Duration;
35 GSM_RingNoteDuration DefNoteDuration = 32; /* 32 = Duration_1_4 */
36 unsigned int DefNoteScale = Scale_880;
38 ringtone.Format = 0;
39 error=GSM_ReadRingtoneFile(argv[2],&ringtone);
40 Print_Error(error);
42 if (ringtone.Format != RING_NOTETONE) {
43 printf("%s\n", _("It can be RTTL ringtone only used with this option"));
44 Terminate(2);
47 started = FALSE;
48 j = 0;
49 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
50 if (ringtone.NoteTone.Commands[i].Type == RING_Note) {
51 Note = &ringtone.NoteTone.Commands[i].Note;
52 if (!started) {
53 if (Note->Note != Note_Pause) {
54 printf(_("Ringtone \"%s\" (tempo = %i Beats Per Minute)"),DecodeUnicodeConsole(ringtone.Name),GSM_RTTLGetTempo(Note->Tempo));
55 printf("\n\n");
56 started = TRUE;
59 if (started) j++;
62 if (j>50) {
63 printf_warn(_("length=%i notes, but you will enter only first 50 tones."), j);
66 printf("\n\n%s ", _("This ringtone in Nokia Composer in phone should look:"));
67 started = FALSE;
68 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
69 if (ringtone.NoteTone.Commands[i].Type == RING_Note) {
70 Note = &ringtone.NoteTone.Commands[i].Note;
71 if (!started) {
72 if (Note->Note != Note_Pause) started = TRUE;
74 if (started) {
75 switch (Note->Duration) {
76 case Duration_Full: printf("1"); break;
77 case Duration_1_2 : printf("2"); break;
78 case Duration_1_4 : printf("4"); break;
79 case Duration_1_8 : printf("8"); break;
80 case Duration_1_16: printf("16");break;
81 case Duration_1_32: printf("32");break;
83 if (Note->DurationSpec == DottedNote) printf(".");
84 switch (Note->Note) {
85 case Note_C : printf("c"); break;
86 case Note_Cis : printf("#c"); break;
87 case Note_D :printf("d"); break;
88 case Note_Dis : printf("#d"); break;
89 case Note_E : printf("e"); break;
90 case Note_F : printf("f"); break;
91 case Note_Fis : printf("#f"); break;
92 case Note_G : printf("g"); break;
93 case Note_Gis : printf("#g"); break;
94 case Note_A : printf("a"); break;
95 case Note_Ais : printf("#a"); break;
96 case Note_H : printf("h"); break;
97 case Note_Pause : printf("-"); break;
99 if (Note->Note != Note_Pause) printf("%i",Note->Scale - 4);
100 printf(" ");
105 printf("\n\n%s ", _("To enter it please press:"));
106 started = FALSE;
107 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
108 if (ringtone.NoteTone.Commands[i].Type == RING_Note) {
109 Note = &ringtone.NoteTone.Commands[i].Note;
110 if (!started) {
111 if (Note->Note != Note_Pause) started = TRUE;
113 if (started) {
114 switch (Note->Note) {
115 case Note_C : case Note_Cis: printf("1");break;
116 case Note_D : case Note_Dis: printf("2");break;
117 case Note_E : printf("3");break;
118 case Note_F : case Note_Fis: printf("4");break;
119 case Note_G : case Note_Gis: printf("5");break;
120 case Note_A : case Note_Ais: printf("6");break;
121 case Note_H : printf("7");break;
122 default : printf("0");break;
124 if (Note->DurationSpec == DottedNote) printf("%s", _("(longer)"));
125 switch (Note->Note) {
126 case Note_Cis: case Note_Dis:
127 case Note_Fis: case Note_Gis:
128 case Note_Ais:
129 printf("#");
130 break;
131 default :
132 break;
134 if (Note->Note != Note_Pause) {
135 if ((unsigned int)Note->Scale != DefNoteScale) {
136 while (DefNoteScale != (unsigned int)Note->Scale) {
137 printf("*");
138 DefNoteScale++;
139 if (DefNoteScale==Scale_7040) DefNoteScale = Scale_880;
143 Duration = 0;
144 switch (Note->Duration) {
145 case Duration_Full : Duration = 128; break;
146 case Duration_1_2 : Duration = 64; break;
147 case Duration_1_4 : Duration = 32; break;
148 case Duration_1_8 : Duration = 16; break;
149 case Duration_1_16 : Duration = 8; break;
150 case Duration_1_32 : Duration = 4; break;
151 default : fprintf(stderr, "error\n");break;
153 if (Duration > DefNoteDuration) {
154 while (DefNoteDuration != Duration) {
155 printf("9");
156 DefNoteDuration = DefNoteDuration * 2;
159 if (Duration < DefNoteDuration) {
160 while (DefNoteDuration != Duration) {
161 printf("8");
162 DefNoteDuration = DefNoteDuration / 2;
165 printf(" ");
170 printf("\n");
171 fflush(stdout);
174 void NokiaSecurityCode(int argc, char *argv[])
176 GSM_Init(TRUE);
178 #ifdef GSM_ENABLE_NOKIA_DCT3
179 if (CheckDCT3Only() != ERR_NOTSUPPORTED) {
180 DCT3GetSecurityCode(argc,argv);
182 #endif
183 #ifdef GSM_ENABLE_NOKIA_DCT4
184 if (CheckDCT4Only() != ERR_NOTSUPPORTED) {
185 /* DCT4ResetSecurityCode(argc, argv); */
186 DCT4GetSecurityCode(argc,argv);
188 #endif
190 GSM_Terminate();
193 void NokiaSetPhoneMenus(int argc, char *argv[])
195 GSM_Init(TRUE);
197 #ifdef GSM_ENABLE_NOKIA_DCT3
198 if (CheckDCT3Only() != ERR_NOTSUPPORTED) {
199 DCT3SetPhoneMenus (argc, argv);
201 #endif
202 #ifdef GSM_ENABLE_NOKIA_DCT4
203 if (CheckDCT4Only() != ERR_NOTSUPPORTED) {
204 DCT4SetPhoneMenus (argc, argv);
206 #endif
208 GSM_Terminate();
211 void NokiaSelfTests(int argc, char *argv[])
213 GSM_Init(TRUE);
215 #ifdef GSM_ENABLE_NOKIA_DCT3
216 if (CheckDCT3Only() != ERR_NOTSUPPORTED) {
217 DCT3SelfTests(argc, argv);
219 #endif
220 #ifdef GSM_ENABLE_NOKIA_DCT4
221 if (CheckDCT4Only() != ERR_NOTSUPPORTED) {
222 DCT4SelfTests(argc, argv);
224 #endif
226 GSM_Terminate();
229 typedef struct _PlayListEntry PlayListEntry;
231 struct _PlayListEntry {
232 unsigned char *Name;
233 unsigned char *NameUP;
234 PlayListEntry *Next;
237 void NokiaAddPlayLists2(unsigned char *ID,unsigned char *Name,unsigned char *IDFolder)
239 GSM_Error error;
240 gboolean Start = TRUE, Available = FALSE;
241 GSM_File Files,Files2,Files3;
242 int j,NamesPos2=0;
243 size_t i, NamesPos = 0;
244 unsigned char Buffer[20],Buffer2[500];
245 unsigned char *Names,*Names2,*Pointer;
246 PlayListEntry *First,*Entry=NULL,*Prev;
248 First = NULL; Names=NULL; Names2=NULL;
250 CopyUnicodeString(Files.ID_FullName,ID);
252 printf(_("Checking %s\n"),DecodeUnicodeString(Name));
253 /* looking into folder content (searching for mp3 and similiar) */
254 while (1) {
255 error = GSM_GetFolderListing(gsm,&Files,Start);
256 if (error == ERR_FOLDERPART) {
257 printf("%s\n", _(" Only part handled!"));
258 break;
260 if (error == ERR_EMPTY) break;
261 if (error == ERR_FILENOTEXIST) return;
262 Print_Error(error);
264 if (!Files.Folder) {
265 if (strcasestr(DecodeUnicodeConsole(Files.Name),".mp3")!=NULL ||
266 strcasestr(DecodeUnicodeConsole(Files.Name),".aac")!=NULL) {
267 if (First==NULL) {
268 First = malloc(sizeof(PlayListEntry));
269 Entry = First;
270 } else {
271 Entry->Next = malloc(sizeof(PlayListEntry));
272 Entry = Entry->Next;
274 Entry->Next = NULL;
275 Entry->Name = malloc(strlen(DecodeUnicodeString(Files.ID_FullName))+1);
276 sprintf(Entry->Name,"%s",DecodeUnicodeString(Files.ID_FullName));
277 /* converting Gammu drives to phone drives */
278 if (Entry->Name[0]=='a' || Entry->Name[0]=='A') {
279 Entry->Name[0]='b';
280 } else if (Entry->Name[0]=='d' || Entry->Name[0]=='D') {
281 Entry->Name[0]='a';
284 Entry->NameUP = malloc(strlen(DecodeUnicodeString(Files.ID_FullName))+1);
285 for (i = 0; i < strlen(DecodeUnicodeString(Files.ID_FullName)) + 1; i++) {
286 Entry->NameUP[i] = tolower(Entry->Name[i]);
289 } else {
290 Names = (unsigned char *)realloc(Names,NamesPos+UnicodeLength(Files.ID_FullName)*2+2);
291 CopyUnicodeString(Names+NamesPos,Files.ID_FullName);
292 NamesPos+=UnicodeLength(Files.ID_FullName)*2+2;
294 Names2 = (unsigned char *)realloc(Names2,NamesPos2+UnicodeLength(Files.Name)*2+2);
295 CopyUnicodeString(Names2+NamesPos2,Files.Name);
296 NamesPos2+=UnicodeLength(Files.Name)*2+2;
299 Start = FALSE;
301 if (First!=NULL) {
302 /* sorting songs names */
303 Entry=First;
304 while (Entry->Next!=NULL) {
305 if (strcmp(Entry->NameUP,Entry->Next->NameUP)>0) {
306 Pointer=Entry->Next->Name;
307 Entry->Next->Name = Entry->Name;
308 Entry->Name = Pointer;
310 Pointer=Entry->Next->NameUP;
311 Entry->Next->NameUP = Entry->NameUP;
312 Entry->NameUP = Pointer;
314 Entry=First;
315 continue;
317 Entry=Entry->Next;
319 /* we checking, if file already exist.if yes, we look for another... */
320 i = 0;
321 Files3.Buffer = NULL;
322 while (1) {
323 CopyUnicodeString(Files3.ID_FullName,IDFolder);
324 CopyUnicodeString(Buffer2,Name);
325 if (i!=0) {
326 sprintf(Buffer, "%ld", (long)i);
327 EncodeUnicode(Buffer2+UnicodeLength(Buffer2)*2,Buffer,strlen(Buffer));
329 EncodeUnicode(Buffer2+UnicodeLength(Buffer2)*2,".m3u",4);
331 Start = TRUE;
332 Available = FALSE;
333 while (1) {
334 error = GSM_GetFolderListing(gsm,&Files3,Start);
335 if (error == ERR_FOLDERPART) {
336 printf("%s\n", _(" Problem with adding playlist"));
337 break;
339 if (error == ERR_EMPTY) break;
340 Print_Error(error);
342 if (!Files3.Folder) {
343 if (mywstrncasecmp(Buffer2,Files3.Name,-1)) {
344 Available = TRUE;
345 break;
348 Start = FALSE;
350 if (!Available) break;
351 i++;
354 /* preparing new playlist file date */
355 Files2.System = FALSE;
356 Files2.Folder = FALSE;
357 Files2.ReadOnly = FALSE;
358 Files2.Hidden = FALSE;
359 Files2.Protected = FALSE;
360 Files2.ModifiedEmpty = FALSE;
361 GSM_GetCurrentDateTime (&Files2.Modified);
362 CopyUnicodeString(Files2.ID_FullName,IDFolder);
363 CopyUnicodeString(Files2.Name,Buffer2);
365 /* preparing new playlist file content */
366 Files2.Buffer=NULL;
367 Files2.Buffer = (unsigned char *)realloc(Files2.Buffer,10);
368 sprintf(Files2.Buffer,"#EXTM3U%c%c",13,10);
369 Files2.Used = 9;
370 Entry=First;
371 while (Entry!=NULL) {
372 Files2.Buffer = (unsigned char *)realloc(Files2.Buffer,Files2.Used+strlen(Entry->Name)+2+1);
373 sprintf(Files2.Buffer+Files2.Used,"%s%c%c",Entry->Name,13,10);
374 Files2.Used+=strlen(Entry->Name)+2;
375 Entry=Entry->Next;
377 Files2.Used -= 2;
378 for (i=0;i<Files2.Used;i++) {
379 if (Files2.Buffer[i]=='/') Files2.Buffer[i]='\\';
382 /* adding new playlist file */
383 sprintf(Buffer2, _("Writing file %s:"), DecodeUnicodeString(Files2.Name));
384 AddOneFile(&Files2, Buffer2, FALSE);
386 /* cleaning buffers */
387 free(Files2.Buffer);
388 Files2.Buffer=NULL;
389 while (Entry!=NULL) {
390 Entry=First;
391 Prev=NULL;
392 while (Entry->Next!=NULL) {
393 Prev=Entry;
394 Entry=Entry->Next;
396 free(Entry->Name);
397 free(Entry->NameUP);
398 free(Entry);
399 Entry=NULL;
400 if (Prev!=NULL) Prev->Next = NULL;
404 /* going into subfolders */
405 if (NamesPos != 0) {
406 i = 0; j = 0;
407 while (i != NamesPos) {
408 NokiaAddPlayLists2(Names+i,Names2+j,IDFolder);
409 i+=UnicodeLength(Names+i)*2+2;
410 j+=UnicodeLength(Names2+j)*2+2;
413 free(Names);
414 free(Names2);
417 void NokiaAddPlayLists(int argc UNUSED, char *argv[] UNUSED)
419 GSM_Error error;
420 gboolean Start = TRUE;
421 GSM_File Files;
422 unsigned char buffer[20],buffer2[20],IDFolder[100];
424 GSM_Init(TRUE);
426 /* delete old playlists */
427 EncodeUnicode(IDFolder,"d:\\predefplaylist",17);
428 CopyUnicodeString(Files.ID_FullName,IDFolder);
429 error = GSM_GetFolderListing(gsm,&Files,Start);
430 if (error == ERR_FILENOTEXIST) {
431 EncodeUnicode(IDFolder,"d:\\predefgallery\\predefplaylist",17+14);
432 CopyUnicodeString(Files.ID_FullName,IDFolder);
433 error = GSM_GetFolderListing(gsm,&Files,Start);
434 } else if (error != ERR_EMPTY) {
435 Print_Error(error);
437 if (error == ERR_FILENOTEXIST) {
438 printf("%s\n", _("Your phone model is not supported. Please report it to authors (see <http://wammu.eu/support/bugs/>). Thank you."));
439 GSM_Terminate();
440 Terminate(2);
441 } else if (error != ERR_EMPTY) {
442 Print_Error(error);
444 while (1) {
445 if (!Files.Folder) {
446 if (strstr(DecodeUnicodeConsole(Files.Name),".m3u")!=NULL) {
447 error = GSM_DeleteFile(gsm,Files.ID_FullName);
448 Print_Error(error);
451 Start = FALSE;
452 error = GSM_GetFolderListing(gsm,&Files,Start);
453 if (error == ERR_FOLDERPART) {
454 printf("%s\n", _("Problem with deleting playlist"));
455 break;
457 if (error == ERR_EMPTY) break;
458 Print_Error(error);
461 /* go over phone memory and add new one playlists */
462 EncodeUnicode(buffer,"d:",2);
463 EncodeUnicode(buffer2,"root",4);
464 NokiaAddPlayLists2(buffer,buffer2,IDFolder);
465 /* go over memory card and add new one playlists */
466 EncodeUnicode(buffer,"a:",2);
467 EncodeUnicode(buffer2,"root",4);
468 NokiaAddPlayLists2(buffer,buffer2,IDFolder);
470 GSM_Terminate();
473 struct NokiaFolderInfo {
474 const char *model;
475 const char *parameter;
476 const char *folder;
477 const char *level;
480 struct NokiaFolderInfo Folder[] = {
481 /* Language indepedent in DCT4 in filesystem 1 */
482 {"", "Application", "applications", "3"},
483 {"", "Game", "games", "3"},
484 /* Language indepedent in DCT4/TIKU/BB5 in filesystem 2 */
485 {"", "Gallery", "d:/predefgallery/predefgraphics", ""},
486 {"", "Gallery2", "d:/predefgallery/predefgraphics/predefcliparts", ""},
487 {"", "Camera", "d:/predefgallery/predefphotos", ""},
488 {"", "Tones", "d:/predefgallery/predeftones", ""},
489 {"", "Tones2", "d:/predefgallery/predefmusic", ""},
490 {"", "Records", "d:/predefgallery/predefrecordings", ""},
491 {"", "Video", "d:/predefgallery/predefvideos", ""},
492 {"", "Playlist", "d:/predefplaylist", ""},
493 {"", "MemoryCard", "a:", ""},
494 /* now values first seen in S40 3.0 */
495 {"", "Application", "d:/predefjava/predefcollections", ""},
496 {"", "Game", "d:/predefjava/predefgames", ""},
498 /* Language depedent in DCT4 filesystem 1 */
499 {"", "Gallery", "Clip-arts", "3"},
500 {"", "Gallery", "004F006200720061007A006B0069", "3"},/* obrazki PL 6220 */
501 {"", "Gallery", "Pictures", "2"},/* 3510 */
502 {"", "Gallery2", "Graphics", "3"},
503 {"", "Gallery2", "00470072006100660069006B0061", "3"},/* grafika PL 6220 */
504 {"", "Camera", "Images", "3"},
505 {"", "Camera", "005A0064006A0119006300690061", "3"},/* zdjecia PL 6220 */
506 {"", "Tones", "Tones", "3"},
507 {"", "Tones", "0044017A007700690119006B0069", "3"},/* dzwieki pl 6220 */
508 {"", "Records", "Recordings", "3"},
509 {"", "Records", "004E0061006700720061006E00690061", "3"},/* nagrania pl 6220 */
510 {"", "Video", "Video clips", "3"},
511 {"", "Video", "0057006900640065006F006B006C006900700079", "3"},/* wideoklipy pl 6220 */
513 /* Language indepedent in OBEX */
514 {"obex", "MMSUnreadInbox", "predefMessages\\predefINBOX", ""},
515 {"obex", "MMSReadInbox", "predefMessages\\predefINBOX", ""},
516 {"obex", "MMSOutbox", "predefMessages\\predefOUTBOX", ""},
517 {"obex", "MMSSent", "predefMessages\\predefSENT", ""},
518 {"obex", "MMSDrafts", "predefMessages\\predefDRAFTS", ""},
519 /* {"obex", "Application, "predefjava\\predefapplications", ""}, */
520 /* {"obex", "Game", "predefjava\\predefgames", ""}, */
521 {"obex", "Gallery", "predefgallery\\predefgraphics", ""},
522 {"obex", "Tones", "predefgallery\\predeftones", ""},
524 /* End of list */
525 {"", "", "", ""}
528 void NokiaAddFile(int argc, char *argv[])
530 GSM_Error error;
531 GSM_File File, Files, File2;
532 FILE *file;
533 unsigned char buffer[10000],JAR[500],Vendor[500],Name[500],Version[500],FileID[400];
534 gboolean Start = TRUE, Found = FALSE, wasclr;
535 gboolean ModEmpty = FALSE, Overwrite = FALSE, OverwriteAll = FALSE;
536 size_t i = 0, Pos;
537 int Size, Size2;
538 int nextlong, j;
540 while (Folder[i].parameter[0] != 0) {
541 if (strcasecmp(argv[2],Folder[i].parameter) == 0) {
542 Found = TRUE;
543 break;
545 i++;
547 if (!Found) {
548 printf(_("What folder type (\"%s\") ?\n"),argv[2]);
549 Terminate(2);
552 if (strcasecmp(argv[2],"Application") == 0 || strcasecmp(argv[2],"Game") == 0) {
553 sprintf(buffer, "%s.jad", argv[3]);
554 file = fopen(buffer, "rb");
555 if (file == NULL) {
556 printf_err(_("Can not open file %s\n"), buffer);
557 Print_Error(ERR_CANTOPENFILE);
559 fclose(file);
560 sprintf(buffer, "%s.jar", argv[3]);
561 file = fopen(buffer, "rb");
562 if (file == NULL) {
563 printf_err(_("Can not open file %s\n"), buffer);
564 Print_Error(ERR_CANTOPENFILE);
566 fclose(file);
567 } else {
568 file = fopen(argv[3],"rb");
569 if (file == NULL) {
570 printf_err(_("Can not open file %s\n"), argv[3]);
571 Print_Error(ERR_CANTOPENFILE);
573 fclose(file);
576 GSM_Init(TRUE);
578 Found = FALSE;
579 if (GSM_GetUsedConnection(gsm) == GCT_IRDAOBEX || GSM_GetUsedConnection(gsm) == GCT_BLUEOBEX) {
580 i = 0;
581 while (Folder[i].parameter[0] != 0) {
582 if (!strcmp("obex",Folder[i].model) &&
583 strcasecmp(argv[2],Folder[i].parameter) == 0) {
584 EncodeUnicode(Files.ID_FullName,Folder[i].folder,strlen(Folder[i].folder));
585 Found = TRUE;
586 break;
588 i++;
590 if (!Found) {
591 printf("%s\n", _("Folder not found. Probably function not supported!"));
592 GSM_Terminate();
593 Terminate(2);
595 } else if (GSM_IsPhoneFeatureAvailable(GSM_GetModelInfo(gsm), F_FILES2)) {
596 i = 0;
597 while (Folder[i].parameter[0] != 0) {
598 if ((Folder[i].folder[0] == 'a' || Folder[i].folder[0] == 'd') &&
599 Folder[i].level[0] == 0x00 &&
600 strcasecmp(argv[2],Folder[i].parameter) == 0) {
601 if (strstr(Folder[i].folder,"d:/predefjava/")!= NULL &&
602 !GSM_IsPhoneFeatureAvailable(GSM_GetModelInfo(gsm), F_SERIES40_30)) {
603 i++;
604 continue;
606 EncodeUnicode(Files.ID_FullName,Folder[i].folder,strlen(Folder[i].folder));
607 Found = TRUE;
608 break;
610 i++;
613 if (!Found) {
614 fprintf(stderr, "%s", _("Searching for phone folder: "));
615 while (1) {
616 error = GSM_GetNextFileFolder(gsm,&Files,Start);
617 if (error == ERR_EMPTY) break;
618 Print_Error(error);
620 if (Files.Folder) {
621 smprintf(gsm, "folder %s level %i\n",DecodeUnicodeConsole(Files.Name),Files.Level);
622 Found = FALSE;
623 i = 0;
624 while (Folder[i].parameter[0] != 0) {
625 EncodeUnicode(buffer,Folder[i].folder,strlen(Folder[i].folder));
626 smprintf(gsm, "comparing \"%s\" \"%s\" \"%s\"\n",GSM_GetModelInfo(gsm)->model,DecodeUnicodeString(Files.ID_FullName),Folder[i].level);
627 if (strcasecmp(argv[2],Folder[i].parameter) == 0 &&
628 mywstrncasecmp(Files.Name,buffer,0) &&
629 Files.Level == atoi(Folder[i].level)) {
630 smprintf(gsm, "found 1\n");
631 Found = TRUE;
632 break;
634 if (strcasecmp(argv[2],Folder[i].parameter) == 0 &&
635 !strcmp(DecodeUnicodeString(Files.ID_FullName),Folder[i].folder) &&
636 Folder[i].level[0] == 0x00) {
637 Found = TRUE;
638 smprintf(gsm, "found 2\n");
639 break;
641 if (Folder[i].folder[0]>='0'&&Folder[i].folder[0] <='9') {
642 DecodeHexUnicode (buffer, Folder[i].folder,strlen(Folder[i].folder));
643 smprintf(gsm, "comparing \"%s\"",DecodeUnicodeString(buffer));
644 smprintf(gsm, "and \"%s\"\n",DecodeUnicodeString(Files.Name));
645 if (strcasecmp(argv[2],Folder[i].parameter) == 0 &&
646 mywstrncasecmp(Files.Name,buffer,0) &&
647 Files.Level == atoi(Folder[i].level)) {
648 Found = TRUE;
649 smprintf(gsm, "found 3\n");
650 break;
653 i++;
655 if (Found) break;
657 fprintf(stderr, "*");
659 Start = FALSE;
661 fprintf(stderr, "\n");
662 fflush(stderr);
664 if (!Found) {
665 printf("%s\n", _("Folder not found. Probably function not supported!"));
666 GSM_Terminate();
667 Terminate(2);
669 File.Buffer = NULL;
670 File.Protected = FALSE;
671 File.ReadOnly = FALSE;
672 File.Hidden = FALSE;
673 File.System = FALSE;
675 if (strcasecmp(argv[2],"Application") == 0 || strcasecmp(argv[2],"Game") == 0) {
676 /* reading jar file */
677 sprintf(buffer,"%s.jar",argv[3]);
678 error = GSM_ReadFile(buffer, &File);
679 Print_Error(error);
680 Size2 = File.Used;
682 /* reading jad file */
683 sprintf(buffer,"%s.jad",argv[3]);
684 error = GSM_ReadFile(buffer, &File);
685 Print_Error(error);
687 /* Getting values from JAD file */
688 error = GSM_JADFindData(&File, Vendor, Name, JAR, Version, &Size);
689 if (error == ERR_FILENOTSUPPORTED) {
690 if (Vendor[0] == 0x00) {
691 fprintf(stderr, "%s\n", _("No vendor info in JAD file"));
692 GSM_Terminate();
693 return;
695 if (Name[0] == 0x00) {
696 fprintf(stderr, "%s\n", _("No name info in JAD file"));
697 GSM_Terminate();
698 return;
700 if (JAR[0] == 0x00) {
701 fprintf(stderr, "%s\n", _("No JAR URL info in JAD file"));
702 GSM_Terminate();
703 return;
706 if (Size != Size2) {
707 printf_info("%s\n", _("Declared JAR file size is different than real. Fixed by Gammu."));
708 for (i=0;i<File.Used;i++) {
709 if (strncasecmp(File.Buffer+i,"MIDlet-Jar-Size: ",17) == 0) {
710 break;
713 Pos = i;
714 while (TRUE) {
715 if (Pos ==0 || File.Buffer[Pos] == 13 || File.Buffer[Pos] == 10) break;
716 Pos--;
718 i+= 15;
719 while (TRUE) {
720 if (i == File.Used || File.Buffer[i] == 13 || File.Buffer[i] == 10) break;
721 i++;
723 while (i != File.Used) {
724 File.Buffer[Pos] = File.Buffer[i];
725 i++;
726 Pos++;
728 File.Used = File.Used - (i - Pos);
729 File.Buffer = realloc(File.Buffer,File.Used);
730 } else if (Size == -1) {
731 printf_info("%s\n", _("No JAR size info in JAD file. Added by Gammu."));
733 if (Size != Size2) {
734 sprintf(buffer,"\nMIDlet-Jar-Size: %i",Size2);
735 File.Buffer = realloc(File.Buffer,File.Used + strlen(buffer));
736 memcpy(File.Buffer+File.Used,buffer,strlen(buffer));
737 File.Used += strlen(buffer);
738 Size = Size2;
740 fprintf(stderr, _("Adding \"%s\""),Name);
741 if (Version[0] != 0x00) fprintf(stderr, _(" version %s"),Version);
742 fprintf(stderr, _(" created by %s\n"),Vendor);
744 /* Bostjan Muller 3200 RH-30 3.08 */
745 if (strstr(JAR,"http://") != NULL) {
746 i = strlen(JAR)-1;
747 while (JAR[i] != '/') i--;
748 strcpy(buffer,JAR+i+1);
749 strcpy(JAR,buffer);
750 smprintf(gsm, "New file name is \"%s\"\n",JAR);
753 /* Changing all #13 or #10 to #13#10 in JAD */
754 Pos = 0;
755 wasclr = FALSE;
756 for (i=0;i<File.Used;i++) {
757 switch (File.Buffer[i]) {
758 case 0x0D:
759 case 0x0A:
760 if (!wasclr) {
761 buffer[Pos++] = 0x0D;
762 buffer[Pos++] = 0x0A;
763 wasclr = TRUE;
764 } else wasclr = FALSE;
765 break;
766 default:
767 buffer[Pos++] = File.Buffer[i];
768 wasclr = FALSE;
771 File.Buffer = realloc(File.Buffer, Pos);
772 File.Used = Pos;
773 memcpy(File.Buffer,buffer,Pos);
775 if (argc > 4) {
776 for (j = 4; j < argc; j++) {
777 if (strcasecmp(argv[j],"-overwrite") == 0) Overwrite = TRUE;
778 if (strcasecmp(argv[j],"-overwriteall") == 0) {
779 Overwrite = TRUE;
780 OverwriteAll = TRUE;
785 /* adding folder */
786 if (strstr(DecodeUnicodeString(Files.ID_FullName),"d:/predefjava/")== NULL) {
787 strcpy(buffer,Vendor);
788 strcat(buffer,Name);
789 EncodeUnicode(File.Name,buffer,strlen(buffer));
790 CopyUnicodeString(File.ID_FullName,Files.ID_FullName);
791 error = GSM_AddFolder(gsm,&File);
792 if (Overwrite && (error == ERR_FILEALREADYEXIST)) {
793 printf_info("%s\n", _("Application already exists. Deleting by Gammu."));
795 Start = TRUE;
796 CopyUnicodeString(File2.ID_FullName,Files.ID_FullName);
797 while (1) {
798 error = GSM_GetFolderListing(gsm,&File2,Start);
799 if (error == ERR_EMPTY) break;
800 Print_Error(error);
802 if (File2.Folder && !strcmp(DecodeUnicodeString(File2.Name),buffer)) {
803 break;
806 Start = FALSE;
809 Start = TRUE;
810 CopyUnicodeString(File.ID_FullName,File2.ID_FullName);
811 while (1) {
812 error = GSM_GetFolderListing(gsm,&File2,Start);
813 if (error == ERR_EMPTY) break;
814 Print_Error(error);
816 strcpy(buffer,DecodeUnicodeString(File2.Name));
818 i = strlen(buffer);
819 if (i < 4) continue;
821 i -= 4;
823 if (OverwriteAll ||
824 strcmp(buffer + i,".jad") == 0 ||
825 strcmp(buffer + i,".jar") == 0) {
826 fprintf(stderr, _(" Deleting %s\n"),buffer);
827 error = GSM_DeleteFile(gsm,File2.ID_FullName);
828 Print_Error(error);
830 CopyUnicodeString(File2.ID_FullName,File.ID_FullName);
831 Start = TRUE;
832 } else {
833 Start = FALSE;
836 } else {
837 Print_Error(error);
839 CopyUnicodeString(FileID,File.ID_FullName);
840 } else {
841 if (Overwrite) {
842 Start = TRUE;
843 CopyUnicodeString(File2.ID_FullName,Files.ID_FullName);
845 printf_info("%s\n", _("Application already exists. Deleting by Gammu."));
847 while (TRUE) {
848 error = GSM_GetFolderListing(gsm,&File2,Start);
849 if (error == ERR_EMPTY) break;
850 Print_Error(error);
852 strcpy(buffer,DecodeUnicodeString(File2.Name));
854 i = strlen(Name);
855 if (strncmp(buffer,Name,i) == 0 &&
856 (strcmp(buffer + i,".jad") == 0 ||
857 strcmp(buffer + i,".jar") == 0 ||
858 (strncmp(buffer + i,"\177_m_",4) == 0 && OverwriteAll))) {
859 fprintf(stderr, _(" Deleting %s\n"),buffer);
860 error = GSM_DeleteFile(gsm,File2.ID_FullName);
861 Print_Error(error);
863 CopyUnicodeString(File2.ID_FullName,Files.ID_FullName);
864 Start = TRUE;
865 } else {
866 Start = FALSE;
871 CopyUnicodeString(FileID,Files.ID_FullName);
872 CopyUnicodeString(File.ID_FullName,Files.ID_FullName);
875 /* adding jad file */
876 strcpy(buffer,JAR);
877 buffer[strlen(buffer) - 1] = 'd';
878 EncodeUnicode(File.Name,buffer,strlen(buffer));
879 File.Type = GSM_File_Other;
880 File.ModifiedEmpty = TRUE;
881 smprintf(gsm, "file id is \"%s\"\n",DecodeUnicodeString(File.ID_FullName));
882 AddOneFile(&File, _("Writing JAD file:"), FALSE);
884 if (argc > 4) {
885 for (j = 4; j < argc; j++) {
886 if (strcasecmp(argv[j],"-readonly") == 0) File.ReadOnly = TRUE;
890 /* reading jar file */
891 sprintf(buffer,"%s.jar",argv[3]);
892 error = GSM_ReadFile(buffer, &File);
893 Print_Error(error);
895 /* adding jar file */
896 CopyUnicodeString(File.ID_FullName,FileID);
897 strcpy(buffer,JAR);
898 EncodeUnicode(File.Name,buffer,strlen(buffer));
899 File.Type = GSM_File_Java_JAR;
900 File.ModifiedEmpty = TRUE;
901 AddOneFile(&File, _("Writing JAR file:"), FALSE);
902 free(File.Buffer);
903 GSM_Terminate();
904 return;
907 if (strcasecmp(argv[2],"Gallery" ) == 0 ||
908 strcasecmp(argv[2],"Gallery2" ) == 0 ||
909 strcasecmp(argv[2],"Camera" ) == 0 ||
910 strcasecmp(argv[2],"Tones" ) == 0 ||
911 strcasecmp(argv[2],"Tones2" ) == 0 ||
912 strcasecmp(argv[2],"Records" ) == 0 ||
913 strcasecmp(argv[2],"Video" ) == 0 ||
914 strcasecmp(argv[2],"Playlist" ) == 0 ||
915 strcasecmp(argv[2],"MemoryCard" ) == 0) {
916 strcpy(buffer,argv[3]);
917 if (argc > 4) {
918 nextlong = 0;
919 for (j = 4; j < argc; j++) {
920 switch(nextlong) {
921 case 0:
922 if (strcasecmp(argv[j],"-name") == 0) {
923 nextlong = 1;
924 continue;
926 if (strcasecmp(argv[j],"-protected") == 0) {
927 File.Protected = TRUE;
928 continue;
930 if (strcasecmp(argv[j],"-readonly") == 0) {
931 File.ReadOnly = TRUE;
932 continue;
934 if (strcasecmp(argv[j],"-hidden") == 0) {
935 File.Hidden = TRUE;
936 continue;
938 if (strcasecmp(argv[j],"-system") == 0) {
939 File.System = TRUE;
940 continue;
942 if (strcasecmp(argv[j],"-newtime") == 0) {
943 ModEmpty = TRUE;
944 continue;
946 printf(_("Parameter \"%s\" unknown\n"),argv[j]);
947 Terminate(2);
948 case 1:
949 strcpy(buffer,argv[j]);
950 nextlong = 0;
951 break;
954 if (nextlong!=0) {
955 printf_err("%s\n", _("Parameter missing!"));
956 Terminate(2);
961 error = GSM_ReadFile(argv[3], &File);
962 Print_Error(error);
963 if (ModEmpty) File.ModifiedEmpty = TRUE;
965 CopyUnicodeString(File.ID_FullName,Files.ID_FullName);
966 EncodeUnicode(File.Name,buffer,strlen(buffer));
967 for (i=strlen(buffer)-1;i>0;i--) {
968 if (buffer[i] == '\\' || buffer[i] == '/') break;
970 if (buffer[i] == '\\' || buffer[i] == '/') {
971 EncodeUnicode(File.Name,buffer+i+1,strlen(buffer)-i-1);
974 GSM_IdentifyFileFormat(&File);
976 AddOneFile(&File, _("Writing file:"), FALSE);
977 free(File.Buffer);
978 GSM_Terminate();
981 void NokiaGetADC(int argc, char *argv[])
983 GSM_Init(TRUE);
985 #ifdef GSM_ENABLE_NOKIA_DCT3
986 if (CheckDCT3Only() != ERR_NOTSUPPORTED) {
987 DCT3GetADC(argc,argv);
989 #endif
990 #ifdef GSM_ENABLE_NOKIA_DCT4
991 if (CheckDCT4Only() != ERR_NOTSUPPORTED) {
992 DCT4GetADC(argc, argv);
994 #endif
996 GSM_Terminate();
999 void NokiaDisplayTest(int argc, char *argv[])
1001 GSM_Init(TRUE);
1003 #ifdef GSM_ENABLE_NOKIA_DCT3
1004 if (CheckDCT3Only() != ERR_NOTSUPPORTED) {
1005 DCT3DisplayTest(argc,argv);
1007 #endif
1008 #ifdef GSM_ENABLE_NOKIA_DCT4
1009 if (CheckDCT4Only() != ERR_NOTSUPPORTED) {
1010 DCT4DisplayTest(argc, argv);
1012 #endif
1014 GSM_Terminate();
1017 void NokiaGetT9(int argc, char *argv[])
1019 GSM_Init(TRUE);
1021 #ifdef GSM_ENABLE_NOKIA_DCT3
1022 if (CheckDCT3Only() != ERR_NOTSUPPORTED) {
1023 DCT3GetT9(argc,argv);
1025 #endif
1026 #ifdef GSM_ENABLE_NOKIA_DCT4
1027 if (CheckDCT4Only() != ERR_NOTSUPPORTED) {
1028 DCT4GetT9(argc, argv);
1030 #endif
1032 GSM_Terminate();
1035 void NokiaVibraTest(int argc, char *argv[])
1037 GSM_Init(TRUE);
1039 #ifdef GSM_ENABLE_NOKIA_DCT3
1040 if (CheckDCT3Only() != ERR_NOTSUPPORTED) {
1041 DCT3VibraTest(argc,argv);
1043 #endif
1044 #ifdef GSM_ENABLE_NOKIA_DCT4
1045 if (CheckDCT4Only() != ERR_NOTSUPPORTED) {
1046 DCT4VibraTest(argc, argv);
1048 #endif
1050 GSM_Terminate();
1052 #endif
1054 /* How should editor hadle tabs in this file? Add editor commands here.
1055 * vim: noexpandtab sw=8 ts=8 sts=8: