1 #include "../helper/locales.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"
21 * Converts between two backup formats.
23 void ConvertBackup(int argc
, char *argv
[])
28 error
= GSM_ReadBackupFile(argv
[2], &Backup
, GSM_GuessBackupFormat(argv
[2], FALSE
));
31 error
= GSM_SaveBackupFile(argv
[3], &Backup
, GSM_GuessBackupFormat(argv
[3], FALSE
));
32 GSM_FreeBackup(&Backup
);
36 void SaveFile(int argc
, char *argv
[])
43 unsigned char Buffer
[100000];
47 if (strcasecmp(argv
[2],"CALENDAR") == 0) {
49 printf("%s\n", _("Where is backup filename and location?"));
52 location
= GetInt(argv
[5]) - 1;
53 error
= GSM_ReadBackupFile(argv
[4], &Backup
,GSM_GuessBackupFormat(argv
[4], FALSE
));
54 if (error
!= ERR_NOTIMPLEMENTED
) {
58 while (Backup
.Calendar
[i
] != NULL
) {
59 if (i
== location
) break;
62 if (i
!= location
|| Backup
.Calendar
[i
] == NULL
) {
63 printf("%s\n", _("Calendar note not found in file"));
64 GSM_FreeBackup(&Backup
);
67 error
= GSM_EncodeVCALENDAR(Buffer
, sizeof(Buffer
), &data_size
, Backup
.Calendar
[i
],TRUE
,Nokia_VCalendar
);
68 GSM_FreeBackup(&Backup
);
70 } else if (strcasecmp(argv
[2],"BOOKMARK") == 0) {
72 printf("%s\n", _("Where is backup filename and location?"));
75 location
= GetInt(argv
[5]) - 1;
76 error
= GSM_ReadBackupFile(argv
[4],&Backup
,GSM_GuessBackupFormat(argv
[4], FALSE
));
77 if (error
!= ERR_NOTIMPLEMENTED
) {
81 while (Backup
.WAPBookmark
[i
]!=NULL
) {
82 if (i
== location
) break;
85 if (i
!= location
|| Backup
.WAPBookmark
[i
] == NULL
) {
86 printf("%s\n", _("WAP bookmark not found in file"));
87 GSM_FreeBackup(&Backup
);
90 error
= GSM_EncodeURLFile(Buffer
, &data_size
, Backup
.WAPBookmark
[i
]);
91 GSM_FreeBackup(&Backup
);
93 } else if (strcasecmp(argv
[2],"NOTE") == 0) {
95 printf("%s\n", _("Where is backup filename and location?"));
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
);
102 while (Backup
.Note
[i
]!=NULL
) {
103 if (i
== location
) break;
106 if (i
!= location
|| Backup
.Note
[i
] == NULL
) {
107 printf("%s\n", _("Note not found in file"));
108 GSM_FreeBackup(&Backup
);
111 error
= GSM_EncodeVNTFile(Buffer
, sizeof(Buffer
), &data_size
, Backup
.Note
[i
]);
112 GSM_FreeBackup(&Backup
);
114 } else if (strcasecmp(argv
[2],"TODO") == 0) {
116 printf("%s\n", _("Where is backup filename and location?"));
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
);
123 while (Backup
.ToDo
[i
]!=NULL
) {
124 if (i
== location
) break;
127 if (i
!= location
|| Backup
.ToDo
[i
] == NULL
) {
128 printf("%s\n", _("Todo note not found in file"));
129 GSM_FreeBackup(&Backup
);
132 error
= GSM_EncodeVTODO(Buffer
, sizeof(Buffer
), &data_size
, Backup
.ToDo
[i
], TRUE
, Nokia_VToDo
);
133 GSM_FreeBackup(&Backup
);
135 } else if (strcasecmp(argv
[2],"VCARD10") == 0 || strcasecmp(argv
[2],"VCARD21") == 0) {
137 printf("%s\n", _("Where is backup filename and location and memory type?"));
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
);
144 if (strcasecmp(argv
[5],"SM") == 0) {
145 while (Backup
.SIMPhonebook
[i
]!=NULL
) {
146 if (i
== location
) break;
149 if (i
!= location
|| Backup
.SIMPhonebook
[i
] == NULL
) {
150 printf("%s\n", _("Phonebook entry not found in file"));
151 GSM_FreeBackup(&Backup
);
154 pbk
= Backup
.SIMPhonebook
[i
];
155 } else if (strcasecmp(argv
[5],"ME") == 0) {
156 while (Backup
.PhonePhonebook
[i
]!=NULL
) {
157 if (i
== location
) break;
160 if (i
!= location
|| Backup
.PhonePhonebook
[i
] == NULL
) {
161 printf("%s\n", _("Phonebook entry not found in file"));
162 GSM_FreeBackup(&Backup
);
165 pbk
= Backup
.PhonePhonebook
[i
];
167 printf(_("Unknown memory type: \"%s\"\n"),argv
[5]);
168 GSM_FreeBackup(&Backup
);
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
);
176 error
= GSM_EncodeVCARD(GSM_GetDebug(gsm
), Buffer
, sizeof(Buffer
), &data_size
, pbk
, TRUE
, Nokia_VCard21
);
177 GSM_FreeBackup(&Backup
);
181 printf(_("Unknown backup format: \"%s\"\n"), argv
[2]);
185 file
= fopen(argv
[3],"wb");
187 printf_err("%s", _("Error while opening file for writing!\n"));
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
;
206 gboolean UseNext
= FALSE
;
209 memset(&Pbk
, 0, sizeof(GSM_MemoryEntry
));
210 MemStatus
.MemoryType
= MemoryType
;
211 Pbk
.MemoryType
= MemoryType
;
215 error
= GSM_GetMemoryStatus(gsm
, &MemStatus
);
216 if (error
== ERR_NONE
) {
217 if (MemStatus
.MemoryUsed
== 0) {
220 error
= GSM_GetNextMemory(gsm
, &Pbk
, TRUE
);
221 if (error
== ERR_NONE
) {
225 MemStatus
.MemoryUsed
= 0;
227 error
= GSM_GetNextMemory(gsm
, &Pbk
, TRUE
);
228 if (error
!= ERR_NONE
) {
233 /* Optionally ask question */
234 if (question
!= NULL
&& !answer_yes(" %s", question
)) {
241 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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."));
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
);
262 error
= GSM_GetNextMemory(gsm
, &Pbk
, FALSE
);
264 if (MemStatus
.MemoryUsed
== 0) {
265 fprintf(stderr
, "*");
267 fprintf(stderr
, "\r ");
268 fprintf(stderr
, "%s ", _("Reading:"));
269 fprintf(stderr
, _("%i percent"),
270 used
* 100 / MemStatus
.MemoryUsed
);
279 fprintf(stderr
, "\n");
285 while (used
< MemStatus
.MemoryUsed
) {
287 error
= GSM_GetMemory(gsm
, &Pbk
);
288 if (error
!= ERR_EMPTY
) {
290 if (Phonebook
!= NULL
) {
291 if (used
>= max_entries
) {
292 printf("\n %s\n", _("Only part of data saved, please increase the limit."));
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
);
309 fprintf(stderr
, "\r ");
310 fprintf(stderr
, "%s ", _("Reading:"));
311 fprintf(stderr
, _("%i percent"),
312 used
* 100 / MemStatus
.MemoryUsed
);
321 fprintf(stderr
, "\n");
328 void DoBackup(int argc
, char *argv
[])
330 GSM_Error error
= ERR_NONE
;
333 GSM_ToDoStatus ToDoStatus
;
334 GSM_CalendarEntry Calendar
;
336 GSM_WAPBookmark Bookmark
;
338 GSM_MultiWAPSettings Settings
;
339 GSM_SyncMLSettings SyncML
;
340 GSM_ChatSettings Chat
;
341 GSM_Ringtone Ringtone
;
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..."));
371 if (Info
.UseUnicode
) {
372 Info
.UseUnicode
=answer_yes("%s", _("Use Unicode subformat of backup file?"));
375 GSM_GetCurrentDateTime (&Backup
.DateTime
);
376 Backup
.DateTimeAvailable
=TRUE
;
379 error
=GSM_GetManufacturer(gsm
, Backup
.Model
);
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
);
394 error
=GSM_GetIMEI(gsm
, Backup
.IMEI
);
395 if (error
!= ERR_NOTSUPPORTED
) {
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
;
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
;
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
;
432 printf(_("Only part of data saved, please increase %s.") , "GSM_MAXCALENDARTODONOTES");
436 *Backup
.Calendar
[used
]=Calendar
;
438 error
=GSM_GetNextCalendar(gsm
,&Calendar
,FALSE
);
439 fprintf(stderr
, "*");
445 fprintf(stderr
, "\n");
448 DoBackupPart
= FALSE
;
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
;
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
;
467 printf(_("Only part of data saved, please increase %s.") , "GSM_MAXCALENDARTODONOTES");
471 *Backup
.ToDo
[used
]=ToDo
;
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
);
483 fprintf(stderr
, "\n");
485 DoBackupPart
= FALSE
;
487 printf("%s\n", _("Checking phone notes"));
489 error
=GSM_GetNextNote(gsm
,&Note
,TRUE
);
490 if (error
==ERR_NONE
) {
491 if (answer_yes(" %s", _("Backup phone notes?"))) DoBackupPart
= TRUE
;
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
;
504 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_NOTE");
508 *Backup
.Note
[used
]=Note
;
510 error
=GSM_GetNextNote(gsm
,&Note
,FALSE
);
511 fprintf(stderr
, "*");
517 fprintf(stderr
, "\n");
520 DoBackupPart
= FALSE
;
521 if (Info
.CallerLogos
) {
522 printf("%s\n", _("Checking phone caller logos"));
523 Bitmap
.Type
= GSM_CallerGroupLogo
;
525 error
=GSM_GetBitmap(gsm
,&Bitmap
);
526 if (error
== ERR_NONE
) {
527 if (answer_yes(" %s", _("Backup phone caller groups and logos?"))) DoBackupPart
= TRUE
;
531 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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
;
541 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_CALLER");
545 *Backup
.CallerLogos
[used
] = Bitmap
;
547 Bitmap
.Location
= used
+ 1;
548 error
=GSM_GetBitmap(gsm
,&Bitmap
);
549 fprintf(stderr
, "*");
555 fprintf(stderr
, "\n");
558 DoBackupPart
= FALSE
;
560 printf("%s\n", _("Checking SIM SMS profiles"));
561 if (answer_yes(" %s", _("Backup SIM SMS profiles?"))) DoBackupPart
= TRUE
;
565 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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
;
576 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_SMSC");
580 *Backup
.SMSC
[used
]=SMSC
;
582 fprintf(stderr
, "*");
584 fprintf(stderr
, "\n");
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
;
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
;
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
;
633 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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
;
642 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_WAPBOOKMARK");
646 *Backup
.WAPBookmark
[used
]=Bookmark
;
648 Bookmark
.Location
= used
+1;
649 error
=GSM_GetWAPBookmark(gsm
,&Bookmark
);
650 fprintf(stderr
, "*");
656 fprintf(stderr
, "\n");
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
;
670 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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
;
679 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_WAPSETTINGS");
683 *Backup
.WAPSettings
[used
]=Settings
;
685 Settings
.Location
= used
+1;
686 error
=GSM_GetWAPSettings(gsm
,&Settings
);
687 fprintf(stderr
, "*");
693 fprintf(stderr
, "\n");
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
;
707 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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
;
716 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_MMSSETTINGS");
720 *Backup
.MMSSettings
[used
]=Settings
;
722 Settings
.Location
= used
+1;
723 error
=GSM_GetMMSSettings(gsm
,&Settings
);
724 fprintf(stderr
, "*");
730 fprintf(stderr
, "\n");
733 DoBackupPart
= FALSE
;
734 if (Info
.ChatSettings
) {
735 printf("%s\n", _("Checking phone Chat settings"));
737 error
=GSM_GetChatSettings(gsm
,&Chat
);
738 if (error
==ERR_NONE
) {
739 if (answer_yes(" %s", _("Backup phone Chat settings?"))) DoBackupPart
= TRUE
;
744 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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
;
753 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_CHATSETTINGS");
757 *Backup
.ChatSettings
[used
]=Chat
;
759 Chat
.Location
= used
+1;
760 error
=GSM_GetChatSettings(gsm
,&Chat
);
761 fprintf(stderr
, "*");
767 fprintf(stderr
, "\n");
770 DoBackupPart
= FALSE
;
771 if (Info
.SyncMLSettings
) {
772 printf("%s\n", _("Checking phone SyncML settings"));
774 error
=GSM_GetSyncMLSettings(gsm
,&SyncML
);
775 if (error
==ERR_NONE
) {
776 if (answer_yes(" %s", _("Backup phone SyncML settings?"))) DoBackupPart
= TRUE
;
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
;
789 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_SYNCMLSETTINGS");
793 *Backup
.SyncMLSettings
[used
]=SyncML
;
795 SyncML
.Location
= used
+1;
796 error
=GSM_GetSyncMLSettings(gsm
,&SyncML
);
797 fprintf(stderr
, "*");
803 fprintf(stderr
, "\n");
806 DoBackupPart
= FALSE
;
808 printf("%s\n", _("Checking phone user ringtones"));
809 Ringtone
.Location
= 1;
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
;
819 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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
;
829 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_RINGTONES");
833 *Backup
.Ringtone
[used
]=Ringtone
;
837 Ringtone
.Location
= i
;
839 error
=GSM_GetRingtone(gsm
,&Ringtone
,FALSE
);
840 fprintf(stderr
, "*");
846 fprintf(stderr
, "\n");
849 DoBackupPart
= FALSE
;
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
;
860 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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
;
871 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_PROFILES");
875 *Backup
.Profiles
[used
]=Profile
;
877 fprintf(stderr
, "*");
879 fprintf(stderr
, "\n");
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
;
894 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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
;
905 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_FMSTATIONS");
909 *Backup
.FMStation
[used
]=FMStation
;
913 FMStation
.Location
= i
;
914 fprintf(stderr
, "*");
916 fprintf(stderr
, "\n");
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
;
931 fprintf(stderr
, LISTFORMAT
, _("Reading"));
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
;
942 printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_GPRSPOINT");
946 *Backup
.GPRSPoint
[used
]=GPRSPoint
;
950 GPRSPoint
.Location
= i
;
951 fprintf(stderr
, "*");
953 fprintf(stderr
, "\n");
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
)
967 error
= GSM_ReadBackupFile(filename
, Backup
, GSM_GuessBackupFormat(filename
, FALSE
));
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
)) {
992 void Restore(int argc
, char *argv
[])
996 GSM_FMStation FMStation
;
997 GSM_DateTime date_time
;
998 GSM_CalendarEntry Calendar
;
1000 GSM_Ringtone Ringtone
;
1001 GSM_MemoryEntry Pbk
;
1002 GSM_MemoryStatus MemStatus
;
1004 GSM_ToDoStatus ToDoStatus
;
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
)) {
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..."));
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
;
1039 while (Backup
.CallerLogos
[max
]!=NULL
) max
++;
1040 for (i
=0;i
<max
;i
++) {
1041 error
=GSM_SetBitmap(gsm
,Backup
.CallerLogos
[i
]);
1043 fprintf(stderr
, "\r");
1044 fprintf(stderr
, "%s ", _("Writing:"));
1045 fprintf(stderr
, _("%i percent"),
1046 (i
+ 1) * 100 / max
);
1052 fprintf(stderr
, "\n");
1056 if (Backup
.PhonePhonebook
[0] != NULL
) {
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
) {
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
;
1076 for (i
=0;i
<MemStatus
.MemoryUsed
+MemStatus
.MemoryFree
;i
++) {
1077 Pbk
.MemoryType
= MEM_ME
;
1078 Pbk
.Location
= i
+ 1;
1080 if (used
<max
&& Backup
.PhonePhonebook
[used
]->Location
== Pbk
.Location
) {
1081 Pbk
= *Backup
.PhonePhonebook
[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
);
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."));
1094 if (Pbk
.EntriesNum
!= 0 && error
==ERR_NONE
) {
1096 for (j
=0;j
<Pbk
.EntriesNum
;j
++) {
1097 if (Pbk
.Entries
[j
].AddError
== ERR_NONE
) continue;
1100 printf(_("Location %d"), Pbk
.Location
);
1101 printf("%20s\n ", " ");
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
) {
1118 fprintf(stderr
, "\r");
1119 fprintf(stderr
, "%s ", _("Writing:"));
1120 fprintf(stderr
, _("%i percent"),
1121 (i
+ 1) * 100 / (MemStatus
.MemoryUsed
+ MemStatus
.MemoryFree
)
1128 fprintf(stderr
, "\n");
1132 if (Backup
.SIMPhonebook
[0] != NULL
) {
1133 MemStatus
.MemoryType
= MEM_SM
;
1134 error
=GSM_GetMemoryStatus(gsm
, &MemStatus
);
1135 if (error
==ERR_NONE
) {
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
;
1144 for (i
=0;i
<MemStatus
.MemoryUsed
+MemStatus
.MemoryFree
;i
++) {
1145 Pbk
.MemoryType
= MEM_SM
;
1146 Pbk
.Location
= i
+ 1;
1148 if (used
<max
&& Backup
.SIMPhonebook
[used
]->Location
== Pbk
.Location
) {
1149 Pbk
= *Backup
.SIMPhonebook
[used
];
1151 if (Pbk
.EntriesNum
!= 0) {
1152 error
=GSM_SetMemory(gsm
, &Pbk
);
1153 if (error
==ERR_NONE
) {
1155 for (j
=0;j
<Pbk
.EntriesNum
;j
++) {
1156 if (Pbk
.Entries
[j
].AddError
== ERR_NONE
) continue;
1159 printf(_("Location %d"), Pbk
.Location
);
1160 printf("%20s\n ", " ");
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
);
1171 fprintf(stderr
, "\r");
1172 fprintf(stderr
, "%s ", _("Writing:"));
1173 fprintf(stderr
, _("%i percent"),
1174 (i
+ 1) * 100 / (MemStatus
.MemoryUsed
+ MemStatus
.MemoryFree
));
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
);
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
) {
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?"));
1207 fprintf(stderr
, "%s ", _("Deleting old notes:"));
1208 error
= GSM_DeleteAllCalendar(gsm
);
1209 if (error
== ERR_NOTSUPPORTED
|| error
== ERR_NOTIMPLEMENTED
) {
1211 error
= GSM_GetNextCalendar(gsm
,&Calendar
,TRUE
);
1212 if (error
!= ERR_NONE
) break;
1213 error
= GSM_DeleteCalendar(gsm
,&Calendar
);
1215 fprintf(stderr
, "*");
1217 fprintf(stderr
, "\n");
1219 fprintf(stderr
, "%s\n", _("Done"));
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
);
1229 fprintf(stderr
, "\r");
1230 fprintf(stderr
, "%s ", _("Writing:"));
1231 fprintf(stderr
, _("%i percent"),
1232 (i
+ 1) * 100 / max
);
1238 fprintf(stderr
, "\n");
1242 if (Backup
.ToDo
[0] != NULL
) {
1243 error
= GSM_GetToDoStatus(gsm
,&ToDoStatus
);
1244 if (error
== ERR_NONE
) {
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
;
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
) {
1261 error
= GSM_GetNextToDo(gsm
,&ToDo
,TRUE
);
1262 if (error
!= ERR_NONE
) break;
1263 error
= GSM_DeleteToDo(gsm
,&ToDo
);
1265 fprintf(stderr
, "*");
1267 fprintf(stderr
, "\n");
1269 fprintf(stderr
, "%s\n", _("Done"));
1273 for (i
=0;i
<max
;i
++) {
1274 ToDo
= *Backup
.ToDo
[i
];
1276 error
=GSM_AddToDo(gsm
,&ToDo
);
1278 fprintf(stderr
, "\r");
1279 fprintf(stderr
, "%s ", _("Writing:"));
1280 fprintf(stderr
, _("%i percent"),
1281 (i
+ 1) * 100 / max
);
1287 fprintf(stderr
, "\n");
1288 } else if (DoRestore
) {
1289 /* At first delete entries, that were deleted */
1291 error
= GSM_GetNextToDo(gsm
,&ToDo
,TRUE
);
1292 while (error
== ERR_NONE
) {
1295 for (i
=0;i
<max
;i
++) {
1296 if (Backup
.ToDo
[i
]->Location
== ToDo
.Location
) {
1302 error
=GSM_DeleteToDo(gsm
,&ToDo
);
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
);
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
);
1322 fprintf(stderr
, "\r");
1323 fprintf(stderr
, "%s ", _("Writing:"));
1324 fprintf(stderr
, _("%i percent"),
1325 (i
+ 1) * 100 / max
);
1331 fprintf(stderr
, "\n");
1335 if (Backup
.Note
[0] != NULL
) {
1336 error
= GSM_GetNotesStatus(gsm
,&ToDoStatus
);
1337 if (error
== ERR_NONE
) {
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
;
1346 fprintf(stderr
, "%s ", _("Deleting old notes:"));
1348 error
= GSM_GetNextNote(gsm
,&Note
,TRUE
);
1349 if (error
!= ERR_NONE
) break;
1350 error
= GSM_DeleteNote(gsm
,&Note
);
1352 fprintf(stderr
, "*");
1354 fprintf(stderr
, "\n");
1356 for (i
=0;i
<max
;i
++) {
1357 Note
= *Backup
.Note
[i
];
1359 error
=GSM_AddNote(gsm
,&Note
);
1361 fprintf(stderr
, "\r");
1362 fprintf(stderr
, "%s ", _("Writing:"));
1363 fprintf(stderr
, _("%i percent"),
1364 (i
+ 1) * 100 / max
);
1370 fprintf(stderr
, "\n");
1373 if (Backup
.SMSC
[0] != NULL
&& answer_yes("%s", _("Restore SIM SMSC profiles?"))) {
1375 while (Backup
.SMSC
[max
]!=NULL
) max
++;
1376 for (i
=0;i
<max
;i
++) {
1377 error
=GSM_SetSMSC(gsm
,Backup
.SMSC
[i
]);
1379 fprintf(stderr
, "\r");
1380 fprintf(stderr
, "%s ", _("Writing:"));
1381 fprintf(stderr
, _("%i percent"),
1382 (i
+ 1) * 100 / max
);
1388 fprintf(stderr
, "\n");
1390 if (Backup
.StartupLogo
!= NULL
&& answer_yes("%s", _("Restore phone startup logo/text?"))) {
1391 error
=GSM_SetBitmap(gsm
,Backup
.StartupLogo
);
1394 if (Backup
.OperatorLogo
!= NULL
&& answer_yes("%s", _("Restore phone operator logo?"))) {
1395 error
=GSM_SetBitmap(gsm
,Backup
.OperatorLogo
);
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
;
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
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");
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
);
1428 fprintf(stderr
, "\r");
1429 fprintf(stderr
, "%s ", _("Writing:"));
1430 fprintf(stderr
, _("%i percent"),
1431 (i
+ 1) * 100 / max
);
1437 fprintf(stderr
, "\n");
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
;
1449 while (Backup
.WAPSettings
[max
]!=NULL
) max
++;
1450 for (i
=0;i
<max
;i
++) {
1451 error
=GSM_SetWAPSettings(gsm
,Backup
.WAPSettings
[i
]);
1453 fprintf(stderr
, "\r");
1454 fprintf(stderr
, "%s ", _("Writing:"));
1455 fprintf(stderr
, _("%i percent"),
1456 (i
+ 1) * 100 / max
);
1462 fprintf(stderr
, "\n");
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
;
1474 while (Backup
.MMSSettings
[max
]!=NULL
) max
++;
1475 for (i
=0;i
<max
;i
++) {
1476 error
=GSM_SetMMSSettings(gsm
,Backup
.MMSSettings
[i
]);
1478 fprintf(stderr
, "\r");
1479 fprintf(stderr
, "%s ", _("Writing:"));
1480 fprintf(stderr
, _("%i percent"),
1481 (i
+ 1) * 100 / max
);
1487 fprintf(stderr
, "\n");
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
;
1499 fprintf(stderr
, LISTFORMAT
, _("Deleting"));
1500 error
=GSM_DeleteUserRingtones(gsm
);
1502 fprintf(stderr
, "%s\n", _("Done"));
1504 if (answer_yes("%s", _("Restore user ringtones?"))) DoRestore
= TRUE
;
1508 while (Backup
.Ringtone
[max
]!=NULL
) max
++;
1509 for (i
=0;i
<max
;i
++) {
1510 error
=GSM_RingtoneConvert(&Ringtone
, Backup
.Ringtone
[i
], Ringtone
.Format
);
1512 error
=GSM_SetRingtone(gsm
,&Ringtone
,&i
);
1514 fprintf(stderr
, "\r");
1515 fprintf(stderr
, "%s ", _("Writing:"));
1516 fprintf(stderr
, _("%i percent"),
1517 (i
+ 1) * 100 / max
);
1523 fprintf(stderr
, "\n");
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
;
1534 Profile
.Location
= 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
);
1546 fprintf(stderr
, "\n");
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
;
1557 fprintf(stderr
, "%s ", _("Deleting old FM stations:"));
1558 error
=GSM_ClearFMStations(gsm
);
1560 fprintf(stderr
, "%s\n", _("Done"));
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
);
1567 fprintf(stderr
, "\r");
1568 fprintf(stderr
, "%s ", _("Writing:"));
1569 fprintf(stderr
, _("%i percent"),
1570 (i
+ 1) * 100 / max
);
1576 fprintf(stderr
, "\n");
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
;
1588 while (Backup
.GPRSPoint
[max
]!=NULL
) max
++;
1589 for (i
=0;i
<max
;i
++) {
1590 error
=GSM_SetGPRSAccessPoint(gsm
,Backup
.GPRSPoint
[i
]);
1592 fprintf(stderr
, "\r");
1593 fprintf(stderr
, "%s ", _("Writing:"));
1594 fprintf(stderr
, _("%i percent"),
1595 (i
+ 1) * 100 / max
);
1601 fprintf(stderr
, "\n");
1604 GSM_FreeBackup(&Backup
);
1608 void AddNew(int argc
, char *argv
[])
1612 GSM_DateTime date_time
;
1613 GSM_MemoryEntry Pbk
;
1614 GSM_MemoryStatus MemStatus
;
1616 GSM_ToDoStatus ToDoStatus
;
1618 GSM_CalendarEntry Calendar
;
1619 GSM_CalendarStatus CalendarStatus
;
1620 GSM_WAPBookmark Bookmark
;
1621 GSM_MemoryType MemoryType
= 0;
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
) {
1629 MemoryType
= GSM_StringToMemoryType(argv
[i
]);
1630 if (MemoryType
== 0) {
1631 printf_err(_("Unknown memory type (\"%s\")\n"),argv
[i
]);
1635 printf_err(_("Unknown parameter (\"%s\")\n"), argv
[i
]);
1640 if (!ReadBackup(argv
[2], &Backup
)) {
1644 signal(SIGINT
, interrupt
);
1645 fprintf(stderr
, "%s\n", _("Press Ctrl+C to break..."));
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
) {
1656 Pbk
.MemoryType
= MEM_ME
;
1657 error
= GSM_GetMemory(gsm
, &Pbk
);
1658 MemStatus
.MemoryFree
= 9999999;
1660 if (error
== ERR_NONE
|| error
== ERR_EMPTY
) {
1662 while (Backup
.PhonePhonebook
[max
] != NULL
) {
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
);
1674 fprintf(stderr
, "\r");
1675 fprintf(stderr
, "%s ", _("Writing:"));
1676 fprintf(stderr
, _("%i percent"),
1677 (i
+ 1) * 100 / max
);
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
) {
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
);
1702 fprintf(stderr
, "\r");
1703 fprintf(stderr
, "%s ", _("Writing:"));
1704 fprintf(stderr
, _("%i percent"),
1705 (i
+ 1) * 100 / max
);
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
);
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?"))) {
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
);
1735 fprintf(stderr
, "\r");
1736 fprintf(stderr
, "%s ", _("Writing:"));
1737 fprintf(stderr
, _("%i percent"),
1738 (i
+ 1) * 100 / max
);
1744 fprintf(stderr
, "\n");
1748 if (Backup
.ToDo
[0] != NULL
) {
1750 error
=GSM_GetToDoStatus(gsm
,&ToDoStatus
);
1751 if (error
== ERR_NONE
) {
1752 if (answer_yes("%s", _("Add phone ToDo?"))) {
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
);
1759 fprintf(stderr
, "\r");
1760 fprintf(stderr
, "%s ", _("Writing:"));
1761 fprintf(stderr
, _("%i percent"),
1762 (i
+ 1) * 100 / max
);
1768 fprintf(stderr
, "\n");
1772 if (Backup
.Note
[0] != NULL
) {
1774 if (answer_yes("%s", _("Add notes to phone?"))) {
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
);
1781 fprintf(stderr
, "\r");
1782 fprintf(stderr
, "%s ", _("Writing:"));
1783 fprintf(stderr
, _("%i percent"),
1784 (i
+ 1) * 100 / max
);
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?"))) {
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
);
1805 fprintf(stderr
, "\r");
1806 fprintf(stderr
, "%s ", _("Writing:"));
1807 fprintf(stderr
, _("%i percent"),
1808 (i
+ 1) * 100 / max
);
1814 fprintf(stderr
, "\n");
1819 GSM_FreeBackup(&Backup
);
1823 /* How should editor hadle tabs in this file? Add editor commands here.
1824 * vim: noexpandtab sw=8 ts=8 sts=8: