/usr/share/perl5/PilotMgr/SyncMemo.pm is in pilot-manager 1.107.0pre108-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 | # Copyright (c) 1997 Sun Microsystems, Inc.
# All rights reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in
# all copies of this software.
#
# IN NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF SUN
# MICROSYSTEMS, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# SUN MICROSYSTEMS, INC. SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THE SOFTWARE PROVIDED
# HEREUNDER IS ON AN "AS IS" BASIS, AND SUN MICROSYSTEMS, INC. HAS NO
# OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
# MODIFICATIONS.
#
# SyncMemo conduit for PilotManager
# Alan Harder, 4/97
# Alan.Harder@Sun.COM
# version 1.7, 2/99
#
# Patch to use Shell.pm module instead of backtick(`) shell calls in v1.7
# submitted by Jeff Dairiki <dairiki@dairiki.org>.
#
package SyncMemo;
use Tk;
use TkUtils;
use strict;
use Data::Dumper;
use Carp;
# $gHomeDirectory; # base directory for files
# $gOnlyAscii; # whether to limit files to "ascii text"
# $OnlyFilesToPilot; # whether to do pilot->file transfers
# $gMemoUpdater; # script for updating memo files
# $gUseUpdater; # whether or not to run update script
# $gPostUpdater; # post update script
# $gUsePostUpdater; # whether or not to run post update script
# $gUseFilemerge; # whether to use filemerge to merge changes
# $gBlowAwayPilot; # nuke all pilot memos and copy over files
my ($gConfigDialog); # configuration dialog
my ($gDismissBtn); # dismiss button on config dialog
my ($gFilemergeCb); # "Use Filemerge" checkbutton
my ($gDefSyncMenu); # Default Sync Type menu
my ($gInfoDialog); # Sync Type info dialog
my ($gYesNoDialog); # yes/no dialog
my ($RCFILE); # configuration file
my ($DBFILE); # record of files/checksums
my ($PREFS); # configuration variables
my $VERSION = "1.8 (early-access2)"; # SyncMemo version
sub conduitInit
{
$RCFILE = "SyncMemo/SyncMemo.prefs";
$DBFILE = $PREFS->{"DBFILE"} = "SyncMemo/SyncMemo.db";
&loadPrefs;
$PREFS->{"gHomeDirectory"} = "$ENV{HOME}/.pilotmgr/SyncMemo"
unless (defined($PREFS->{"gHomeDirectory"}));
$PREFS->{"gOnlyAscii"} = 1
unless (defined($PREFS->{"gOnlyAscii"}));
$PREFS->{"OnlyFilesToPilot"} = 0
unless (defined($PREFS->{"OnlyFilesToPilot"}));
$PREFS->{"gMemoUpdater"} = "$ENV{HOME}/.pilotmgr/SyncMemo/update"
unless (defined($PREFS->{"gMemoUpdater"}));
$PREFS->{"gUseUpdater"} = 0
unless (defined($PREFS->{"gUseUpdater"}));
$PREFS->{"gPostUpdater"} = ""
unless (defined($PREFS->{"gPostUpdater"}));
$PREFS->{"gUsePostUpdater"} = 0
unless (defined($PREFS->{"gUsePostUpdater"}));
$PREFS->{"gUseFilemerge"} = 0
unless (defined($PREFS->{"gUseFilemerge"}));
$PREFS->{"gBlowAwayPilot"} = 0
unless (defined($PREFS->{"gBlowAwayPilot"}));
$PREFS->{'UseDefaultSyncType'} = 0
unless (defined($PREFS->{'UseDefaultSyncType'}));
$PREFS->{'DefaultSyncType'} = 'Full'
unless (defined($PREFS->{'DefaultSyncType'}));
$PREFS->{'useSkipStart'} = 0
unless (defined($PREFS->{'useSkipStart'}));
$PREFS->{'useSkipEnd'} = 0
unless (defined($PREFS->{'useSkipEnd'}));
$PREFS->{'skipStart'} = '#'
unless (defined($PREFS->{'skipStart'}));
$PREFS->{'skipEnd'} = '~'
unless (defined($PREFS->{'skipEnd'}));
$PREFS->{'privateHandler'} = 'Default Handling'
unless (defined($PREFS->{'privateHandler'}));
$PREFS->{'privatePerms'} = '640'
unless (defined($PREFS->{'privatePerms'}));
}
sub conduitQuit
{
&savePrefs;
}
sub conduitInfo
{
return { "database" =>
{
"name" => "MemoDB",
"creator" => "memo",
"type" => "DATA",
"flags" => 0,
"version" => 0,
},
"version" => $VERSION,
"author" => "Alan Harder",
"email" => "Alan.Harder\@Sun.COM" };
}
sub conduitConfigure
{
my ($this, $wm) = @_;
my ($frame, $obj, $subfr);
unless (defined($gConfigDialog))
{
$gConfigDialog = $wm->Toplevel(-title => "Configuring SyncMemo");
$gConfigDialog->transient($wm);
$gYesNoDialog = $wm->Dialog(-title => "Do Something",
-text =>
"Are you sure? \n(No undo!) ",
-justify => "center",
-buttons => ["Yes", "No"],
-default_button => "No",
-popover => $gConfigDialog,
-overanchor => 'c', -popanchor => 'c');
PilotMgr::setColors($gYesNoDialog);
$gInfoDialog = $wm->Toplevel(-title => "SyncMemo");
$gInfoDialog->transient($wm);
$gInfoDialog->withdraw;
$frame = $gInfoDialog->Frame;
($obj) = TkUtils::Text($frame, "Sync Type Info");
$obj->insert('end',
"Sometimes SyncMemo will popup a dialog asking whether " .
"a full or fast sync should be performed. The purpose of " .
"this dialog is to make sure all memo changes get noticed " .
"during the hotsync. There are two cases this might not " .
"happen:\n 1. You have restored a backed up MemoDB file- any " .
"and all memos may now be totally different, so a full sync " .
"is in order!\n 2. You have synced to another machine- when " .
"you do this the memos you had changed will be updated to " .
"THAT machine, and then cleared so that when SyncMemo does " .
"its next sync it doesn't know the memo has changed. The " .
"only way to get all the changes is to do a full sync " .
"(load ALL the memos and look at them to see if they have " .
"changed).\nIf you find that you see this dialog a lot and " .
"always give the same answer you can use the Default Sync " .
"Type option in the SyncMemo configuration dialog to specify ".
"a default answer. HOWEVER, if you choose Fast Sync as your ".
"default YOU must be aware of when the above conditions " .
"occur and manually select Reset SyncMemo from the config " .
"dialog to force a full sync.");
$obj->configure(-height => 20, -state => 'disabled');
$obj->pack(-expand => 1, -fill => 'both');
$obj = TkUtils::Button($frame, "Dismiss", sub{$gInfoDialog->withdraw});
$obj->pack;
$frame->pack(-expand => 1, -fill => 'both');
PilotMgr::setColors($gInfoDialog);
$frame = $gConfigDialog->Frame(-relief => "ridge", -bd => 4);
$obj = TkUtils::Label($frame, "SyncMemo Settings");
$obj->pack(-anchor => "c");
$subfr = $frame->Frame;
$obj = $subfr->Label(-text => "Memo directory: ");
$obj->pack(-side => "left", -anchor => "nw", -fill => "x");
$obj = $subfr->Entry(-textvariable => \$PREFS->{"gHomeDirectory"},
-relief => "sunken", -width => 60);
$obj->pack(-side => "right", -anchor => "w", -fill => "x");
$subfr->pack(-anchor => "e");
$subfr = $frame->Frame;
$obj = $subfr->Label(-text => "Skip files:");
$obj->pack(-side => "left", -anchor => "nw", -fill => "x");
$obj = TkUtils::Checkbutton($subfr, "starting with",
\$PREFS->{"useSkipStart"});
$obj->pack(-side => "left", -anchor => "w", -fill => "x");
$obj = $subfr->Entry(-textvariable => \$PREFS->{"skipStart"},
-relief => "sunken", -width => 15);
$obj->pack(-side => "left", -anchor => "w", -fill => "x");
$obj = TkUtils::Checkbutton($subfr, "ending with",
\$PREFS->{"useSkipEnd"});
$obj->pack(-side => "left", -anchor => "w", -fill => "x");
$obj = $subfr->Entry(-textvariable => \$PREFS->{"skipEnd"},
-relief => "sunken", -width => 16);
$obj->pack(-side => "left", -anchor => "w", -fill => "x");
$subfr->pack(-anchor => "e");
$subfr = $frame->Frame;
TkUtils::LabelRadiobuttons($subfr, "Private memos:",
\$PREFS->{"privateHandler"},
"Default Handling",
"Skip", "Use permissions:");
$obj = $subfr->Entry(-textvariable => \$PREFS->{"privatePerms"},
-relief => "sunken", -width => 4);
$obj->pack;
$subfr->pack;
$subfr = $frame->Frame;
$obj = TkUtils::Checkbutton($subfr, "Only sync text files",
\$PREFS->{"gOnlyAscii"});
$obj->pack(-side => "left", -fill => "x");
$gFilemergeCb = TkUtils::Checkbutton($subfr, "Use Filemerge",
\$PREFS->{"gUseFilemerge"});
$gFilemergeCb->configure(-state => "disabled")
if ($PREFS->{"OnlyFilesToPilot"});
$gFilemergeCb->pack(-side => 'right', -fill => 'x');
$obj = TkUtils::Checkbutton($subfr, 'Only Sync Files->Pilot',
\$PREFS->{'OnlyFilesToPilot'});
$obj->configure(-command => sub{
$gFilemergeCb->configure(-state => (($gFilemergeCb->cget('-state')
eq 'normal') ? 'disabled' : 'normal')) });
$obj->pack(-side => "left", -fill => "x");
$subfr->pack;
$frame->pack(-side => "top", -fill => "x");
$frame = $gConfigDialog->Frame(-relief => "ridge", -bd => 4);
$obj = TkUtils::Label($frame, "Update Scripts");
$obj->pack(-anchor => "c");
$subfr = $frame->Frame;
$obj = $subfr->Label(-text => "Pre-Update script: ");
$obj->pack(-side => "left", -anchor => "nw", -fill => "x");
$obj = $subfr->Entry(-textvariable => \$PREFS->{"gMemoUpdater"},
-relief => "sunken", -width => 60);
$obj->pack(-side => "right", -anchor => "w", -fill => "x");
$subfr->pack(-anchor => "e");
$subfr = $frame->Frame;
$obj = $subfr->Label(-text => "Post-Update script: ");
$obj->pack(-side => "left", -anchor => "nw", -fill => "x");
$obj = $subfr->Entry(-textvariable => \$PREFS->{"gPostUpdater"},
-relief => "sunken", -width => 60);
$obj->pack(-side => "right", -anchor => "w", -fill => "x");
$subfr->pack(-anchor => "e");
$subfr = $frame->Frame;
$obj = TkUtils::Checkbutton($subfr,"Run pre-update script before sync",
\$PREFS->{"gUseUpdater"});
$obj->pack(-side => "left", -fill => "x");
$obj = TkUtils::Checkbutton($subfr,"Run post-update script after sync",
\$PREFS->{"gUsePostUpdater"});
$obj->pack(-fill => "x");
$subfr->pack;
$subfr = $frame->Frame;
$gDismissBtn = TkUtils::Button($gConfigDialog, "Dismiss",
sub{ &savePrefs; $gConfigDialog->withdraw });
$obj = TkUtils::Button($subfr, "Run Pre-Update Script Now",
sub{ if (-x $PREFS->{"gMemoUpdater"}) {
$gDismissBtn->configure(-state => "disabled");
my ($curs) = ($gConfigDialog->cget("-cursor"));
$gConfigDialog->configure(-cursor => "watch");
$gConfigDialog->update;
system "$PREFS->{gMemoUpdater}";
$gConfigDialog->configure(-cursor => $curs);
$gDismissBtn->configure(-state => "normal");
} });
$obj->pack(-side => "left", -anchor => "w", -fill => "x");
$obj = TkUtils::Button($subfr, "Run Post-Update Script Now",
sub{ if (-x $PREFS->{"gPostUpdater"}) {
$gDismissBtn->configure(-state => "disabled");
my ($curs) = ($gConfigDialog->cget("-cursor"));
$gConfigDialog->configure(-cursor => "watch");
$gConfigDialog->update;
system "$PREFS->{gPostUpdater}";
$gConfigDialog->configure(-cursor => $curs);
$gDismissBtn->configure(-state => "normal");
} });
$obj->pack(-side => "left", -anchor => "w", -fill => "x");
$subfr->pack;
$frame->pack(-side => "top", -fill => "x");
$frame = $gConfigDialog->Frame(-relief => "ridge", -bd => 4);
$obj = TkUtils::Label($frame, "Special Options");
$obj->pack(-anchor => "center");
$obj = TkUtils::Label($frame,
"These options allow special actions to be performed on your " .
"next hotsync.\nA Reset will cause SyncMemo to reexamine ALL " .
"memos on the Pilot instead of just\nthose that have changed. " .
"Blowing away either the Pilot or Files will cause ALL memos\n" .
"in that database to be deleted and replaced with the contents " .
"of the other database.");
$obj->configure(-justify => "left");
$obj->pack(-anchor => "center");
$subfr = $frame->Frame;
$obj = TkUtils::Button($subfr, "Reset SyncMemo",
sub{ $gYesNoDialog->configure(-title => "Reset SyncMemo");
unlink ($PREFS->{"DBFILE"}) if ($gYesNoDialog->Show eq "Yes");
});
$obj->pack(-side => "left", -anchor => "w", -fill => "x");
$obj = TkUtils::Button($subfr, "Overwrite Pilot",
sub{ $gYesNoDialog->configure(-title => "Overwrite Pilot");
if ($gYesNoDialog->Show eq "Yes")
{
unlink($PREFS->{"DBFILE"});
$PREFS->{"gBlowAwayPilot"} = 1;
}
});
$obj->pack(-side => "left", -anchor => "w", -fill => "x");
$obj = TkUtils::Button($subfr, "Overwrite Files",
sub{ $gYesNoDialog->configure(-title => "Overwrite Files");
if ($gYesNoDialog->Show eq "Yes")
{
unlink($PREFS->{"DBFILE"});
&cleanDir($PREFS->{"gHomeDirectory"}, 1);
}
});
$obj->pack(-side => "left", -anchor => "w", -fill => "x");
$subfr->pack;
$frame->pack(-side => 'top', -fill => 'x');
$frame = $gConfigDialog->Frame(-relief => 'ridge', -bd => 4);
$obj = TkUtils::Label($frame, 'Advanced Options');
$obj->pack(-anchor => 'center');
$subfr = $frame->Frame;
$obj = TkUtils::Checkbutton($subfr, 'Sync type defaults to ',
\$PREFS->{'UseDefaultSyncType'});
$obj->pack(-side => 'left', -fill => 'x');
$gDefSyncMenu = TkUtils::Menu($subfr,
$PREFS->{"DefaultSyncType"},
sub{ ($PREFS->{"DefaultSyncType"} = $_[0]) =~ s|.*/ ||;
$gDefSyncMenu->configure(-text => $PREFS->{'DefaultSyncType'});
},
'Fast', [], 'Full', []);
$subfr->pack;
$subfr = $frame->Frame;
$obj = TkUtils::Label($subfr,
"This option allows you to skip the popup dialog during the " .
"sync which asks if\na Fast or Full sync should be performed. " .
"Only activate this option if you know\nwhat you are doing.");
$obj->configure(-justify => 'left');
$obj->pack(-side => 'left', -anchor => 'center');
$obj = TkUtils::Button($subfr, "More\nInfo",
sub{ $gInfoDialog->Popup(-popanchor => 'c', -overanchor => 'c',
-popover => $gConfigDialog);
});
$obj->pack(-anchor => 'center');
$subfr->pack;
$frame->pack(-side => 'top', -fill => 'x');
$gDismissBtn->pack(-side => 'bottom', -anchor => 'c');
PilotMgr::setColors($gConfigDialog);
}
$gConfigDialog->Popup(-popanchor => 'c',
-popover => $wm,
-overanchor => 'c');
}
sub cleanDir
{
my ($dir, $top) = @_;
my ($sub, @dirlist);
opendir DIR, $dir;
@dirlist = readdir DIR;
closedir DIR;
foreach $sub (@dirlist)
{
next if $sub =~ /^\.\.?$/;
$sub = "$dir/$sub";
# If we're in the top directory, don't clean files only
# clean directories.
#
next if ($top and -f $sub);
if (-d $sub)
{
&cleanDir($sub, 0);
rmdir($sub);
}
elsif (-f $sub)
{
unlink $sub;
}
}
}
sub conduitSync
{
my ($this, $dlp, $info) = @_;
my (%oldsum, %newsum, %piid, %pifile, $record, %pilot, $fullsync);
my ($appinfo, $cnt,$ret, $file,$fname, $a1,$a2,$a3, $i, $lastsync);
my (@cats, %catcase, %catindx, $cat, @cat_ids,
$updates, $filetext, $pilot_dbhandle);
my ($dbinfo) = (&conduitInfo->{database});
my ($dbname) = ($dbinfo->{name});
# Special case! "Overwrite Pilot"
if ($PREFS->{"gBlowAwayPilot"})
{
$PREFS->{"gBlowAwayPilot"} = 0;
&savePrefs;
PilotMgr::msg(
"Overwrite Pilot option: deleting and recreating $dbname!");
$ret = $dlp->delete($dbname);
if ($ret < 0)
{
$ret = PDA::Pilot::errorText($ret);
PilotMgr::msg("Error $ret while deleting $dbname.. Aborting!");
return;
}
$pilot_dbhandle = $dlp->create($dbname, $dbinfo->{creator},
$dbinfo->{type}, $dbinfo->{flags},
$dbinfo->{version});
}
else
{
# Open or create DB:
eval
{
$pilot_dbhandle = $dlp->open($dbname);
};
if ($@ =~ /read-only value/)
{
PilotMgr::msg("Pilot database '$dbname' does not exist.\n" .
"Creating it...");
$pilot_dbhandle = $dlp->create($dbname, $dbinfo->{creator},
$dbinfo->{type}, $dbinfo->{flags},
$dbinfo->{version});
}
elsif ($@)
{
croak($@);
}
}
if (!defined($pilot_dbhandle))
{
PilotMgr::msg("Unable to open/create '$dbname'. Aborting!");
return;
}
# Let the user know what we're doing
#
$dlp->getStatus();
$appinfo = $pilot_dbhandle->getAppBlock();
@cats = @{$appinfo->{categoryName}};
@cat_ids = @{$appinfo->{categoryID}};
foreach $i ($[..$#cats)
{
next unless (length($cats[$i])>0);
$cats[$i] =~ tr|/|+|;
$cat = $cats[$i];
$cat =~ tr/A-Z/a-z/;
$catcase{$cat} = $cats[$i]; # translate lowercase to anycase
$catindx{$cats[$i]} = $i; # translate anycase to index
}
# Run pre-update script
if ($PREFS->{"gUseUpdater"})
{
PilotMgr::status("Running pre-update script", 0);
&runScript($dlp, $PREFS->{"gMemoUpdater"}, "memo update");
PilotMgr::status("Running pre-update script", 100);
}
# Read DBFILE
($a1, $a2, $a3, $lastsync) = &readDBFile;
if ($lastsync > 0)
{
if ($lastsync != $info->{"successfulSyncDate"})
{
if ($PREFS->{'UseDefaultSyncType'})
{
$i = $PREFS->{'DefaultSyncType'} . ' Sync';
}
else
{
$dlp->watchdog(20);
$i = PilotMgr::askUser("Your last sync was either " .
"unsuccessful or did not include SyncMemo. If you have " .
"done any memo sync operations to another machine or " .
"restored an old MemoDB file you should do a full sync " .
"now. Otherwise a fast sync is still safe...",
'Fast Sync', 'Full Sync');
$dlp->watchdog(0);
}
unless ($i =~ /full/i)
{
%oldsum = %$a1; %piid = %$a2; %pifile = %$a3;
}
}
else
{
%oldsum = %$a1; %piid = %$a2; %pifile = %$a3;
}
}
# Check files
%newsum = &checkFiles($dlp, %oldsum);
# Read pilot changes
unless ($PREFS->{'OnlyFilesToPilot'})
{
if (%oldsum)
{
%pilot = &readChangedMemos($dlp, $pilot_dbhandle);
$fullsync = 0;
} else {
%pilot = &readAllMemos($dlp, $pilot_dbhandle);
$fullsync = 1;
}
# Check for renamed categories
if (defined($PREFS->{"categories"}))
{
for ($i=0; $i < 16; $i++)
{
if ($cats[$i] && $PREFS->{"categories"}->[$i] &&
($cats[$i] ne $PREFS->{"categories"}->[$i]))
{
# Category renamed! Add records to be processed:
#(This could be more efficient by just renaming the dir)
PilotMgr::msg("Processing Category Change: " .
$PREFS->{"categories"}->[$i] . " -> " .
$cats[$i]);
%pilot = &readMemosInCategory($pilot_dbhandle,
$i, {%pilot});
}
}
}
$PREFS->{"categories"} = [@cats];
}
#compare and update
$cnt = 0;
$updates = "";
my ($count, $count_max) = (0, scalar(keys %newsum));
foreach $file (keys(%newsum))
{
unless ($count % &fake_ceil($count_max / 20))
{
PilotMgr::status("Synchronizing Memos",
int (100 * $count / $count_max));
}
$dlp->tickle unless (++$count % 40);
if (!defined($oldsum{$file}) ||
$newsum{$file} ne $oldsum{$file})
{
# Do update
$cnt++;
unless (open(FD, "<$file"))
{
PilotMgr::msg("Error reading $file.");
$newsum{$file} = $oldsum{$file};
delete $oldsum{$file};
next;
}
$filetext = join('', <FD>);
close(FD);
# determine category based on containing directory...
if ($file =~ m|/([^/]*)/[^/]*$|)
{
$cat = $a3 = $1;
$cat =~ tr/A-Z/a-z/;
if (!defined($catcase{$cat}))
{
for ($a1 = 0; $a1 < 16; $a1++)
{
if (!length($cats[$a1]))
{
$cats[$a1] = $a3;
$appinfo->{categoryName} = [@cats];
$catcase{$cat} = $a3;
$catindx{$a3} = $a1;
$a3 = 129;
foreach $a2 (@cat_ids)
{
$a3 = ord($a2) + 1 if (ord($a2) >= $a3);
}
$cat_ids[$a1] = sprintf("%c", $a3);
$appinfo->{categoryID} = [@cat_ids];
PilotMgr::msg("Creating new Pilot category '" .
$catcase{$cat} . "' with id " . $a3 . ".");
$i = $pilot_dbhandle->setAppBlock($appinfo);
if ($i < 0)
{
$i = PDA::Pilot::errorText($i);
PilotMgr::msg("** Error $i creating new " .
" category $catcase{$cat} on Pilot.");
}
last;
}
}
}
$cat = $catcase{$cat};
$cat = defined($catindx{$cat}) ? $catindx{$cat} : "";
}
$record = &fileToNeutral($piid{$file}, $cat, $filetext);
$fname = $file;
$fname =~ s|^$PREFS->{"gHomeDirectory"}/||;
if (defined($record->{pilot_id}) &&
defined($pilot{$record->{pilot_id}}))
{
if ($pilot{$record->{pilot_id}} eq "DELETED")
{
PilotMgr::msg("Memo $fname ($record->{pilot_id}) " .
"was deleted on the Pilot but modified on the " .
"workstation.. recreating on Pilot..");
}
elsif (&recsDiffer($record, $pilot{$record->{pilot_id}}))
{
$cat = $cats[$pilot{$record->{pilot_id}}->{category}];
if ($fname !~ m|$cat/[^/]+$|)
{
# Category changed too!
PilotMgr::msg("(Category Change: $fname)");
unlink($file);
delete $piid{$file};
delete $oldsum{$file};
delete $newsum{$file};
$fname =~ s|^.*/||g;
$file = "$PREFS->{gHomeDirectory}/$cat";
$record->{category} = defined($catindx{$cat})
? $catindx{$cat} : "";
mkdir($file, 0755) unless (-d $file);
if (-e "$file/$fname") {
$file = &mktemp($file);
} else {
$file .= "/$fname";
}
$fname = "$cat/$fname";
$piid{$file} = $record->{pilot_id};
}
PilotMgr::msg("Memo $fname ($record->{pilot_id}) " .
"modified on Pilot and workstation..");
&mergeRecs($dlp, $record,
$pilot{$record->{pilot_id}});
PilotMgr::msg("Update File: $fname");
open(FD, ">$file");
print FD &neutralToFile($record);
close(FD);
$ret = &cksum($file);
if ($ret =~ /^(\d+)\s+(\d+)/)
{
$newsum{$file} = "$1 $2";
}
else
{
PilotMgr::msg("Sum Error: couldn't retrieve checksum ",
"for $fname, using zero sum. (sum='$ret')");
$newsum{$file} = "0 0";
}
if ($pilot{$record->{pilot_id}}->{"private"} and
$PREFS->{"privateHandler"} eq "Use permissions:" and
$PREFS->{"privatePerms"} > 0)
{
chmod oct($PREFS->{"privatePerms"}), $file;
}
$updates .= "$file\n";
}
delete $pilot{$record->{pilot_id}};
}
if ($fullsync && ($ret = &matchRec(\%pilot, $record)))
{
PilotMgr::msg("Matching $fname and Pilot record $ret.");
delete $pilot{$ret};
} else {
PilotMgr::msg("Update Pilot: $fname.");
$ret = &writeMemo($record, $dlp, $pilot_dbhandle);
}
if ($ret < 0)
{
$ret = PDA::Pilot::errorText($ret);
PilotMgr::msg("Error $ret writing $file to pilot.");
$dlp->log("SyncMemo: Error $ret writing $file to pilot.");
$newsum{$file} = $oldsum{$file};
delete $oldsum{$file};
next;
}
$piid{$file} = $ret;
}
delete $oldsum{$file} if (defined($oldsum{$file}));
}
# check for files to delete
$count = 0;
foreach $file (keys(%oldsum))
{
$dlp->tickle unless (++$count % 40);
$fname = $file;
$fname =~ s|^$PREFS->{"gHomeDirectory"}/||;
if (defined($pilot{$piid{$file}}))
{
if ($pilot{$piid{$file}} eq "DELETED")
{
# delete on both sides, no action needed..
delete $pilot{$piid{$file}};
} else {
PilotMgr::msg("Memo $fname ($piid{$file}) " .
"was deleted on the workstation but modified on the " .
"Pilot.. recreating workstation file..");
}
next;
}
PilotMgr::msg("Delete Pilot: $fname ($piid{$file})");
$ret = &deleteRecord($dlp, $pilot_dbhandle, $piid{$file});
if ($ret < 0)
{
$ret = PDA::Pilot::errorText($ret);
PilotMgr::msg("Error $ret deleting pilot record $piid{$file}!!");
$dlp->log("SyncMemo: Error $ret deleting pilot record " .
$piid{$file});
}
$cnt++;
}
# Check pilot changes
unless ($PREFS->{'OnlyFilesToPilot'})
{
$count = 0;
foreach $i (keys(%pilot))
{
$dlp->tickle unless (++$count % 20);
$cnt++;
if ($pilot{$i} eq "DELETED")
{
if (defined($pifile{$i}))
{
$file = $fname = $pifile{$i};
$fname =~ s|^$PREFS->{"gHomeDirectory"}/||;
PilotMgr::msg("Delete File: $fname.");
unlink($file);
delete $newsum{$file};
delete $piid{$file};
delete $pifile{$i};
$updates .= "$file\n";
} else {
PilotMgr::msg("Memo $i deleted on Pilot but file not " .
"found.. ignored.");
}
}
else
{
$file = "$PREFS->{gHomeDirectory}/" .
$cats[$pilot{$i}->{category}];
if (defined($pifile{$i}))
{
$fname = $pifile{$i};
$ret = "Update";
if ($fname !~ m|^$file/[^/]+$|)
{
# Changed Category! Delete in old location..
unlink($fname);
delete $piid{$fname};
delete $newsum{$fname};
$fname =~ s|^$PREFS->{"gHomeDirectory"}/||;
PilotMgr::msg("Delete File: $fname.");
$fname =~ s|^.*/||g;
mkdir($file, 0755) unless (-d $file);
if (-e "$file/$fname") {
$file = &mktemp($file);
} else {
$file .= "/$fname";
}
$fname = $file;
$ret = "New Category/Update";
} else {
$file = $fname;
}
} else {
mkdir($file, 0755) unless (-d $file);
$fname = &makeFilename($pilot{$i});
$fname =~ s/\n.*//g;
$fname =~ tr| '"<>()[]/;\n|____________|s; #'
$file = $fname = &mktemp(($a1=$file), $fname);
if (open(FD, ">$file"))
{
close(FD);
unlink($file);
} else {
# in case some weird character causes a filename prob
$file = $fname = &mktemp($a1);
}
$ret = "Create new";
}
$fname =~ s|^$PREFS->{"gHomeDirectory"}/||;
unless (open(FD, ">$file"))
{
PilotMgr::msg("$ret File: $fname.\n" .
"Error opening $file for write!!");
next;
}
print FD &neutralToFile($pilot{$i});
close(FD);
if ($PREFS->{"gOnlyAscii"} && ($ret eq "Create new"))
{
unless (&isPilotText($file))
{
PilotMgr::msg("Skipping non-textfile from pilot (" .
$cats[$pilot{$i}->{category}] . ", $i, $fname)");
unlink($file);
next;
}
}
if ($pilot{$i}->{"private"} and
$PREFS->{"privateHandler"} eq "Use permissions:" and
$PREFS->{"privatePerms"} > 0)
{
chmod oct($PREFS->{"privatePerms"}), $file;
}
PilotMgr::msg("$ret File: $fname.");
$ret = &cksum($file);
$ret = '' unless defined $ret;
if ($ret =~ /^(\d+)\s+(\d+)/)
{
$newsum{$file} = "$1 $2";
}
else
{
PilotMgr::msg("Sum Error: couldn't retrieve checksum ",
"for $fname, using zero sum. (sum='$ret')");
$newsum{$file} = "0 0";
}
$piid{$file} = $i;
$pifile{$i} = $file;
$updates .= "$file\n";
}
}
}
&cleanupPilot($dlp, $pilot_dbhandle)
unless ($PREFS->{"OnlyFilesToPilot"});
$pilot_dbhandle->close();
PilotMgr::msg("All files up to date.") if ($cnt == 0 && %newsum);
PilotMgr::msg("No Memo files found.") if ($cnt == 0 && !%newsum);
# Run post-update script
if ($PREFS->{"gUsePostUpdater"})
{
PilotMgr::status("Running post-update script", 0);
&runScript($dlp, $PREFS->{"gPostUpdater"}, "post update", $updates);
PilotMgr::status("Running post-update script", 100);
}
# Write back to DBFILE
unless (open(FD, ">$DBFILE"))
{
PilotMgr::msg("Error opening $DBFILE for write.");
return;
}
print FD $info->{"thisSyncDate"}, "\n";
foreach $file (keys(%newsum))
{
print FD "$newsum{$file} $file $piid{$file}\n";
}
close(FD);
}
##########################################################################
sub loadPrefs
{
my ($lines);
open(FD, "<$RCFILE") || return;
$lines = join('', <FD>);
close(FD);
eval $lines;
# For some reason, we need to reference $PREFS here
# or the preferences won't get loaded properly.
#
$PREFS;
}
sub savePrefs
{
my ($var);
$Data::Dumper::Purity = 1;
$Data::Dumper::Deepcopy = 1;
if (open(FD, ">$RCFILE"))
{
if (defined &Data::Dumper::Dumpxs)
{
print FD Data::Dumper->Dumpxs([$PREFS], ['PREFS']);
}
else
{
print FD Data::Dumper->Dump([$PREFS], ['PREFS']);
}
print FD "1;\n";
close(FD);
}
else
{
PilotMgr::msg("Unable to save preferences to $RCFILE!");
}
}
sub readDBFile
{
my (%sum, %id, %fi, $line, @lines);
my ($lastsync) = (0);
%sum = %id = %fi = ();
if (open(FD, "<$DBFILE"))
{
@lines = <FD>;
close(FD);
if ($lines[0] =~ /^(\d+)$/)
{
$lastsync = $1;
shift(@lines);
}
foreach $line (@lines)
{
if ($line =~ /^(\d+ \d+) (.+) (\d+)$/)
{
$sum{$2} = $1;
$id{$2} = $3;
$fi{$3} = $2;
}
}
}
return ({%sum}, {%id}, {%fi}, $lastsync);
}
sub checkFiles
{
my ($dlp, %oldsum) = @_;
my (%sum, $sum, $file, $dir, @list, @dirlist);
my ($skipStart, $skipEnd) = (quotemeta $PREFS->{'skipStart'},
quotemeta $PREFS->{'skipEnd'});
opendir DIR, $PREFS->{'gHomeDirectory'};
@dirlist = readdir DIR;
closedir DIR;
foreach $dir (@dirlist)
{
next if $dir =~ /^\.\.?$/ or not -d "$PREFS->{gHomeDirectory}/$dir";
opendir DIR, "$PREFS->{gHomeDirectory}/$dir";
@_ = readdir DIR;
closedir DIR;
foreach $file (@_)
{
next unless -f "$PREFS->{gHomeDirectory}/$dir/$file";
next if ($PREFS->{'useSkipStart'} and $file =~ /^$skipStart/);
next if ($PREFS->{'useSkipEnd'} and $file =~ /$skipEnd$/);
push(@list, "$PREFS->{gHomeDirectory}/$dir/$file");
}
}
my ($count, $count_max) = (0, scalar(@list));
PilotMgr::status("Reading File System Memos", 0);
foreach $file (@list)
{
unless ($count % &fake_ceil($count_max / 20))
{
PilotMgr::status("Reading File System Memos",
int(100 * $count / $count_max));
}
$dlp->tickle unless (++$count % 20);
if ($PREFS->{"gOnlyAscii"})
{
unless (&isPilotText($file))
{
my $fname = $file;
$fname =~ s|^$PREFS->{"gHomeDirectory"}/||;
PilotMgr::msg("Skipping non-textfile $fname.");
next;
}
}
$sum = &cksum($file);
$sum = '' unless defined $sum;
if ($sum =~ /^(\d+)\s+(\d+)/)
{
$sum{$file} = "$1 $2";
}
else
{
$sum{$file} = $oldsum{$file} if (defined $oldsum{$file});
$file =~ s|^.*/([^/]+/[^/]+)$|$1|;
PilotMgr::msg("Sum Error: couldn't retrieve checksum for $file, ",
"using old sum. (sum='$sum')");
}
}
PilotMgr::status("Reading File System Memos", 100);
return (%sum);
}
sub readAllMemos
{
my ($sock, $dbhandle) = @_;
my ($i, $record, $id, $count_max);
my (%db);
$i = 0;
PilotMgr::status("Reading Pilot Memos [full sync]", 0);
$count_max = $dbhandle->getRecords();
while (1)
{
$record = $dbhandle->getRecord($i);
last if (!defined($record));
unless ($i % &fake_ceil($count_max / 20))
{
PilotMgr::status("Reading Pilot Memos [full sync]",
int(100 * $i / $count_max));
}
$i++;
next if ($record->{"deleted"} or $record->{"archived"} or
$record->{"busy"} or
$record->{"secret"} && $PREFS->{"privateHandler"} eq "Skip");
$id = $record->{"id"};
$db{$id} = &pilotToNeutral($id, $record->{"category"}, $record);
}
PilotMgr::status("Reading Pilot Memos [full sync]", 100);
return(%db);
}
sub readChangedMemos
{
my ($sock, $dbhandle) = @_;
my ($i, $record, $id);
my (%db);
PilotMgr::status("Reading Pilot Memos [fast sync]", 0);
while (1)
{
$record = $dbhandle->getNextModRecord();
last if (!defined($record));
next if ($record->{"secret"} and
$PREFS->{"privateHandler"} eq "Skip");
$id = $record->{"id"};
if ($record->{"deleted"} or $record->{"archived"})
{
$db{$id} = "DELETED";
}
else
{
$db{$id} = &pilotToNeutral($id, $record->{"category"}, $record);
}
}
PilotMgr::status("Reading Pilot Memos [fast sync]", 100);
return(%db);
}
sub readMemosInCategory
{
my ($dbhandle, $categ, $current_recs) = @_;
my ($record, $id);
my (%db) = (%$current_recs);
while (1)
{
$record = $dbhandle->getNextRecord($categ);
last if (!defined($record));
$id = $record->{"id"};
next if (defined($db{$id}));
if ($record->{"deleted"} or $record->{"archived"})
{
$db{$id} = "DELETED";
}
else
{
$db{$id} = &pilotToNeutral($id, $record->{"category"}, $record);
}
}
return(%db);
}
sub recsDiffer
{
my ($a, $b) = @_;
my (%seen, $key);
foreach $key (keys %$a, keys %$b)
{
next if $seen{$key}++;
next if (&isSpecialSyncField($key));
return 1 unless (defined $a->{$key} and defined $b->{$key} and
$a->{$key} eq $b->{$key});
}
return 0;
}
sub matchRec
{
my ($pilot, $rec) = @_;
my ($pi);
foreach $pi (values(%$pilot))
{
return $pi->{pilot_id} unless (&recsDiffer($rec, $pi));
}
return 0;
}
sub writeMemo
{
my ($record, $dlp, $pilot_dbhandle) = @_;
my ($pi_rec, $id);
$record->{pilot_id} ||= 0;
$record->{category} ||= 0;
$pi_rec = &neutralToPilot($record, $pilot_dbhandle);
$pi_rec->{attr} ||= 0; # Why isn't this set?
$pi_rec->{category} ||= 0; # Why isn't this set?
$dlp->tickle;
$id = $pilot_dbhandle->setRecord($pi_rec);
return $id;
}
sub deleteRecord
{
my ($dlp, $pilot_dbhandle, $record_id) = @_;
my ($ret);
$ret = $pilot_dbhandle->deleteRecord($record_id);
return ($ret);
}
sub cleanupPilot
{
my ($dlp, $pilot_dbhandle) = @_;
$pilot_dbhandle->purge();
$pilot_dbhandle->resetFlags();
}
sub fileMerge
{
my ($dlp, $text1, $text2) = @_;
my ($file1, $file2, $outfile, $outtext);
$file1 = &mktemp("/tmp", "File.txt");
open(FD, ">$file1") || return;
print FD $text1;
close(FD);
$file2 = &mktemp("/tmp", "Pilot.txt");
open(FD, ">$file2") || do { unlink($file1); return };
print FD $text2;
close(FD);
$outfile = &mktemp("/tmp", "Merge.txt");
$dlp->watchdog(20);
system "filemerge $file1 $file2 $outfile";
$dlp->watchdog(0);
unlink($file1);
unlink($file2);
open(FD, "<$outfile") || return;
$outtext = join('', <FD>);
close(FD);
unlink($outfile);
return $outtext;
}
sub runScript
{
my ($dlp, $cmdline, $name, $input_text) = @_;
my ($script, $args, $bg, $tmp, $tmpfile);
$bg = '&' if ($cmdline =~ s/\s*&$//);
($script, $args) = split(' ', $cmdline, 2);
$name .= " " if ($name);
if (-x $script)
{
PilotMgr::msg("Running ${name}script.");
$dlp->watchdog(20);
if ($input_text)
{
$tmpfile = &mktemp("/tmp");
open(FD, ">$tmpfile") || ($tmpfile = "");
print FD $input_text;
close(FD);
}
if (defined $tmpfile) {
system "$script $args < $tmpfile $bg";
} else {
system "$script $args < /dev/null $bg";
}
unlink($tmpfile) if (defined $tmpfile);
$dlp->watchdog(0);
} else {
PilotMgr::msg("Error running ${name}script.");
}
}
sub mktemp
{
my ($dir, $basename) = @_;
my ($fname, $fext) = ("Memo0000", "");
$basename ||= "";
return ("$dir/$basename") if ($basename && (! -e "$dir/$basename"));
$fext = $1 if ($basename =~ /(\.\w+)$/);
$fext ||= ".txt";
while (1)
{
return ("$dir/$fname$fext") if (! -e "$dir/$fname$fext");
$fname++;
}
}
sub fake_ceil
{
my ($val) = (int($_[0]));
return 1 if ($val == 0);
return $val;
}
sub isPilotText
{
open(FD, "<$_[0]") or return 0;
while (read(FD, $_, 4096))
{
close FD, return 0 if /[^\x09-\x7F\x83\x91-\x95\x99\xA1-\xFF]/;
}
close FD;
return 1;
}
sub cksum
{
my ($fn) = @_;
my ($checksum, $blocks) = (0);
if (-f $fn and open(IN, "<$fn"))
{
while (read(IN, $_, 4096))
{
$checksum = ($checksum + unpack("%32C*", $_)) % 65535;
}
close IN;
$checksum = 65535 if ($checksum == 0);
$blocks = int(((-s $fn) + 511)/512);
return "$checksum $blocks";
} else {
warn "Sum error for $fn: $!";
return "0 0";
}
}
##########################################################################
sub pilotToNeutral
{
my ($id, $category, $pi_rec) = @_;
my ($record);
$record = {
pilot_id => $id,
category => $category,
};
#Copy all relevant fields here:
$record->{text} = $pi_rec->{text};
$record->{private} = $pi_rec->{secret} if (exists $pi_rec->{secret});
return($record);
}
sub neutralToPilot
{
my ($record, $db_handle) = @_;
my ($pi_rec) = ($db_handle->newRecord());
$pi_rec->{id} = $record->{pilot_id};
$pi_rec->{category} = $record->{category};
#Copy all relevant fields here:
$pi_rec->{text} = $record->{text};
$pi_rec->{secret} = $record->{private} if (exists $record->{private});
return $pi_rec;
}
sub fileToNeutral
{
my ($id, $category, $filetext) = @_;
my ($record);
$record = { 'private' => '' };
$record->{pilot_id} = $id if ($id);
$record->{category} = $category if (length($category) > 0);
#Parse file and fill all relevant fields here:
$record->{text} = $filetext;
#XXX set private to 1 if prefs is in attr mode and attrs match..
# if this is added, remove "private" from isSpecialSyncField and
# add ability to change perms on an existing file... (fully sync this field)
return($record);
}
sub neutralToFile
{
my ($record) = @_;
my ($filetext) = ("");
#Pull out record fields and encode into filetext:
$filetext = $record->{text};
return($filetext);
}
sub isSpecialSyncField
{
my ($field) = @_;
# Fields that should NOT be compared between Pilot and file.
# (ie info stored only on one side or the other, but not both)
# "pilot_id" should always be one of these fields.
# return ($field eq "pilot_id" || $field eq "createdate");
return ($field eq "pilot_id" or $field eq "private");
}
sub mergeRecs
{
my ($dlp, $record, $pirec) = @_;
my ($ret);
#Merge method. Modify fields in $record to get final result.
$ret = "";
if ($PREFS->{"gUseFilemerge"})
{
PilotMgr::msg("Running filemerge..");
$ret = &fileMerge($dlp, $record->{text}, $pirec->{text});
PilotMgr::msg("Using filemerged text.") if ($ret);
}
unless ($ret)
{
PilotMgr::msg("Concatenating both versions! Merge " .
"changes before your next hotsync!");
$ret = $record->{text} .
"\n--- ^^ File ^^ === Version Separator === vv Pilot vv ---\n" .
$pirec->{text};
}
$record->{text} = $ret;
}
sub makeFilename
{
my ($record) = @_;
my ($filename) = ("");
#Make a potential filename from the given record:
if ($record->{text} =~ /^\s*<HTML>/i)
{
if ($record->{text} =~ /<TITLE\s*[^>]*>\s*(.*)<\/TITLE\s*[^>]*>/si)
{
# Try to use the title of HTML docs
$filename = substr($1, 0, 16);
}
elsif ($record->{text} =~ /(\s*<[^>]*>)*\s*([^<]*)\s*/si)
{
# Use first non-html text
$filename = substr($2, 0, 16);
}
$filename =~ s/\s+$//;
$filename =~ s/\s+/_/g;
$filename .= ".html" if (length($filename) > 0);
}
unless ($filename)
{
$filename = substr($record->{text}, 0, 16);
$filename =~ s/\n.*//g;
$filename =~ s/\s+$//;
$filename =~ s/^\s+//;
$filename =~ s/\s+/_/g;
$filename =~ s/^$/_/;
$filename .= ".txt";
}
return($filename);
}
1;
|