Translation update done using Pootle.
[gammu.git] / gammu / backup.c
blob7226b8796dabf15b4e0a329a95a74071555ecec5
1 #include "../helper/locales.h"
3 #include <gammu.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <signal.h>
8 #include "backup.h"
9 #include "memory.h"
10 #include "message.h"
11 #include "common.h"
12 #include "../helper/formats.h"
14 #include "../helper/message-display.h"
15 #include "../helper/memory-display.h"
16 #include "../helper/printing.h"
17 #include "../helper/string.h"
18 #include "../helper/cmdline.h"
20 /**
21 * Converts between two backup formats.
23 void ConvertBackup(int argc, char *argv[])
25 GSM_Backup Backup;
26 GSM_Error error;
28 error = GSM_ReadBackupFile(argv[2], &Backup, GSM_GuessBackupFormat(argv[2], FALSE));
29 Print_Error(error);
31 error = GSM_SaveBackupFile(argv[3], &Backup, GSM_GuessBackupFormat(argv[3], FALSE));
32 GSM_FreeBackup(&Backup);
33 Print_Error(error);
36 void SaveFile(int argc, char *argv[])
38 GSM_Error error;
39 GSM_Backup Backup;
40 int i;
41 size_t data_size = 0;
42 FILE *file;
43 unsigned char Buffer[100000];
44 GSM_MemoryEntry *pbk;
45 long int location;
47 if (strcasecmp(argv[2],"CALENDAR") == 0) {
48 if (argc < 5) {
49 printf("%s\n", _("Where is backup filename and location?"));
50 Terminate(2);
52 location = GetInt(argv[5]) - 1;
53 error = GSM_ReadBackupFile(argv[4], &Backup,GSM_GuessBackupFormat(argv[4], FALSE));
54 if (error != ERR_NOTIMPLEMENTED) {
55 Print_Error(error);
57 i = 0;
58 while (Backup.Calendar[i] != NULL) {
59 if (i == location) break;
60 i++;
62 if (i != location || Backup.Calendar[i] == NULL) {
63 printf("%s\n", _("Calendar note not found in file"));
64 GSM_FreeBackup(&Backup);
65 Terminate(2);
67 error = GSM_EncodeVCALENDAR(Buffer, sizeof(Buffer), &data_size, Backup.Calendar[i],TRUE,Nokia_VCalendar);
68 GSM_FreeBackup(&Backup);
69 Print_Error(error);
70 } else if (strcasecmp(argv[2],"BOOKMARK") == 0) {
71 if (argc < 5) {
72 printf("%s\n", _("Where is backup filename and location?"));
73 Terminate(2);
75 location = GetInt(argv[5]) - 1;
76 error = GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE));
77 if (error != ERR_NOTIMPLEMENTED) {
78 Print_Error(error);
80 i = 0;
81 while (Backup.WAPBookmark[i]!=NULL) {
82 if (i == location) break;
83 i++;
85 if (i != location || Backup.WAPBookmark[i] == NULL) {
86 printf("%s\n", _("WAP bookmark not found in file"));
87 GSM_FreeBackup(&Backup);
88 Terminate(2);
90 error = GSM_EncodeURLFile(Buffer, &data_size, Backup.WAPBookmark[i]);
91 GSM_FreeBackup(&Backup);
92 Print_Error(error);
93 } else if (strcasecmp(argv[2],"NOTE") == 0) {
94 if (argc<5) {
95 printf("%s\n", _("Where is backup filename and location?"));
96 Terminate(2);
98 location = GetInt(argv[5]) - 1;
99 error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE));
100 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
101 i = 0;
102 while (Backup.Note[i]!=NULL) {
103 if (i == location) break;
104 i++;
106 if (i != location || Backup.Note[i] == NULL) {
107 printf("%s\n", _("Note not found in file"));
108 GSM_FreeBackup(&Backup);
109 Terminate(2);
111 error = GSM_EncodeVNTFile(Buffer, sizeof(Buffer), &data_size, Backup.Note[i]);
112 GSM_FreeBackup(&Backup);
113 Print_Error(error);
114 } else if (strcasecmp(argv[2],"TODO") == 0) {
115 if (argc<5) {
116 printf("%s\n", _("Where is backup filename and location?"));
117 Terminate(2);
119 location = GetInt(argv[5]) - 1;
120 error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE));
121 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
122 i = 0;
123 while (Backup.ToDo[i]!=NULL) {
124 if (i == location) break;
125 i++;
127 if (i != location || Backup.ToDo[i] == NULL) {
128 printf("%s\n", _("Todo note not found in file"));
129 GSM_FreeBackup(&Backup);
130 Terminate(2);
132 error = GSM_EncodeVTODO(Buffer, sizeof(Buffer), &data_size, Backup.ToDo[i], TRUE, Nokia_VToDo);
133 GSM_FreeBackup(&Backup);
134 Print_Error(error);
135 } else if (strcasecmp(argv[2],"VCARD10") == 0 || strcasecmp(argv[2],"VCARD21") == 0) {
136 if (argc<6) {
137 printf("%s\n", _("Where is backup filename and location and memory type?"));
138 Terminate(2);
140 location = GetInt(argv[6]) - 1;
141 error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE));
142 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
143 i = 0;
144 if (strcasecmp(argv[5],"SM") == 0) {
145 while (Backup.SIMPhonebook[i]!=NULL) {
146 if (i == location) break;
147 i++;
149 if (i != location || Backup.SIMPhonebook[i] == NULL) {
150 printf("%s\n", _("Phonebook entry not found in file"));
151 GSM_FreeBackup(&Backup);
152 Terminate(2);
154 pbk = Backup.SIMPhonebook[i];
155 } else if (strcasecmp(argv[5],"ME") == 0) {
156 while (Backup.PhonePhonebook[i]!=NULL) {
157 if (i == location) break;
158 i++;
160 if (i != location || Backup.PhonePhonebook[i] == NULL) {
161 printf("%s\n", _("Phonebook entry not found in file"));
162 GSM_FreeBackup(&Backup);
163 Terminate(2);
165 pbk = Backup.PhonePhonebook[i];
166 } else {
167 printf(_("Unknown memory type: \"%s\"\n"),argv[5]);
168 GSM_FreeBackup(&Backup);
169 Terminate(2);
171 if (strcasecmp(argv[2],"VCARD10") == 0) {
172 error = GSM_EncodeVCARD(GSM_GetDebug(gsm), Buffer, sizeof(Buffer), &data_size, pbk, TRUE, Nokia_VCard10);
173 GSM_FreeBackup(&Backup);
174 Print_Error(error);
175 } else {
176 error = GSM_EncodeVCARD(GSM_GetDebug(gsm), Buffer, sizeof(Buffer), &data_size, pbk, TRUE, Nokia_VCard21);
177 GSM_FreeBackup(&Backup);
178 Print_Error(error);
180 } else {
181 printf(_("Unknown backup format: \"%s\"\n"), argv[2]);
182 Terminate(2);
185 file = fopen(argv[3],"wb");
186 if (file == NULL) {
187 printf_err("%s", _("Error while opening file for writing!\n"));
188 Terminate(3);
190 if (data_size != fwrite(Buffer,1,data_size,file)) {
191 printf_err("%s", _("Error while writing file!\n"));
193 if (fclose(file) != 0) {
194 printf_err("%s", _("Error while closing file!\n"));
199 * Reads phone phonebook, optionally asking question whether to read it.
201 GSM_Error ReadPhonebook(GSM_MemoryEntry **Phonebook, GSM_MemoryType MemoryType, const char *question, int max_entries, ReadPhonebookCallback callback, gboolean progress)
203 GSM_MemoryStatus MemStatus;
204 GSM_MemoryEntry Pbk;
205 GSM_Error error;
206 gboolean UseNext = FALSE;
207 int i, used;
209 memset(&Pbk, 0, sizeof(GSM_MemoryEntry));
210 MemStatus.MemoryType = MemoryType;
211 Pbk.MemoryType = MemoryType;
212 Pbk.Location = 0;
214 UseNext = FALSE;
215 error = GSM_GetMemoryStatus(gsm, &MemStatus);
216 if (error == ERR_NONE) {
217 if (MemStatus.MemoryUsed == 0) {
218 return ERR_NONE;
220 error = GSM_GetNextMemory(gsm, &Pbk, TRUE);
221 if (error == ERR_NONE) {
222 UseNext = TRUE;
224 } else {
225 MemStatus.MemoryUsed = 0;
226 UseNext = TRUE;
227 error = GSM_GetNextMemory(gsm, &Pbk, TRUE);
228 if (error != ERR_NONE) {
229 return error;
233 /* Optionally ask question */
234 if (question != NULL && !answer_yes(" %s", question)) {
235 return ERR_NONE;
238 if (UseNext) {
239 used = 0;
240 if (progress) {
241 fprintf(stderr, LISTFORMAT, _("Reading"));
243 error = ERR_NONE;
244 while (error == ERR_NONE) {
245 if (Phonebook != NULL) {
246 if (used >= max_entries) {
247 printf("\n %s\n", _("Only part of data saved, please increase the limit."));
248 break;
250 Phonebook[used] = malloc(sizeof(GSM_MemoryEntry));
251 if (Phonebook[used] == NULL) {
252 Print_Error(ERR_MOREMEMORY);
254 Phonebook[used+1] = NULL;
255 *Phonebook[used] = Pbk;
257 if (callback != NULL) {
258 error = callback(&Pbk, gsm);
259 Print_Error(error);
261 used++;
262 error = GSM_GetNextMemory(gsm, &Pbk, FALSE);
263 if (progress) {
264 if (MemStatus.MemoryUsed == 0) {
265 fprintf(stderr, "*");
266 } else {
267 fprintf(stderr, "\r ");
268 fprintf(stderr, "%s ", _("Reading:"));
269 fprintf(stderr, _("%i percent"),
270 used * 100 / MemStatus.MemoryUsed);
273 if (gshutdown) {
274 GSM_Terminate();
275 Terminate(4);
278 if (progress) {
279 fprintf(stderr, "\n");
280 fflush(stderr);
282 } else {
283 i = 1;
284 used = 0;
285 while (used < MemStatus.MemoryUsed) {
286 Pbk.Location = i;
287 error = GSM_GetMemory(gsm, &Pbk);
288 if (error != ERR_EMPTY) {
289 Print_Error(error);
290 if (Phonebook != NULL) {
291 if (used >= max_entries) {
292 printf("\n %s\n", _("Only part of data saved, please increase the limit."));
293 break;
295 Phonebook[used] = malloc(sizeof(GSM_MemoryEntry));
296 if (Phonebook[used] == NULL) {
297 Print_Error(ERR_MOREMEMORY);
299 Phonebook[used+1] = NULL;
300 *Phonebook[used] = Pbk;
302 if (callback != NULL) {
303 error = callback(&Pbk, gsm);
304 Print_Error(error);
306 used++;
308 if (progress) {
309 fprintf(stderr, "\r ");
310 fprintf(stderr, "%s ", _("Reading:"));
311 fprintf(stderr, _("%i percent"),
312 used * 100 / MemStatus.MemoryUsed);
314 i++;
315 if (gshutdown) {
316 GSM_Terminate();
317 Terminate(4);
320 if (progress) {
321 fprintf(stderr, "\n");
322 fflush(stderr);
325 return ERR_NONE;
328 void DoBackup(int argc, char *argv[])
330 GSM_Error error = ERR_NONE;
331 int i, used;
332 GSM_ToDoEntry ToDo;
333 GSM_ToDoStatus ToDoStatus;
334 GSM_CalendarEntry Calendar;
335 GSM_Bitmap Bitmap;
336 GSM_WAPBookmark Bookmark;
337 GSM_Profile Profile;
338 GSM_MultiWAPSettings Settings;
339 GSM_SyncMLSettings SyncML;
340 GSM_ChatSettings Chat;
341 GSM_Ringtone Ringtone;
342 GSM_SMSC SMSC;
343 GSM_Backup Backup;
344 GSM_NoteEntry Note;
345 GSM_Backup_Info Info;
346 GSM_FMStation FMStation;
347 GSM_GPRSAccessPoint GPRSPoint;
348 gboolean DoBackupPart;
349 char buffer[GSM_MAX_INFO_LENGTH];
351 if (argc == 4 && strcasecmp(argv[3],"-yes") == 0) always_answer_yes = TRUE;
353 GSM_ClearBackup(&Backup);
354 GSM_GetBackupFormatFeatures(GSM_GuessBackupFormat(argv[2], FALSE),&Info);
356 sprintf(Backup.Creator, "Gammu %s", GAMMU_VERSION);
357 if (strlen(GetOS()) != 0) {
358 strcat(Backup.Creator+strlen(Backup.Creator),", ");
359 strcat(Backup.Creator+strlen(Backup.Creator),GetOS());
361 if (strlen(GetCompiler()) != 0) {
362 strcat(Backup.Creator+strlen(Backup.Creator),", ");
363 strcat(Backup.Creator+strlen(Backup.Creator),GetCompiler());
366 signal(SIGINT, interrupt);
367 fprintf(stderr, "%s\n", _("Press Ctrl+C to break..."));
369 GSM_Init(TRUE);
371 if (Info.UseUnicode) {
372 Info.UseUnicode=answer_yes("%s", _("Use Unicode subformat of backup file?"));
374 if (Info.DateTime) {
375 GSM_GetCurrentDateTime (&Backup.DateTime);
376 Backup.DateTimeAvailable=TRUE;
378 if (Info.Model) {
379 error=GSM_GetManufacturer(gsm, Backup.Model);
380 Print_Error(error);
381 strcat(Backup.Model," ");
382 error=GSM_GetModel(gsm, buffer);
383 strcat(Backup.Model, buffer);
384 if (GSM_GetModelInfo(gsm)->model[0]!=0) {
385 strcat(Backup.Model," (");
386 strcat(Backup.Model,GSM_GetModelInfo(gsm)->model);
387 strcat(Backup.Model,")");
389 strcat(Backup.Model," ");
390 error=GSM_GetFirmware(gsm, buffer, NULL, NULL);
391 strcat(Backup.Model,buffer);
393 if (Info.IMEI) {
394 error=GSM_GetIMEI(gsm, Backup.IMEI);
395 if (error != ERR_NOTSUPPORTED) {
396 Print_Error(error);
397 } else {
398 Backup.IMEI[0] = 0;
401 printf("\n");
403 if (Info.PhonePhonebook) {
404 printf("%s\n", _("Checking phone phonebook"));
405 ReadPhonebook(Backup.PhonePhonebook, MEM_ME, _("Backup phone phonebook?"), GSM_BACKUP_MAX_PHONEPHONEBOOK, NULL, TRUE);
408 if (Info.SIMPhonebook) {
409 printf("%s\n", _("Checking SIM phonebook"));
410 ReadPhonebook(Backup.SIMPhonebook, MEM_SM, _("Backup SIM phonebook?"), GSM_BACKUP_MAX_SIMPHONEBOOK, NULL, TRUE);
413 DoBackupPart = FALSE;
414 if (Info.Calendar) {
415 printf("%s\n", _("Checking phone calendar"));
416 Calendar.Location = 0;
417 error=GSM_GetNextCalendar(gsm,&Calendar,TRUE);
418 if (error==ERR_NONE) {
419 if (answer_yes(" %s", _("Backup phone calendar notes?"))) DoBackupPart = TRUE;
422 if (DoBackupPart) {
423 used = 0;
424 fprintf(stderr, LISTFORMAT, _("Reading"));
425 while (error == ERR_NONE) {
426 if (used < GSM_MAXCALENDARTODONOTES) {
427 Backup.Calendar[used] = malloc(sizeof(GSM_CalendarEntry));
428 if (Backup.Calendar[used] == NULL) Print_Error(ERR_MOREMEMORY);
429 Backup.Calendar[used+1] = NULL;
430 } else {
431 printf("\n ");
432 printf(_("Only part of data saved, please increase %s.") , "GSM_MAXCALENDARTODONOTES");
433 printf("\n");
434 break;
436 *Backup.Calendar[used]=Calendar;
437 used ++;
438 error=GSM_GetNextCalendar(gsm,&Calendar,FALSE);
439 fprintf(stderr, "*");
440 if (gshutdown) {
441 GSM_Terminate();
442 Terminate(4);
445 fprintf(stderr, "\n");
446 fflush(stderr);
448 DoBackupPart = FALSE;
449 if (Info.ToDo) {
450 printf("%s\n", _("Checking phone todos"));
451 error=GSM_GetToDoStatus(gsm,&ToDoStatus);
452 if (error == ERR_NONE && ToDoStatus.Used != 0) {
453 if (answer_yes(" %s", _("Backup phone todos?"))) DoBackupPart = TRUE;
456 if (DoBackupPart) {
457 used = 0;
458 ToDo.Location = 0;
459 error=GSM_GetNextToDo(gsm,&ToDo,TRUE);
460 while (error == ERR_NONE) {
461 if (used < GSM_MAXCALENDARTODONOTES) {
462 Backup.ToDo[used] = malloc(sizeof(GSM_ToDoEntry));
463 if (Backup.ToDo[used] == NULL) Print_Error(ERR_MOREMEMORY);
464 Backup.ToDo[used+1] = NULL;
465 } else {
466 printf("\n ");
467 printf(_("Only part of data saved, please increase %s.") , "GSM_MAXCALENDARTODONOTES");
468 printf("\n");
469 break;
471 *Backup.ToDo[used]=ToDo;
472 used ++;
473 error=GSM_GetNextToDo(gsm,&ToDo,FALSE);
474 fprintf(stderr, "\r ");
475 fprintf(stderr, "%s ", _("Reading:"));
476 fprintf(stderr, _("%i percent"),
477 used * 100 / ToDoStatus.Used);
478 if (gshutdown) {
479 GSM_Terminate();
480 Terminate(4);
483 fprintf(stderr, "\n");
485 DoBackupPart = FALSE;
486 if (Info.Note) {
487 printf("%s\n", _("Checking phone notes"));
488 Note.Location = 0;
489 error=GSM_GetNextNote(gsm,&Note,TRUE);
490 if (error==ERR_NONE) {
491 if (answer_yes(" %s", _("Backup phone notes?"))) DoBackupPart = TRUE;
494 if (DoBackupPart) {
495 used = 0;
496 fprintf(stderr, LISTFORMAT, _("Reading"));
497 while (error == ERR_NONE) {
498 if (used < GSM_BACKUP_MAX_NOTE) {
499 Backup.Note[used] = malloc(sizeof(GSM_NoteEntry));
500 if (Backup.Note[used] == NULL) Print_Error(ERR_MOREMEMORY);
501 Backup.Note[used+1] = NULL;
502 } else {
503 printf("\n ");
504 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_NOTE");
505 printf("\n");
506 break;
508 *Backup.Note[used]=Note;
509 used ++;
510 error=GSM_GetNextNote(gsm,&Note,FALSE);
511 fprintf(stderr, "*");
512 if (gshutdown) {
513 GSM_Terminate();
514 Terminate(4);
517 fprintf(stderr, "\n");
518 fflush(stderr);
520 DoBackupPart = FALSE;
521 if (Info.CallerLogos) {
522 printf("%s\n", _("Checking phone caller logos"));
523 Bitmap.Type = GSM_CallerGroupLogo;
524 Bitmap.Location = 1;
525 error=GSM_GetBitmap(gsm,&Bitmap);
526 if (error == ERR_NONE) {
527 if (answer_yes(" %s", _("Backup phone caller groups and logos?"))) DoBackupPart = TRUE;
530 if (DoBackupPart) {
531 fprintf(stderr, LISTFORMAT, _("Reading"));
532 error = ERR_NONE;
533 used = 0;
534 while (error == ERR_NONE) {
535 if (used < GSM_BACKUP_MAX_CALLER) {
536 Backup.CallerLogos[used] = malloc(sizeof(GSM_Bitmap));
537 if (Backup.CallerLogos[used] == NULL) Print_Error(ERR_MOREMEMORY);
538 Backup.CallerLogos[used+1] = NULL;
539 } else {
540 printf("\n ");
541 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_CALLER");
542 printf("\n");
543 break;
545 *Backup.CallerLogos[used] = Bitmap;
546 used ++;
547 Bitmap.Location = used + 1;
548 error=GSM_GetBitmap(gsm,&Bitmap);
549 fprintf(stderr, "*");
550 if (gshutdown) {
551 GSM_Terminate();
552 Terminate(4);
555 fprintf(stderr, "\n");
556 fflush(stderr);
558 DoBackupPart = FALSE;
559 if (Info.SMSC) {
560 printf("%s\n", _("Checking SIM SMS profiles"));
561 if (answer_yes(" %s", _("Backup SIM SMS profiles?"))) DoBackupPart = TRUE;
563 if (DoBackupPart) {
564 used = 0;
565 fprintf(stderr, LISTFORMAT, _("Reading"));
566 while (TRUE) {
567 SMSC.Location = used + 1;
568 error = GSM_GetSMSC(gsm,&SMSC);
569 if (error != ERR_NONE) break;
570 if (used < GSM_BACKUP_MAX_SMSC) {
571 Backup.SMSC[used] = malloc(sizeof(GSM_SMSC));
572 if (Backup.SMSC[used] == NULL) Print_Error(ERR_MOREMEMORY);
573 Backup.SMSC[used + 1] = NULL;
574 } else {
575 printf("\n ");
576 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_SMSC");
577 printf("\n");
578 break;
580 *Backup.SMSC[used]=SMSC;
581 used++;
582 fprintf(stderr, "*");
584 fprintf(stderr, "\n");
585 fflush(stderr);
587 DoBackupPart = FALSE;
588 if (Info.StartupLogo) {
589 printf("%s\n", _("Checking phone startup text"));
590 Bitmap.Type = GSM_WelcomeNote_Text;
591 error = GSM_GetBitmap(gsm,&Bitmap);
592 if (error == ERR_NONE) {
593 if (answer_yes(" %s", _("Backup phone startup logo/text?"))) DoBackupPart = TRUE;
596 if (DoBackupPart) {
597 Backup.StartupLogo = malloc(sizeof(GSM_Bitmap));
598 if (Backup.StartupLogo == NULL) Print_Error(ERR_MOREMEMORY);
599 *Backup.StartupLogo = Bitmap;
600 if (Bitmap.Text[0]==0 && Bitmap.Text[1]==0) {
601 Bitmap.Type = GSM_StartupLogo;
602 error = GSM_GetBitmap(gsm,&Bitmap);
603 if (error == ERR_NONE) *Backup.StartupLogo = Bitmap;
606 DoBackupPart = FALSE;
607 if (Info.OperatorLogo) {
608 printf("%s\n", _("Checking phone operator logo"));
609 Bitmap.Type = GSM_OperatorLogo;
610 error=GSM_GetBitmap(gsm,&Bitmap);
611 if (error == ERR_NONE) {
612 if (strcmp(Bitmap.NetworkCode,"000 00")!=0) {
613 if (answer_yes(" %s", _("Backup phone operator logo?"))) DoBackupPart = TRUE;
617 if (DoBackupPart) {
618 Backup.OperatorLogo = malloc(sizeof(GSM_Bitmap));
619 if (Backup.OperatorLogo == NULL) Print_Error(ERR_MOREMEMORY);
620 *Backup.OperatorLogo = Bitmap;
622 DoBackupPart = FALSE;
623 if (Info.WAPBookmark) {
624 printf("%s\n", _("Checking phone WAP bookmarks"));
625 Bookmark.Location = 1;
626 error=GSM_GetWAPBookmark(gsm,&Bookmark);
627 if (error==ERR_NONE) {
628 if (answer_yes(" %s", _("Backup phone WAP bookmarks?"))) DoBackupPart = TRUE;
631 if (DoBackupPart) {
632 used = 0;
633 fprintf(stderr, LISTFORMAT, _("Reading"));
634 error = ERR_NONE;
635 while (error == ERR_NONE) {
636 if (used < GSM_BACKUP_MAX_WAPBOOKMARK) {
637 Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark));
638 if (Backup.WAPBookmark[used] == NULL) Print_Error(ERR_MOREMEMORY);
639 Backup.WAPBookmark[used+1] = NULL;
640 } else {
641 printf("\n ");
642 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_WAPBOOKMARK");
643 printf("\n");
644 break;
646 *Backup.WAPBookmark[used]=Bookmark;
647 used ++;
648 Bookmark.Location = used+1;
649 error=GSM_GetWAPBookmark(gsm,&Bookmark);
650 fprintf(stderr, "*");
651 if (gshutdown) {
652 GSM_Terminate();
653 Terminate(4);
656 fprintf(stderr, "\n");
657 fflush(stderr);
659 DoBackupPart = FALSE;
660 if (Info.WAPSettings) {
661 printf("%s\n", _("Checking phone WAP settings"));
662 Settings.Location = 1;
663 error=GSM_GetWAPSettings(gsm,&Settings);
664 if (error==ERR_NONE) {
665 if (answer_yes(" %s", _("Backup phone WAP settings?"))) DoBackupPart = TRUE;
668 if (DoBackupPart) {
669 used = 0;
670 fprintf(stderr, LISTFORMAT, _("Reading"));
671 error = ERR_NONE;
672 while (error == ERR_NONE) {
673 if (used < GSM_BACKUP_MAX_WAPSETTINGS) {
674 Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings));
675 if (Backup.WAPSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
676 Backup.WAPSettings[used+1] = NULL;
677 } else {
678 printf("\n ");
679 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_WAPSETTINGS");
680 printf("\n");
681 break;
683 *Backup.WAPSettings[used]=Settings;
684 used ++;
685 Settings.Location = used+1;
686 error=GSM_GetWAPSettings(gsm,&Settings);
687 fprintf(stderr, "*");
688 if (gshutdown) {
689 GSM_Terminate();
690 Terminate(4);
693 fprintf(stderr, "\n");
694 fflush(stderr);
696 DoBackupPart = FALSE;
697 if (Info.MMSSettings) {
698 printf("%s\n", _("Checking phone MMS settings"));
699 Settings.Location = 1;
700 error=GSM_GetMMSSettings(gsm,&Settings);
701 if (error==ERR_NONE) {
702 if (answer_yes(" %s", _("Backup phone MMS settings?"))) DoBackupPart = TRUE;
705 if (DoBackupPart) {
706 used = 0;
707 fprintf(stderr, LISTFORMAT, _("Reading"));
708 error = ERR_NONE;
709 while (error == ERR_NONE) {
710 if (used < GSM_BACKUP_MAX_MMSSETTINGS) {
711 Backup.MMSSettings[used] = malloc(sizeof(GSM_MultiWAPSettings));
712 if (Backup.MMSSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
713 Backup.MMSSettings[used+1] = NULL;
714 } else {
715 printf("\n ");
716 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_MMSSETTINGS");
717 printf("\n");
718 break;
720 *Backup.MMSSettings[used]=Settings;
721 used ++;
722 Settings.Location = used+1;
723 error=GSM_GetMMSSettings(gsm,&Settings);
724 fprintf(stderr, "*");
725 if (gshutdown) {
726 GSM_Terminate();
727 Terminate(4);
730 fprintf(stderr, "\n");
731 fflush(stderr);
733 DoBackupPart = FALSE;
734 if (Info.ChatSettings) {
735 printf("%s\n", _("Checking phone Chat settings"));
736 Chat.Location = 1;
737 error=GSM_GetChatSettings(gsm,&Chat);
738 if (error==ERR_NONE) {
739 if (answer_yes(" %s", _("Backup phone Chat settings?"))) DoBackupPart = TRUE;
742 if (DoBackupPart) {
743 used = 0;
744 fprintf(stderr, LISTFORMAT, _("Reading"));
745 error = ERR_NONE;
746 while (error == ERR_NONE) {
747 if (used < GSM_BACKUP_MAX_CHATSETTINGS) {
748 Backup.ChatSettings[used] = malloc(sizeof(GSM_ChatSettings));
749 if (Backup.ChatSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
750 Backup.ChatSettings[used+1] = NULL;
751 } else {
752 printf("\n ");
753 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_CHATSETTINGS");
754 printf("\n");
755 break;
757 *Backup.ChatSettings[used]=Chat;
758 used ++;
759 Chat.Location = used+1;
760 error=GSM_GetChatSettings(gsm,&Chat);
761 fprintf(stderr, "*");
762 if (gshutdown) {
763 GSM_Terminate();
764 Terminate(4);
767 fprintf(stderr, "\n");
768 fflush(stderr);
770 DoBackupPart = FALSE;
771 if (Info.SyncMLSettings) {
772 printf("%s\n", _("Checking phone SyncML settings"));
773 SyncML.Location = 1;
774 error=GSM_GetSyncMLSettings(gsm,&SyncML);
775 if (error==ERR_NONE) {
776 if (answer_yes(" %s", _("Backup phone SyncML settings?"))) DoBackupPart = TRUE;
779 if (DoBackupPart) {
780 used = 0;
781 fprintf(stderr, LISTFORMAT, _("Reading"));
782 while (error == ERR_NONE) {
783 if (used < GSM_BACKUP_MAX_SYNCMLSETTINGS) {
784 Backup.SyncMLSettings[used] = malloc(sizeof(GSM_SyncMLSettings));
785 if (Backup.SyncMLSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
786 Backup.SyncMLSettings[used+1] = NULL;
787 } else {
788 printf("\n ");
789 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_SYNCMLSETTINGS");
790 printf("\n");
791 break;
793 *Backup.SyncMLSettings[used]=SyncML;
794 used ++;
795 SyncML.Location = used+1;
796 error=GSM_GetSyncMLSettings(gsm,&SyncML);
797 fprintf(stderr, "*");
798 if (gshutdown) {
799 GSM_Terminate();
800 Terminate(4);
803 fprintf(stderr, "\n");
804 fflush(stderr);
806 DoBackupPart = FALSE;
807 if (Info.Ringtone) {
808 printf("%s\n", _("Checking phone user ringtones"));
809 Ringtone.Location = 1;
810 Ringtone.Format = 0;
811 error=GSM_GetRingtone(gsm,&Ringtone,FALSE);
812 if (error==ERR_EMPTY || error == ERR_NONE) {
813 if (answer_yes(" %s", _("Backup phone user ringtones?"))) DoBackupPart = TRUE;
816 if (DoBackupPart) {
817 used = 0;
818 i = 1;
819 fprintf(stderr, LISTFORMAT, _("Reading"));
820 error = ERR_NONE;
821 while (error == ERR_NONE || error == ERR_EMPTY) {
822 if (error == ERR_NONE) {
823 if (used < GSM_BACKUP_MAX_RINGTONES) {
824 Backup.Ringtone[used] = malloc(sizeof(GSM_Ringtone));
825 if (Backup.Ringtone[used] == NULL) Print_Error(ERR_MOREMEMORY);
826 Backup.Ringtone[used+1] = NULL;
827 } else {
828 printf("\n ");
829 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_RINGTONES");
830 printf("\n");
831 break;
833 *Backup.Ringtone[used]=Ringtone;
834 used ++;
836 i++;
837 Ringtone.Location = i;
838 Ringtone.Format = 0;
839 error=GSM_GetRingtone(gsm,&Ringtone,FALSE);
840 fprintf(stderr, "*");
841 if (gshutdown) {
842 GSM_Terminate();
843 Terminate(4);
846 fprintf(stderr, "\n");
847 fflush(stderr);
849 DoBackupPart = FALSE;
850 if (Info.Profiles) {
851 printf("%s\n", _("Checking phone profiles"));
852 Profile.Location = 1;
853 error = GSM_GetProfile(gsm,&Profile);
854 if (error == ERR_NONE) {
855 if (answer_yes(" %s", _("Backup phone profiles?"))) DoBackupPart = TRUE;
858 if (DoBackupPart) {
859 used = 0;
860 fprintf(stderr, LISTFORMAT, _("Reading"));
861 while (TRUE) {
862 Profile.Location = used + 1;
863 error = GSM_GetProfile(gsm,&Profile);
864 if (error != ERR_NONE) break;
865 if (used < GSM_BACKUP_MAX_PROFILES) {
866 Backup.Profiles[used] = malloc(sizeof(GSM_Profile));
867 if (Backup.Profiles[used] == NULL) Print_Error(ERR_MOREMEMORY);
868 Backup.Profiles[used + 1] = NULL;
869 } else {
870 printf("\n ");
871 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_PROFILES");
872 printf("\n");
873 break;
875 *Backup.Profiles[used]=Profile;
876 used++;
877 fprintf(stderr, "*");
879 fprintf(stderr, "\n");
880 fflush(stderr);
882 DoBackupPart = FALSE;
883 if (Info.FMStation) {
884 printf("%s\n", _("Checking phone FM radio stations"));
885 FMStation.Location = 1;
886 error = GSM_GetFMStation(gsm,&FMStation);
887 if (error == ERR_NONE || error == ERR_EMPTY) {
888 if (answer_yes(" %s", _("Backup phone FM radio stations?"))) DoBackupPart=TRUE;
891 if (DoBackupPart) {
892 used = 0;
893 i = 1;
894 fprintf(stderr, LISTFORMAT, _("Reading"));
895 error = ERR_NONE;
896 while (error == ERR_NONE || error == ERR_EMPTY) {
897 error = GSM_GetFMStation(gsm,&FMStation);
898 if (error == ERR_NONE) {
899 if (used < GSM_BACKUP_MAX_FMSTATIONS) {
900 Backup.FMStation[used] = malloc(sizeof(GSM_FMStation));
901 if (Backup.FMStation[used] == NULL) Print_Error(ERR_MOREMEMORY);
902 Backup.FMStation[used + 1] = NULL;
903 } else {
904 printf("\n ");
905 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_FMSTATIONS");
906 printf("\n");
907 break;
909 *Backup.FMStation[used]=FMStation;
910 used++;
912 i++;
913 FMStation.Location = i;
914 fprintf(stderr, "*");
916 fprintf(stderr, "\n");
917 fflush(stderr);
919 DoBackupPart = FALSE;
920 if (Info.GPRSPoint) {
921 printf("%s\n", _("Checking phone GPRS access points"));
922 GPRSPoint.Location = 1;
923 error = GSM_GetGPRSAccessPoint(gsm,&GPRSPoint);
924 if (error == ERR_NONE || error == ERR_EMPTY) {
925 if (answer_yes(" %s", _("Backup phone GPRS access points?"))) DoBackupPart = TRUE;
928 if (DoBackupPart) {
929 used = 0;
930 i = 1;
931 fprintf(stderr, LISTFORMAT, _("Reading"));
932 error = ERR_NONE;
933 while (error == ERR_NONE || error == ERR_EMPTY) {
934 error = GSM_GetGPRSAccessPoint(gsm,&GPRSPoint);
935 if (error == ERR_NONE) {
936 if (used < GSM_BACKUP_MAX_GPRSPOINT) {
937 Backup.GPRSPoint[used] = malloc(sizeof(GSM_GPRSAccessPoint));
938 if (Backup.GPRSPoint[used] == NULL) Print_Error(ERR_MOREMEMORY);
939 Backup.GPRSPoint[used + 1] = NULL;
940 } else {
941 printf("\n ");
942 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_GPRSPOINT");
943 printf("\n");
944 break;
946 *Backup.GPRSPoint[used]=GPRSPoint;
947 used++;
949 i++;
950 GPRSPoint.Location = i;
951 fprintf(stderr, "*");
953 fprintf(stderr, "\n");
954 fflush(stderr);
957 GSM_Terminate();
959 GSM_SaveBackupFile(argv[2], &Backup, GSM_GuessBackupFormat(argv[2], Info.UseUnicode));
960 GSM_FreeBackup(&Backup);
963 gboolean ReadBackup(const char *filename, GSM_Backup *Backup)
965 GSM_Error error;
967 error = GSM_ReadBackupFile(filename, Backup, GSM_GuessBackupFormat(filename, FALSE));
968 Print_Error(error);
970 if (Backup->DateTimeAvailable) {
971 fprintf(stderr, LISTFORMAT "%s\n", _("Time of backup"), OSDateTime(Backup->DateTime, FALSE));
973 if (Backup->Model[0] != 0) {
974 fprintf(stderr, LISTFORMAT "%s\n", _("Phone"), Backup->Model);
976 if (Backup->IMEI[0] != 0) {
977 fprintf(stderr, LISTFORMAT "%s\n", _("IMEI"), Backup->IMEI);
979 if (Backup->Creator[0] != 0) {
980 fprintf(stderr, LISTFORMAT "%s\n", _("File created by"), Backup->Creator);
983 if (Backup->MD5Calculated[0] != 0 && strcasecmp(Backup->MD5Original, Backup->MD5Calculated) != 0) {
984 if (!answer_yes(_("Checksum in backup file do not match (original: %s, new: %s). Continue?"), Backup->MD5Original, Backup->MD5Calculated)) {
985 return FALSE;
989 return TRUE;
992 void Restore(int argc, char *argv[])
994 GSM_Error error;
995 GSM_Backup Backup;
996 GSM_FMStation FMStation;
997 GSM_DateTime date_time;
998 GSM_CalendarEntry Calendar;
999 GSM_Bitmap Bitmap;
1000 GSM_Ringtone Ringtone;
1001 GSM_MemoryEntry Pbk;
1002 GSM_MemoryStatus MemStatus;
1003 GSM_ToDoEntry ToDo;
1004 GSM_ToDoStatus ToDoStatus;
1005 GSM_NoteEntry Note;
1006 GSM_Profile Profile;
1007 GSM_MultiWAPSettings Settings;
1008 GSM_GPRSAccessPoint GPRSPoint;
1009 GSM_WAPBookmark Bookmark;
1010 int i, j, used, max = 0;
1011 gboolean Past = TRUE, First;
1012 gboolean Found, DoRestore;
1014 if (argc == 4 && strcasecmp(argv[3],"-yes") == 0) always_answer_yes = TRUE;
1016 if (!ReadBackup(argv[2], &Backup)) {
1017 return;
1020 GSM_Init(TRUE);
1022 printf("%s\n", _("Please note that restoring data will cause existing data in phone to be deleted."));
1023 printf("%s\n", _("Use addnew command if you just want to add some entries to your phone."));
1025 signal(SIGINT, interrupt);
1026 fprintf(stderr, "%s\n", _("Press Ctrl+C to break..."));
1028 DoRestore = FALSE;
1029 if (Backup.CallerLogos[0] != NULL) {
1030 Bitmap.Type = GSM_CallerGroupLogo;
1031 Bitmap.Location = 1;
1032 error=GSM_GetBitmap(gsm,&Bitmap);
1033 if (error == ERR_NONE) {
1034 if (answer_yes("%s", _("Restore phone caller groups and logos?"))) DoRestore = TRUE;
1037 if (DoRestore) {
1038 max = 0;
1039 while (Backup.CallerLogos[max]!=NULL) max++;
1040 for (i=0;i<max;i++) {
1041 error=GSM_SetBitmap(gsm,Backup.CallerLogos[i]);
1042 Print_Error(error);
1043 fprintf(stderr, "\r");
1044 fprintf(stderr, "%s ", _("Writing:"));
1045 fprintf(stderr, _("%i percent"),
1046 (i + 1) * 100 / max);
1047 if (gshutdown) {
1048 GSM_Terminate();
1049 Terminate(4);
1052 fprintf(stderr, "\n");
1055 DoRestore = FALSE;
1056 if (Backup.PhonePhonebook[0] != NULL) {
1057 max = 0;
1058 while (Backup.PhonePhonebook[max]!=NULL) max++;
1059 MemStatus.MemoryType = MEM_ME;
1060 error=GSM_GetMemoryStatus(gsm, &MemStatus);
1061 /* Some phones do not support status, try reading some entry */
1062 if (error != ERR_NONE) {
1063 Pbk.Location = 1;
1064 Pbk.MemoryType = MEM_ME;
1065 error = GSM_GetMemory(gsm, &Pbk);
1066 MemStatus.MemoryUsed = max;
1067 MemStatus.MemoryFree = max;
1069 if (error == ERR_NONE || error == ERR_EMPTY) {
1070 fprintf(stderr, _("%i entries in backup file\n"),max);
1071 if (answer_yes("%s", _("Restore phone phonebook?"))) DoRestore = TRUE;
1074 if (DoRestore) {
1075 used = 0;
1076 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
1077 Pbk.MemoryType = MEM_ME;
1078 Pbk.Location = i + 1;
1079 Pbk.EntriesNum = 0;
1080 if (used<max && Backup.PhonePhonebook[used]->Location == Pbk.Location) {
1081 Pbk = *Backup.PhonePhonebook[used];
1082 used++;
1083 if (Pbk.EntriesNum != 0) error=GSM_SetMemory(gsm, &Pbk);
1084 if (error == ERR_PERMISSION && GSM_IsPhoneFeatureAvailable(GSM_GetModelInfo(gsm), F_6230iCALLER)) {
1085 error=GSM_DeleteMemory(gsm, &Pbk);
1086 Print_Error(error);
1087 error=GSM_SetMemory(gsm, &Pbk);
1089 if (error == ERR_MEMORY && GSM_IsPhoneFeatureAvailable(GSM_GetModelInfo(gsm), F_6230iCALLER)) {
1090 printf_err("%s\n", _("Probably caller group is missing from your backup, add it and use --restore again."));
1091 GSM_Terminate();
1092 Terminate(2);
1094 if (Pbk.EntriesNum != 0 && error==ERR_NONE) {
1095 First = TRUE;
1096 for (j=0;j<Pbk.EntriesNum;j++) {
1097 if (Pbk.Entries[j].AddError == ERR_NONE) continue;
1098 if (First) {
1099 printf("\r");
1100 printf(_("Location %d"), Pbk.Location);
1101 printf("%20s\n ", " ");
1102 First = FALSE;
1104 PrintMemorySubEntry(&Pbk.Entries[j], gsm);
1105 printf(" %s\n", GSM_ErrorString(Pbk.Entries[j].AddError));
1109 if (Pbk.EntriesNum == 0) {
1110 /* Delete only when there was some content in phone */
1111 if (MemStatus.MemoryUsed > 0) {
1112 error = GSM_DeleteMemory(gsm, &Pbk);
1113 if (error != ERR_EMPTY && error != ERR_NONE) {
1114 Print_Error(error);
1118 fprintf(stderr, "\r");
1119 fprintf(stderr, "%s ", _("Writing:"));
1120 fprintf(stderr, _("%i percent"),
1121 (i + 1) * 100 / (MemStatus.MemoryUsed + MemStatus.MemoryFree)
1123 if (gshutdown) {
1124 GSM_Terminate();
1125 Terminate(4);
1128 fprintf(stderr, "\n");
1131 DoRestore = FALSE;
1132 if (Backup.SIMPhonebook[0] != NULL) {
1133 MemStatus.MemoryType = MEM_SM;
1134 error=GSM_GetMemoryStatus(gsm, &MemStatus);
1135 if (error==ERR_NONE) {
1136 max = 0;
1137 while (Backup.SIMPhonebook[max]!=NULL) max++;
1138 fprintf(stderr, _("%i entries in backup file\n"),max);
1139 if (answer_yes("%s", _("Restore SIM phonebook?"))) DoRestore = TRUE;
1142 if (DoRestore) {
1143 used = 0;
1144 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
1145 Pbk.MemoryType = MEM_SM;
1146 Pbk.Location = i + 1;
1147 Pbk.EntriesNum = 0;
1148 if (used<max && Backup.SIMPhonebook[used]->Location == Pbk.Location) {
1149 Pbk = *Backup.SIMPhonebook[used];
1150 used++;
1151 if (Pbk.EntriesNum != 0) {
1152 error=GSM_SetMemory(gsm, &Pbk);
1153 if (error==ERR_NONE) {
1154 First = TRUE;
1155 for (j=0;j<Pbk.EntriesNum;j++) {
1156 if (Pbk.Entries[j].AddError == ERR_NONE) continue;
1157 if (First) {
1158 printf("\r");
1159 printf(_("Location %d"), Pbk.Location);
1160 printf("%20s\n ", " ");
1161 First = FALSE;
1163 PrintMemorySubEntry(&Pbk.Entries[j], gsm);
1164 printf(" %s\n",GSM_ErrorString(Pbk.Entries[j].AddError));
1169 if (Pbk.EntriesNum == 0) error=GSM_DeleteMemory(gsm, &Pbk);
1170 Print_Error(error);
1171 fprintf(stderr, "\r");
1172 fprintf(stderr, "%s ", _("Writing:"));
1173 fprintf(stderr, _("%i percent"),
1174 (i + 1) * 100 / (MemStatus.MemoryUsed + MemStatus.MemoryFree));
1175 if (gshutdown) {
1176 GSM_Terminate();
1177 Terminate(4);
1180 fprintf(stderr, "\n");
1183 if (GSM_GetConfig(gsm, -1)->SyncTime == FALSE) {
1184 if (answer_yes("%s", _("Do you want to set phone date/time? (NOTE: in some phones it's required to correctly restore calendar notes and other items)"))) {
1185 GSM_GetCurrentDateTime(&date_time);
1187 error=GSM_SetDateTime(gsm, &date_time);
1188 Print_Error(error);
1191 DoRestore = FALSE;
1192 if (Backup.Calendar[0] != NULL) {
1193 Calendar.Location = 0;
1194 /* N6110 doesn't support getting calendar status */
1195 error = GSM_GetNextCalendar(gsm,&Calendar,TRUE);
1196 if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) {
1197 max = 0;
1198 while (Backup.Calendar[max] != NULL) max++;
1199 fprintf(stderr, _("%i entries in backup file\n"),max);
1200 if (answer_yes("%s", _("Restore phone calendar notes?"))) {
1201 Past = answer_yes(" %s", _("Restore notes from the past?"));
1202 DoRestore = TRUE;
1206 if (DoRestore) {
1207 fprintf(stderr, "%s ", _("Deleting old notes:"));
1208 error = GSM_DeleteAllCalendar(gsm);
1209 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1210 while (1) {
1211 error = GSM_GetNextCalendar(gsm,&Calendar,TRUE);
1212 if (error != ERR_NONE) break;
1213 error = GSM_DeleteCalendar(gsm,&Calendar);
1214 Print_Error(error);
1215 fprintf(stderr, "*");
1217 fprintf(stderr, "\n");
1218 } else {
1219 fprintf(stderr, "%s\n", _("Done"));
1220 Print_Error(error);
1223 for (i=0;i<max;i++) {
1224 if (!Past && GSM_IsCalendarNoteFromThePast(Backup.Calendar[i])) continue;
1226 Calendar = *Backup.Calendar[i];
1227 error=GSM_AddCalendar(gsm,&Calendar);
1228 Print_Error(error);
1229 fprintf(stderr, "\r");
1230 fprintf(stderr, "%s ", _("Writing:"));
1231 fprintf(stderr, _("%i percent"),
1232 (i + 1) * 100 / max);
1233 if (gshutdown) {
1234 GSM_Terminate();
1235 Terminate(4);
1238 fprintf(stderr, "\n");
1241 DoRestore = FALSE;
1242 if (Backup.ToDo[0] != NULL) {
1243 error = GSM_GetToDoStatus(gsm,&ToDoStatus);
1244 if (error == ERR_NONE) {
1245 max = 0;
1246 while (Backup.ToDo[max]!=NULL) max++;
1247 fprintf(stderr, _("%i entries in backup file\n"),max);
1249 if (answer_yes("%s", _("Restore phone todo?"))) DoRestore = TRUE;
1252 if (DoRestore) {
1253 ToDo = *Backup.ToDo[0];
1254 error = GSM_SetToDo(gsm,&ToDo);
1256 if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) {
1257 fprintf(stderr, "%s ", _("Deleting old todos:"));
1258 error=GSM_DeleteAllToDo(gsm);
1259 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1260 while (1) {
1261 error = GSM_GetNextToDo(gsm,&ToDo,TRUE);
1262 if (error != ERR_NONE) break;
1263 error = GSM_DeleteToDo(gsm,&ToDo);
1264 Print_Error(error);
1265 fprintf(stderr, "*");
1267 fprintf(stderr, "\n");
1268 } else {
1269 fprintf(stderr, "%s\n", _("Done"));
1270 Print_Error(error);
1273 for (i=0;i<max;i++) {
1274 ToDo = *Backup.ToDo[i];
1275 ToDo.Location = 0;
1276 error=GSM_AddToDo(gsm,&ToDo);
1277 Print_Error(error);
1278 fprintf(stderr, "\r");
1279 fprintf(stderr, "%s ", _("Writing:"));
1280 fprintf(stderr, _("%i percent"),
1281 (i + 1) * 100 / max);
1282 if (gshutdown) {
1283 GSM_Terminate();
1284 Terminate(4);
1287 fprintf(stderr, "\n");
1288 } else if (DoRestore) {
1289 /* At first delete entries, that were deleted */
1290 used = 0;
1291 error = GSM_GetNextToDo(gsm,&ToDo,TRUE);
1292 while (error == ERR_NONE) {
1293 used++;
1294 Found = FALSE;
1295 for (i=0;i<max;i++) {
1296 if (Backup.ToDo[i]->Location == ToDo.Location) {
1297 Found = TRUE;
1298 break;
1301 if (!Found) {
1302 error=GSM_DeleteToDo(gsm,&ToDo);
1303 Print_Error(error);
1305 error = GSM_GetNextToDo(gsm,&ToDo,FALSE);
1306 fprintf(stderr, "\r");
1307 fprintf(stderr, "%s ", _("Writing:"));
1308 fprintf(stderr, _("%i percent"),
1309 used * 100 / ToDoStatus.Used);
1310 if (gshutdown) {
1311 GSM_Terminate();
1312 Terminate(4);
1315 fprintf(stderr, "\n");
1317 /* Now write modified/new entries */
1318 for (i=0;i<max;i++) {
1319 ToDo = *Backup.ToDo[i];
1320 error = GSM_SetToDo(gsm,&ToDo);
1321 Print_Error(error);
1322 fprintf(stderr, "\r");
1323 fprintf(stderr, "%s ", _("Writing:"));
1324 fprintf(stderr, _("%i percent"),
1325 (i + 1) * 100 / max);
1326 if (gshutdown) {
1327 GSM_Terminate();
1328 Terminate(4);
1331 fprintf(stderr, "\n");
1334 DoRestore = FALSE;
1335 if (Backup.Note[0] != NULL) {
1336 error = GSM_GetNotesStatus(gsm,&ToDoStatus);
1337 if (error == ERR_NONE) {
1338 max = 0;
1339 while (Backup.Note[max]!=NULL) max++;
1340 fprintf(stderr, _("%i entries in backup file\n"),max);
1342 if (answer_yes("%s", _("Restore phone notes?"))) DoRestore = TRUE;
1345 if (DoRestore) {
1346 fprintf(stderr, "%s ", _("Deleting old notes:"));
1347 while (1) {
1348 error = GSM_GetNextNote(gsm,&Note,TRUE);
1349 if (error != ERR_NONE) break;
1350 error = GSM_DeleteNote(gsm,&Note);
1351 Print_Error(error);
1352 fprintf(stderr, "*");
1354 fprintf(stderr, "\n");
1356 for (i=0;i<max;i++) {
1357 Note = *Backup.Note[i];
1358 Note.Location = 0;
1359 error=GSM_AddNote(gsm,&Note);
1360 Print_Error(error);
1361 fprintf(stderr, "\r");
1362 fprintf(stderr, "%s ", _("Writing:"));
1363 fprintf(stderr, _("%i percent"),
1364 (i + 1) * 100 / max);
1365 if (gshutdown) {
1366 GSM_Terminate();
1367 Terminate(4);
1370 fprintf(stderr, "\n");
1373 if (Backup.SMSC[0] != NULL && answer_yes("%s", _("Restore SIM SMSC profiles?"))) {
1374 max = 0;
1375 while (Backup.SMSC[max]!=NULL) max++;
1376 for (i=0;i<max;i++) {
1377 error=GSM_SetSMSC(gsm,Backup.SMSC[i]);
1378 Print_Error(error);
1379 fprintf(stderr, "\r");
1380 fprintf(stderr, "%s ", _("Writing:"));
1381 fprintf(stderr, _("%i percent"),
1382 (i + 1) * 100 / max);
1383 if (gshutdown) {
1384 GSM_Terminate();
1385 Terminate(4);
1388 fprintf(stderr, "\n");
1390 if (Backup.StartupLogo != NULL && answer_yes("%s", _("Restore phone startup logo/text?"))) {
1391 error=GSM_SetBitmap(gsm,Backup.StartupLogo);
1392 Print_Error(error);
1394 if (Backup.OperatorLogo != NULL && answer_yes("%s", _("Restore phone operator logo?"))) {
1395 error=GSM_SetBitmap(gsm,Backup.OperatorLogo);
1396 Print_Error(error);
1398 DoRestore = FALSE;
1399 if (Backup.WAPBookmark[0] != NULL) {
1400 Bookmark.Location = 1;
1401 error = GSM_GetWAPBookmark(gsm,&Bookmark);
1402 if (error == ERR_NONE || error == ERR_INVALIDLOCATION) {
1403 if (answer_yes("%s", _("Restore phone WAP bookmarks?"))) DoRestore = TRUE;
1406 if (DoRestore) {
1407 fprintf(stderr, "%s ", _("Deleting old bookmarks:"));
1408 /* One thing to explain: DCT4 phones seems to have bug here.
1409 * When delete for example first bookmark, phone change
1410 * numeration for getting frame, not for deleting. So, we try to
1411 * get 1'st bookmark. Inside frame is "correct" location. We use
1412 * it later
1414 while (error==ERR_NONE) {
1415 error = GSM_DeleteWAPBookmark(gsm,&Bookmark);
1416 Bookmark.Location = 1;
1417 error = GSM_GetWAPBookmark(gsm,&Bookmark);
1418 fprintf(stderr, "*");
1420 fprintf(stderr, "\n");
1421 max = 0;
1422 while (Backup.WAPBookmark[max]!=NULL) max++;
1423 for (i=0;i<max;i++) {
1424 Bookmark = *Backup.WAPBookmark[i];
1425 Bookmark.Location = 0;
1426 error=GSM_SetWAPBookmark(gsm,&Bookmark);
1427 Print_Error(error);
1428 fprintf(stderr, "\r");
1429 fprintf(stderr, "%s ", _("Writing:"));
1430 fprintf(stderr, _("%i percent"),
1431 (i + 1) * 100 / max);
1432 if (gshutdown) {
1433 GSM_Terminate();
1434 Terminate(4);
1437 fprintf(stderr, "\n");
1439 DoRestore = FALSE;
1440 if (Backup.WAPSettings[0] != NULL) {
1441 Settings.Location = 1;
1442 error = GSM_GetWAPSettings(gsm,&Settings);
1443 if (error == ERR_NONE) {
1444 if (answer_yes("%s", _("Restore phone WAP settings?"))) DoRestore = TRUE;
1447 if (DoRestore) {
1448 max = 0;
1449 while (Backup.WAPSettings[max]!=NULL) max++;
1450 for (i=0;i<max;i++) {
1451 error=GSM_SetWAPSettings(gsm,Backup.WAPSettings[i]);
1452 Print_Error(error);
1453 fprintf(stderr, "\r");
1454 fprintf(stderr, "%s ", _("Writing:"));
1455 fprintf(stderr, _("%i percent"),
1456 (i + 1) * 100 / max);
1457 if (gshutdown) {
1458 GSM_Terminate();
1459 Terminate(4);
1462 fprintf(stderr, "\n");
1464 DoRestore = FALSE;
1465 if (Backup.MMSSettings[0] != NULL) {
1466 Settings.Location = 1;
1467 error = GSM_GetMMSSettings(gsm,&Settings);
1468 if (error == ERR_NONE) {
1469 if (answer_yes("%s", _("Restore phone MMS settings?"))) DoRestore = TRUE;
1472 if (DoRestore) {
1473 max = 0;
1474 while (Backup.MMSSettings[max]!=NULL) max++;
1475 for (i=0;i<max;i++) {
1476 error=GSM_SetMMSSettings(gsm,Backup.MMSSettings[i]);
1477 Print_Error(error);
1478 fprintf(stderr, "\r");
1479 fprintf(stderr, "%s ", _("Writing:"));
1480 fprintf(stderr, _("%i percent"),
1481 (i + 1) * 100 / max);
1482 if (gshutdown) {
1483 GSM_Terminate();
1484 Terminate(4);
1487 fprintf(stderr, "\n");
1489 DoRestore = FALSE;
1490 if (Backup.Ringtone[0] != NULL) {
1491 Ringtone.Location = 1;
1492 Ringtone.Format = 0;
1493 error = GSM_GetRingtone(gsm,&Ringtone,FALSE);
1494 if (error == ERR_NONE || error ==ERR_EMPTY) {
1495 if (answer_yes("%s", _("Delete all phone user ringtones?"))) DoRestore = TRUE;
1498 if (DoRestore) {
1499 fprintf(stderr, LISTFORMAT, _("Deleting"));
1500 error=GSM_DeleteUserRingtones(gsm);
1501 Print_Error(error);
1502 fprintf(stderr, "%s\n", _("Done"));
1503 DoRestore = FALSE;
1504 if (answer_yes("%s", _("Restore user ringtones?"))) DoRestore = TRUE;
1506 if (DoRestore) {
1507 max = 0;
1508 while (Backup.Ringtone[max]!=NULL) max++;
1509 for (i=0;i<max;i++) {
1510 error=GSM_RingtoneConvert(&Ringtone, Backup.Ringtone[i], Ringtone.Format);
1511 Print_Error(error);
1512 error=GSM_SetRingtone(gsm,&Ringtone,&i);
1513 Print_Error(error);
1514 fprintf(stderr, "\r");
1515 fprintf(stderr, "%s ", _("Writing:"));
1516 fprintf(stderr, _("%i percent"),
1517 (i + 1) * 100 / max);
1518 if (gshutdown) {
1519 GSM_Terminate();
1520 Terminate(4);
1523 fprintf(stderr, "\n");
1525 DoRestore = FALSE;
1526 if (Backup.Profiles[0] != NULL) {
1527 Profile.Location = 1;
1528 error = GSM_GetProfile(gsm,&Profile);
1529 if (error == ERR_NONE) {
1530 if (answer_yes("%s", _("Restore phone profiles?"))) DoRestore = TRUE;
1533 if (DoRestore) {
1534 Profile.Location= 0;
1535 max = 0;
1536 while (Backup.Profiles[max]!=NULL) max++;
1537 for (i=0;i<max;i++) {
1538 Profile = *Backup.Profiles[i];
1539 error=GSM_SetProfile(gsm,&Profile);
1540 Print_Error(error);
1541 if (gshutdown) {
1542 GSM_Terminate();
1543 Terminate(4);
1546 fprintf(stderr, "\n");
1548 DoRestore = FALSE;
1549 if (Backup.FMStation[0] != NULL) {
1550 FMStation.Location = 1;
1551 error = GSM_GetFMStation(gsm,&FMStation);
1552 if (error == ERR_NONE || error == ERR_EMPTY) {
1553 if (answer_yes("%s", _("Restore phone FM radio stations?"))) DoRestore = TRUE;
1556 if (DoRestore) {
1557 fprintf(stderr, "%s ", _("Deleting old FM stations:"));
1558 error=GSM_ClearFMStations(gsm);
1559 Print_Error(error);
1560 fprintf(stderr, "%s\n", _("Done"));
1561 max = 0;
1562 while (Backup.FMStation[max]!=NULL) max++;
1563 for (i=0;i<max;i++) {
1564 FMStation = *Backup.FMStation[i];
1565 error=GSM_SetFMStation(gsm,&FMStation);
1566 Print_Error(error);
1567 fprintf(stderr, "\r");
1568 fprintf(stderr, "%s ", _("Writing:"));
1569 fprintf(stderr, _("%i percent"),
1570 (i + 1) * 100 / max);
1571 if (gshutdown) {
1572 GSM_Terminate();
1573 Terminate(4);
1576 fprintf(stderr, "\n");
1578 DoRestore = FALSE;
1579 if (Backup.GPRSPoint[0] != NULL) {
1580 GPRSPoint.Location = 1;
1581 error = GSM_GetGPRSAccessPoint(gsm,&GPRSPoint);
1582 if (error == ERR_NONE || error == ERR_EMPTY) {
1583 if (answer_yes("%s", _("Restore phone GPRS Points?"))) DoRestore = TRUE;
1586 if (DoRestore) {
1587 max = 0;
1588 while (Backup.GPRSPoint[max]!=NULL) max++;
1589 for (i=0;i<max;i++) {
1590 error=GSM_SetGPRSAccessPoint(gsm,Backup.GPRSPoint[i]);
1591 Print_Error(error);
1592 fprintf(stderr, "\r");
1593 fprintf(stderr, "%s ", _("Writing:"));
1594 fprintf(stderr, _("%i percent"),
1595 (i + 1) * 100 / max);
1596 if (gshutdown) {
1597 GSM_Terminate();
1598 Terminate(4);
1601 fprintf(stderr, "\n");
1604 GSM_FreeBackup(&Backup);
1605 GSM_Terminate();
1608 void AddNew(int argc, char *argv[])
1610 GSM_Error error;
1611 GSM_Backup Backup;
1612 GSM_DateTime date_time;
1613 GSM_MemoryEntry Pbk;
1614 GSM_MemoryStatus MemStatus;
1615 GSM_ToDoEntry ToDo;
1616 GSM_ToDoStatus ToDoStatus;
1617 GSM_NoteEntry Note;
1618 GSM_CalendarEntry Calendar;
1619 GSM_CalendarStatus CalendarStatus;
1620 GSM_WAPBookmark Bookmark;
1621 GSM_MemoryType MemoryType = 0;
1622 int i, max;
1624 for (i = 3; i < argc; i++) {
1625 if (strcasecmp(argv[i],"-yes") == 0) {
1626 always_answer_yes = TRUE;
1627 } else if (strcasecmp(argv[i],"-memory") == 0 && i + 1 < argc) {
1628 i++;
1629 MemoryType = GSM_StringToMemoryType(argv[i]);
1630 if (MemoryType == 0) {
1631 printf_err(_("Unknown memory type (\"%s\")\n"),argv[i]);
1632 Terminate(2);
1634 } else {
1635 printf_err(_("Unknown parameter (\"%s\")\n"), argv[i]);
1636 Terminate(2);
1640 if (!ReadBackup(argv[2], &Backup)) {
1641 return;
1644 signal(SIGINT, interrupt);
1645 fprintf(stderr, "%s\n", _("Press Ctrl+C to break..."));
1648 GSM_Init(TRUE);
1650 if (Backup.PhonePhonebook[0] != NULL) {
1651 MemStatus.MemoryType = (MemoryType == 0 ? MEM_ME : MemoryType);
1652 error=GSM_GetMemoryStatus(gsm, &MemStatus);
1653 /* Some phones do not support status, try reading some entry */
1654 if (error != ERR_NONE) {
1655 Pbk.Location = 1;
1656 Pbk.MemoryType = MEM_ME;
1657 error = GSM_GetMemory(gsm, &Pbk);
1658 MemStatus.MemoryFree = 9999999;
1660 if (error == ERR_NONE || error == ERR_EMPTY) {
1661 max = 0;
1662 while (Backup.PhonePhonebook[max] != NULL) {
1663 max++;
1665 fprintf(stderr, _("%i entries in backup file\n"), max);
1666 if (MemStatus.MemoryFree < max) {
1667 fprintf(stderr, _("Memory has only %i free locations.Exiting\n"), MemStatus.MemoryFree);
1668 } else if (answer_yes("%s", _("Add phone phonebook entries?"))) {
1669 for (i = 0; i < max; i++) {
1670 Pbk = *Backup.PhonePhonebook[i];
1671 Pbk.MemoryType = (MemoryType == 0 ? MEM_ME : MemoryType);
1672 error=GSM_AddMemory(gsm, &Pbk);
1673 Print_Error(error);
1674 fprintf(stderr, "\r");
1675 fprintf(stderr, "%s ", _("Writing:"));
1676 fprintf(stderr, _("%i percent"),
1677 (i + 1) * 100 / max);
1678 if (gshutdown) {
1679 GSM_Terminate();
1680 Terminate(4);
1683 fprintf(stderr, "\n");
1687 if (Backup.SIMPhonebook[0] != NULL) {
1688 MemStatus.MemoryType = (MemoryType == 0 ? MEM_SM : MemoryType);
1689 error=GSM_GetMemoryStatus(gsm, &MemStatus);
1690 if (error==ERR_NONE) {
1691 max = 0;
1692 while (Backup.SIMPhonebook[max]!=NULL) max++;
1693 fprintf(stderr, _("%i entries in backup file\n"),max);
1694 if (MemStatus.MemoryFree < max) {
1695 fprintf(stderr, _("Memory has only %i free locations.Exiting\n"),MemStatus.MemoryFree);
1696 } else if (answer_yes("%s", _("Add SIM phonebook entries?"))) {
1697 for (i=0;i<max;i++) {
1698 Pbk = *Backup.SIMPhonebook[i];
1699 Pbk.MemoryType = (MemoryType == 0 ? MEM_SM : MemoryType);
1700 error=GSM_AddMemory(gsm, &Pbk);
1701 Print_Error(error);
1702 fprintf(stderr, "\r");
1703 fprintf(stderr, "%s ", _("Writing:"));
1704 fprintf(stderr, _("%i percent"),
1705 (i + 1) * 100 / max);
1706 if (gshutdown) {
1707 GSM_Terminate();
1708 Terminate(4);
1711 fprintf(stderr, "\n");
1716 if (GSM_GetConfig(gsm, -1)->SyncTime == FALSE) {
1717 if (answer_yes("%s", _("Do you want to set phone date/time? (NOTE: in some phones it's required to correctly restore calendar notes and other items)"))) {
1718 GSM_GetCurrentDateTime(&date_time);
1720 error=GSM_SetDateTime(gsm, &date_time);
1721 Print_Error(error);
1724 if (Backup.Calendar[0] != NULL) {
1725 Calendar.Location = 1;
1726 error = GSM_GetCalendarStatus(gsm,&CalendarStatus);
1727 if (error == ERR_NONE) {
1728 if (answer_yes("%s", _("Add phone calendar notes?"))) {
1729 max = 0;
1730 while (Backup.Calendar[max]!=NULL) max++;
1731 for (i=0;i<max;i++) {
1732 Calendar = *Backup.Calendar[i];
1733 error=GSM_AddCalendar(gsm,&Calendar);
1734 Print_Error(error);
1735 fprintf(stderr, "\r");
1736 fprintf(stderr, "%s ", _("Writing:"));
1737 fprintf(stderr, _("%i percent"),
1738 (i + 1) * 100 / max);
1739 if (gshutdown) {
1740 GSM_Terminate();
1741 Terminate(4);
1744 fprintf(stderr, "\n");
1748 if (Backup.ToDo[0] != NULL) {
1749 ToDo.Location = 1;
1750 error=GSM_GetToDoStatus(gsm,&ToDoStatus);
1751 if (error == ERR_NONE) {
1752 if (answer_yes("%s", _("Add phone ToDo?"))) {
1753 max = 0;
1754 while (Backup.ToDo[max]!=NULL) max++;
1755 for (i=0;i<max;i++) {
1756 ToDo = *Backup.ToDo[i];
1757 error = GSM_AddToDo(gsm,&ToDo);
1758 Print_Error(error);
1759 fprintf(stderr, "\r");
1760 fprintf(stderr, "%s ", _("Writing:"));
1761 fprintf(stderr, _("%i percent"),
1762 (i + 1) * 100 / max);
1763 if (gshutdown) {
1764 GSM_Terminate();
1765 Terminate(4);
1768 fprintf(stderr, "\n");
1772 if (Backup.Note[0] != NULL) {
1773 Note.Location = 1;
1774 if (answer_yes("%s", _("Add notes to phone?"))) {
1775 max = 0;
1776 while (Backup.Note[max]!=NULL) max++;
1777 for (i=0;i<max;i++) {
1778 Note = *Backup.Note[i];
1779 error = GSM_AddNote(gsm,&Note);
1780 Print_Error(error);
1781 fprintf(stderr, "\r");
1782 fprintf(stderr, "%s ", _("Writing:"));
1783 fprintf(stderr, _("%i percent"),
1784 (i + 1) * 100 / max);
1785 if (gshutdown) {
1786 GSM_Terminate();
1787 Terminate(4);
1790 fprintf(stderr, "\n");
1793 if (Backup.WAPBookmark[0] != NULL) {
1794 Bookmark.Location = 1;
1795 error = GSM_GetWAPBookmark(gsm,&Bookmark);
1796 if (error == ERR_NONE || error == ERR_INVALIDLOCATION) {
1797 if (answer_yes("%s", _("Add phone WAP bookmarks?"))) {
1798 max = 0;
1799 while (Backup.WAPBookmark[max]!=NULL) max++;
1800 for (i=0;i<max;i++) {
1801 Bookmark = *Backup.WAPBookmark[i];
1802 Bookmark.Location = 0;
1803 error=GSM_SetWAPBookmark(gsm,&Bookmark);
1804 Print_Error(error);
1805 fprintf(stderr, "\r");
1806 fprintf(stderr, "%s ", _("Writing:"));
1807 fprintf(stderr, _("%i percent"),
1808 (i + 1) * 100 / max);
1809 if (gshutdown) {
1810 GSM_Terminate();
1811 Terminate(4);
1814 fprintf(stderr, "\n");
1819 GSM_FreeBackup(&Backup);
1820 GSM_Terminate();
1823 /* How should editor hadle tabs in this file? Add editor commands here.
1824 * vim: noexpandtab sw=8 ts=8 sts=8: