6 if (typeof foldersync ==
'undefined') {
33 foldersync.central.logEvent(
"sync-update",
34 "Update listeners", 5);
35 foldersync.sync._notify(this.crt.state,
this.crt.syncqueueobject);
37 this.crt.state =
null;
38 this.crt.syncqueueobject =
null;
40 foldersync.central.logEvent(
"sync-update",
41 "Update thread terminated " +
42 "unexpected:\n\n" + e, 1,
43 "chrome://foldersync/content/sync.js",
56 foldersync.central.logEvent(
"sync-getQueue",
57 "Get element from Queue", 5);
60 if (foldersync.sync._queue.length)
61 this.crt = foldersync.sync._queue.shift();
63 foldersync.central.logEvent(
"sync-getQueue",
64 "GetQueue thread terminated " +
65 "unexpected:\n\n" + e, 1,
66 "chrome://foldersync/content/sync.js",
80 foldersync.central.logEvent(
"sync-getProfile",
81 "Get Profile " + this.crt, 5);
83 this.crt = foldersync.preferences.getProfileByGUID(this.crt);
87 this.crt =
JSON.parse(
JSON.stringify(
this.crt));
90 var defTags = foldersync.preferences.getDefaultTags();
91 defTags =
JSON.parse(
JSON.stringify(defTags));
92 this.crt.defaulttags = defTags;
95 var fallbacks = foldersync.preferences.getFallbacks();
96 fallbacks =
JSON.parse(
JSON.stringify(fallbacks));
97 this.crt.fallbacks = fallbacks;
99 foldersync.central.logEvent(
"sync-getProfile",
100 "GetProfile thread terminated " +
101 "unexpected:\n\n" + e, 1,
102 "chrome://foldersync/content/sync.js",
126 foldersync.central.logEvent(
"sync-getItems",
127 "Get Items: " + this.crt, 5);
131 import(
"resource://app/jsmodules/sbProperties.jsm");
133 var
ios = Components.classes[
"@mozilla.org/network/io-service;1"].
134 getService(Components.interfaces.nsIIOService);
136 var playlists = this.crt;
139 for each (var guid
in playlists){
140 var pList = foldersync.central.getPlaylistByGUID(guid);
141 foldersync.central.logEvent(
"sync-getItems",
142 "Parse playlist " + pList.guid +
"\n" +
143 "Name: " + pList.name, 5);
145 var plEntry = {
name: pList.name, items: []};
147 for (var
i = 0;
i < pList.length;
i++){
149 var item = pList.getItemByIndex(
i);
153 path =
ios.newURI(decodeURI(item.getProperty(
154 SBProperties.contentURL)),
null,
null).
160 foldersync.central.logEvent(
"sync-getItems",
161 "Add item " + item.guid +
"\n" +
169 artist: item.getProperty(SBProperties.artistName),
170 title: item.getProperty(SBProperties.trackName),
171 album: item.getProperty(SBProperties.albumName),
172 genre: item.getProperty(SBProperties.genre),
173 rating: item.getProperty(SBProperties.rating),
174 tracknum: item.getProperty(SBProperties.trackNumber),
175 albumartist: item.getProperty(SBProperties.albumArtistName),
176 year: item.getProperty(SBProperties.year),
177 discnumber: item.getProperty(SBProperties.discNumber),
178 disccount: item.getProperty(SBProperties.totalDiscs),
179 producer: item.getProperty(SBProperties.producerName),
180 composer: item.getProperty(SBProperties.composerName),
181 duration: item.getProperty(SBProperties.duration),
186 entry.tags.coverpath =
ios.newURI(decodeURI(item.getProperty(
187 "http://songbirdnest.com/data/" +
188 "1.0#primaryImageURL")),
null,
189 null).QueryInterface(Components.
194 plEntry.items.push(entry);
198 this.crt.push(plEntry);
201 foldersync.central.logEvent(
"sync-getItems",
202 "GetItems thread terminated " +
203 "unexpected:\n\n" + e, 1,
204 "chrome://foldersync/content/sync.js",
232 foldersync.central.logEvent(
"sync-sync",
233 "Initialisate sync thread", 5);
234 this._thread = Components.classes[
"@mozilla.org/thread-manager;1"].
235 getService(Components.interfaces.nsIThreadManager).
238 Components.classes[
"@mozilla.org/thread-manager;1"].
239 getService(Components.interfaces.nsIThreadManager).
241 this._OS = foldersync.central.getOS();
243 foldersync.central.logEvent(
"sync-sync",
244 "Sync thread initialisation " +
245 "failed:\n\n" + e, 1,
246 "chrome://foldersync/content/sync.js",
254 foldersync.central.logEvent(
"sync-sync",
255 "Start sync thread", 5);
256 this._thread.dispatch(
this, Components.interfaces.nsIThread.
259 foldersync.central.logEvent(
"sync-sync",
260 "Starting sync thread failed:\n\n" + e,
262 "chrome://foldersync/content/sync.js",
268 ensureRunning:
function(){
276 isSyncing:
function(){
277 return this._running;
284 _notify:
function(state, syncqueueobject){
286 foldersync.central.logEvent(
"sync-sync",
287 "Notify listeners of new state", 5);
289 foldersync.sync._threads.update.crt.state = state;
290 foldersync.sync._threads.update.crt.
291 syncqueueobject = syncqueueobject;
293 this._mainthread.dispatch(foldersync.sync._threads.update,
294 Components.interfaces.nsIThread.
297 foldersync.central.logEvent(
"sync-sync",
298 "Starting update thread failed:\n\n" + e,
300 "chrome://foldersync/content/sync.js",
306 _getNext:
function(){
308 foldersync.central.logEvent(
"sync-sync",
309 "Get the next SyncQueueObject", 5);
311 this._mainthread.dispatch(foldersync.sync._threads.getQueue,
312 Components.interfaces.nsIThread.
314 return foldersync.sync._threads.getQueue.crt;
316 foldersync.central.logEvent(
"sync-sync",
317 "Starting getQueue thread failed:\n\n" +
319 "chrome://foldersync/content/sync.js",
327 _getProfile:
function(guid){
329 foldersync.central.logEvent(
"sync-sync",
330 "Get Profile " + guid, 5);
332 foldersync.sync._threads.getProfile.crt = guid;
334 this._mainthread.dispatch(foldersync.sync._threads.getProfile,
335 Components.interfaces.nsIThread.
337 return foldersync.sync._threads.getProfile.crt;
339 foldersync.central.logEvent(
"sync-sync",
340 "Starting getProfile thread failed:" +
342 "chrome://foldersync/content/sync.js",
351 _getItems:
function(guids){
353 foldersync.central.logEvent(
"sync-sync",
354 "Get Items from " + guids, 5);
356 foldersync.sync._threads.getItems.crt = guids;
358 this._mainthread.dispatch(foldersync.sync._threads.getItems,
359 Components.interfaces.nsIThread.
361 return foldersync.sync._threads.getItems.crt;
363 foldersync.central.logEvent(
"sync-sync",
364 "Starting getItems thread failed:\n\n" +
366 "chrome://foldersync/content/sync.js",
375 _enumFolder:
function(folder, cArray){
376 foldersync.central.logEvent(
"sync-sync",
"Enumerate '" + folder.path +
380 result.files = cArray ? (cArray.files ? cArray.files : []) : [];
381 result.folders = cArray ? (cArray.folders ? cArray.folders : []) : [];
385 entries = folder.directoryEntries;
387 foldersync.central.logEvent(
"sync-sync",
388 "Failed to access '" + folder.path +
390 "chrome://foldersync/content/sync.js",
395 while(entries.hasMoreElements())
397 var ent = entries.getNext();
398 ent.QueryInterface(Components.interfaces.nsIFile);
400 result.files.push(ent);
402 if (ent.isDirectory()){
403 result = this._enumFolder(ent, result);
404 result.folders.push(ent);
415 _ensureCharacters:
function(
string, profile){
416 var aString =
new String (
string);
419 var waitChar = profile.advanced.cutSpaces;
421 for (var
i = 0;
i < aString.length;
i++){
423 for each (var bChar
in profile.advanced.blockedChars)
424 if (aString[
i] == bChar)
427 rBuffer += profile.advanced.replaceChar;
431 if (profile.advanced.cutSpaces)
432 if (aString[
i] ==
" "){
440 rBuffer += aString[
i];
448 if (!profile.advanced.cutReplaced){
450 if (profile.advanced.cutSpaces){
453 for each (var c
in rBuffer)
474 _replaceTags:
function(crt, tags, playlist, profile){
478 var
artist = tags.artist ? tags.artist : profile.defaulttags.artist;
479 var title = tags.title ? tags.title : profile.defaulttags.title;
480 var album = tags.album ? tags.album : profile.defaulttags.album;
481 var albumartist = tags.albumartist ? tags.albumartist :
482 ( profile.fallbacks.albumartist ?
483 artist : profile.defaulttags.
485 var discnumber = tags.discnumber ? tags.discnumber :
486 profile.defaulttags.discnumber;
487 var composer = tags.composer ? tags.composer :
488 profile.defaulttags.composer;
489 var genre = tags.genre ? tags.genre : profile.defaulttags.genre;
490 var
rating = tags.rating ? tags.rating : profile.defaulttags.rating;
491 var
year = tags.year ? tags.year : profile.defaulttags.year;
492 var disccount = tags.disccount ? tags.disccount :
493 profile.defaulttags.disccount;
494 var producer = tags.producer ? tags.producer :
495 profile.defaulttags.producer;
496 var tracknum = tags.tracknum ? tags.tracknum :
497 profile.defaulttags.tracknumber;
498 while (tracknum.length < profile.structure.tnDigits){
499 tracknum =
"0" + tracknum;
502 result = result.replace(/%artist%/g, artist);
503 result = result.replace(/%title%/g, title);
504 result = result.replace(/%album%/g, album);
505 result = result.replace(/%albumartist%/g, albumartist);
506 result = result.replace(/%discnumber%/g, discnumber);
507 result = result.replace(/%composer%/g, composer);
508 result = result.replace(/%genre%/g, genre);
509 result = result.replace(/%rating%/g, rating);
510 result = result.replace(/%playlist%/g, playlist);
511 result = result.replace(/%year%/g, year);
512 result = result.replace(/%disccount%/g, disccount);
513 result = result.replace(/%producer%/g, producer);
514 result = result.replace(/%tracknumber%/g, tracknum);
516 return this._ensureCharacters(result, profile);
523 _updateTaskPoints:
function(
value, syncqueueobject){
524 this._crtPoints +=
value;
525 if ((this._crtPoints/this._maxPoints)-0.01 >=
526 (this._lstPoints/this._maxPoints)){
527 this._lstPoints = this._crtPoints;
529 event:
"status-update",
530 value: (this._crtPoints/this._maxPoints)*100
533 return syncqueueobject.cancel;
539 this._running =
true;
540 foldersync.central.logEvent(
"sync-sync",
541 "Sync thread started", 4);
543 var crtObject = this._getNext();
546 var crtSync = crtObject.sync;
548 foldersync.central.logEvent(
"sync-sync",
549 "Sync started: \n\n" +
550 "Target: " + crtSync.
551 targetFolder +
"\n" +
552 "Profile: " + crtSync.
553 profileGUID +
"\n", 4);
555 this._notify({
value:0,
event:
"started"}, crtObject);
558 var crtProfile = this._getProfile(crtSync.profileGUID);
561 foldersync.central.logEvent(
"sync-sync",
562 "Sync error:\n\n" +
"Profile " +
563 crtSync.profileGUID +
" is not " +
564 "avaiable, Sync cancelled.", 1,
565 "chrome://foldersync/content/" +
567 crtObject.cancel =
true;
568 this._notify({
value:0,
event:
"failed-noprofile"}, crtObject);
570 crtObject = this._getNext();
574 var tFolder = Components.classes[
"@mozilla.org/file/local;1"].
577 tFolder.initWithPath(crtSync.targetFolder);
579 foldersync.central.logEvent(
"sync-sync",
580 "Sync error:\n\n" +
"Folder '" +
581 crtSync.targetFolder +
"' is" +
582 "invalid. Sync cancelled.", 1,
583 "chrome://foldersync/content/" +
584 "sync.js", e.lineNumber);
585 this._notify({
value:0,
event:
"failed-invalid"}, crtObject);
587 crtObject = this._getNext();
590 if (!tFolder.exists()){
591 foldersync.central.logEvent(
"sync-sync",
592 "Sync error:\n\n" +
"Folder '" +
593 crtSync.targetFolder +
"' does" +
594 "not exist. Sync cancelled.", 1,
595 "chrome://foldersync/content/" +
597 this._notify({
value:0,
event:
"failed-invalid"}, crtObject);
599 crtObject = this._getNext();
604 var tFiles = this._enumFolder(tFolder);
605 var tFolders = tFiles.folders;
606 tFiles = tFiles.files;
609 var crtItems = this._getItems(crtSync.playlists);
611 foldersync.central.logEvent(
"sync-sync",
612 "Sync error:\n\n" +
"Could not get" +
613 "media items for playlists, " +
614 "Sync cancelled.", 1,
615 "chrome://foldersync/content/" +
617 this._notify({
value:0,
event:
"failed-noitems"}, crtObject);
619 crtObject = this._getNext();
624 if (crtProfile.playlists.isEnabled && crtProfile.playlists.isSorted){
626 var tagRankTmp2 =
null;
627 var tagRankTmp = crtProfile.playlists.sortingScheme.match(/^%[a-z]+(:[ad])?%(,%[a-z]+(:[ad])?%)*$/g);
630 foldersync.central.logEvent(
"sync-sync",
631 "Sync error:\n\n" +
"Bad sorting" +
633 "Sync cancelled.", 1,
634 "chrome://foldersync/content/" +
636 this._notify({
value:0,
event:
"failed-badsortingschema"}, crtObject);
638 crtObject = this._getNext();
641 tagRankTmp = crtProfile.playlists.sortingScheme.match(/%([a-z]+:?[ad]?)%/g);
642 for (var
i=0;
i<tagRankTmp.length;
i++){
643 tagRankTmp2 = tagRankTmp[
i].match(/^%([a-z]+):?([ad])?%$/);
644 if ((tagRankTmp2[2] ==
null) || (tagRankTmp2[2] ==
"a")){
645 tagRank.push({
name :
"%"+tagRankTmp2[1]+
"%", order : 1});
648 tagRank.push({
name :
"%"+tagRankTmp2[1]+
"%", order : -1});
652 var compStr =
function(a, b){
653 if (!a && !b)
return 0;
654 if (!a && b)
return -1;
655 if (!b && a)
return 1;
658 if (as == bs){
return 0;}
660 var max = as.length > bs.length ? as.length : bs.length;
661 while ((as[pos] == bs[pos]) && (pos < max)) {pos++}
662 var result = as.charCodeAt(pos) - bs.charCodeAt(pos);
664 return as.length - bs.length;
667 var compareItems =
function(a, b) {
669 for (var
i=0;
i<tagRank.length;
i++) {
670 switch (tagRank[
i].
name){
672 ret = compStr(a.tags.artist, b.tags.artist)*tagRank[
i].order;
675 ret = compStr(a.tags.title, b.tags.title)*tagRank[
i].order;
678 ret = compStr(a.tags.album, b.tags.album)*tagRank[
i].order;
681 ret = compStr(a.tags.genre, b.tags.genre)*tagRank[
i].order;
684 ret = compStr(a.tags.rating, b.tags.rating)*tagRank[
i].order;
686 case "%tracknumber%":
687 ret = ((a.tags.tracknum?a.tags.tracknum:0)-(b.tags.tracknum?b.tags.tracknum:0))*tagRank[
i].order;
690 ret = compStr(a.tags.playlist, b.tags.playlist)*tagRank[
i].order;
692 case "%albumartist%":
693 ret = compStr(a.tags.albumartist, b.tags.albumartist)*tagRank[
i].order;
696 ret = compStr(a.tags.year, b.tags.year)*tagRank[
i].order;
699 ret = ((a.tags.discnumber?a.tags.discnumber:0)-(b.tags.discnumber?b.tags.discnumber:0))*tagRank[
i].order;
702 ret = ((a.tags.disccount?a.tags.disccount:0)-(b.tags.disccount?b.tags.disccount:0))*tagRank[
i].order;
705 ret = compStr(a.tags.composer, b.tags.composer)*tagRank[
i].order;
708 ret = compStr(a.tags.producer, b.tags.producer)*tagRank[
i].order;
714 if (ret!=0)
return ret;
718 for each (var plEntry
in crtItems){
720 plEntry.items.sort(compareItems);
722 foldersync.central.logEvent(
"sync-sync",
723 "Sorting playlists failed:\n\n" +
725 "chrome://foldersync/content/sync.js",
735 if (crtProfile.playlists.isEnabled){
736 var relParts = crtProfile.playlists.toFolder.split(
"/");
737 var aFile = tFolder.clone();
738 for each (var part
in relParts){
745 plRel = aFile.leafName +
746 crtProfile.playlists.splitChar + plRel;
747 aFile = aFile.parent;
749 foldersync.central.logEvent(
"sync-sync",
750 "Relative path for " +
753 "No parent directory " +
754 "for '" + aFile.path +
"'",
755 1,
"chrome://foldersync/" +
762 plRel =
".." + crtProfile.playlists.splitChar +
765 foldersync.central.logEvent(
"sync-sync",
769 1,
"chrome://foldersync/" +
776 if (crtProfile.playlists.doRelativePoint)
777 plRel =
"." + crtProfile.playlists.splitChar + plRel;
779 foldersync.central.logEvent(
"sync-sync",
"Playlist's path " +
780 "prefix is '" + plRel +
"'", 5);
784 var failedFiles = [];
788 var deleteFiles = [];
792 for each (var pList
in crtItems){
793 foldersync.central.logEvent(
"sync-sync",
"Prepare playlist '" +
794 pList.name +
"'", 5);
797 if (crtProfile.playlists.isEnabled){
798 switch (crtProfile.playlists.format){
803 playlist =
"#EXTM3U\r\n";
808 for each (var song
in pList.items){
809 foldersync.central.logEvent(
"sync-sync",
"Prepare '" +
812 var crtFile = Components.classes[
"@mozilla.org/file/local;1"].
816 crtFile.initWithPath(song.path);
818 foldersync.central.logEvent(
"sync-sync",
819 "File '" + crtFile.path +
"' " +
820 "is invalid:\n\n" + e, 2,
821 "chrome://foldersync/content/" +
822 "sync.js", e.lineNumber);
826 if (!crtFile.exists()){
827 foldersync.central.logEvent(
"sync-sync",
828 "File '" + crtFile.path +
829 "' does not exist.", 2,
830 "chrome://foldersync/content/" +
836 var tSubFolder = tFolder.clone();
837 var tSubFolders = [];
838 var tName = crtFile.leafName;
839 if (crtProfile.structure.isEnabled){
841 var tParts = crtProfile.structure.schema.split(
"/");
842 for (var
i = 0;
i < tParts.length;
i++){
843 var cItem = this._replaceTags(tParts[
i], song.tags,
844 pList.name, crtProfile);
845 if (i != tParts.length - 1){
847 tSubFolder.append(cItem);
848 tSubFolders.push(cItem);
850 if (crtProfile.structure.doCovers &&
851 (tParts[i] == crtProfile.structure.coverSchema) &&
852 song.tags.coverpath){
854 var coverName = crtProfile.structure.coverFile;
855 var sCover = song.tags.coverpath.split(
".");
856 if (sCover.length > 1)
857 coverName +=
"." + sCover[sCover.length-1];
859 var coverF = tSubFolder.clone();
860 coverF.append(coverName);
862 var exists = coverF.exists();
864 for each (var
file in copyFiles){
865 if ((file.to == tSubFolder.path) &&
866 (file.name == coverName)){
873 var coverSF = Components.classes[
"@mozilla.org/" +
878 coverSF.initWithPath(song.tags.coverpath);
879 if (!coverSF.exists())
880 throw Components.Exception(song.tags.coverpath +
885 to: tSubFolder.clone(),
889 for each (var cf
in copyFiles)
890 if ((cf.from.path == copyFile.from.path) &&
891 (cf.to.path == copyFile.to.path) &&
892 (cf.name == copyFile.name))
895 foldersync.central.logEvent(
"sync-sync",
897 song.tags.coverpath +
903 to: tSubFolder.clone(),
909 foldersync.central.logEvent(
"sync-sync",
910 "Cover file '" + song.
911 tags.coverpath +
"' " +
912 "caused unexpected " +
913 "Problem:\n\n" + e, 1,
914 "chrome://foldersync/" +
919 keepFiles.push(coverF);
920 foldersync.central.logEvent(
"sync-sync",
"Cover " +
921 "exists already at '" +
922 coverF.path +
"'", 5);
929 var sName = crtFile.leafName.split(
".");
930 if (sName.length > 1){
931 tName +=
"." + sName[sName.length-1];
934 if (tName.length > crtProfile.advanced.fMaxLength) {
936 for (var z = 0; z < crtProfile.advanced.fMaxLength-22;
938 temp_name += tName[z];
940 temp_name += crtProfile.advanced.replaceChar;
941 for (var z = tName.length-20; z < tName.length; z++){
950 var tFile = tSubFolder.clone();
954 if (crtProfile.playlists.isEnabled){
957 for each (var part
in tSubFolders){
958 relPath += part + crtProfile.playlists.splitChar;
962 switch (crtProfile.playlists.format){
964 playlist +=
"\r\n#EXTINF:" +
965 Math.round(song.tags.duration / 1000000) +
966 "," + (song.tags.artist ? song.tags.artist +
968 (song.tags.title ? song.tags.title :
969 crtProfile.defaulttags.title) +
"\r\n";
971 playlist += relPath +
"\r\n";
978 if (crtProfile.flags.doUpdate){
982 if (((tFile.lastModifiedTime + 2000 >
983 crtFile.lastModifiedTime) &&
984 (tFile.lastModifiedTime - 2000 <
985 crtFile.lastModifiedTime))){
986 foldersync.central.logEvent(
"sync-sync",
"File '" +
987 tFile.path +
"' hasn't " +
988 "modifyed, won't copy it.",5);
989 keepFiles.push(tFile);
994 foldersync.central.logEvent(
"sync-sync",
"File '" +
995 tFile.path +
"' exists " +
996 "already, won't copy it.",5);
997 keepFiles.push(tFile);
1004 var copyFile = {from: crtFile, to: tSubFolder,
name: tName};
1006 for each (var cf
in copyFiles)
1007 if ((cf.from.path == copyFile.from.path) &&
1008 (cf.to.path == copyFile.to.path) &&
1009 (cf.name == copyFile.name))
1012 foldersync.central.logEvent(
"sync-sync",
"File '" +
1013 song.path +
"' will go to '" +
1014 tSubFolder.path +
"' with " +
1015 "name '" + tName +
"'", 5);
1016 copyFiles.push(copyFile);
1018 foldersync.central.logEvent(
"sync-sync",
"File '" +
1019 song.path +
"' already in " +
1020 "copy array to '" + tSubFolder.
1021 path +
"' with name '" +
1026 if (numEntries % 1000 == 0)
1027 this._notify({
value:0,
event:
"initing"}, crtObject);
1028 if (crtObject.cancel)
1032 if (crtProfile.playlists.isEnabled){
1034 switch (crtProfile.playlists.format){
1042 var pFile = plBase.clone();
1043 var pFileName = this._ensureCharacters(pList.name, crtProfile);
1044 pFile.append(pFileName +
"." + extension);
1045 foldersync.central.logEvent(
"sync-sync",
1046 "Write playlist '" + pFile.path +
1049 if (!pFile.exists()){
1050 pFile.create(Components.interfaces.nsIFile.
1051 NORMAL_FILE_TYPE, 0664);
1055 var foStream = Components.classes[
"@mozilla.org/network/" +
1056 "file-output-stream;1"].
1058 nsIFileOutputStream);
1059 foStream.init(pFile, 0x02 | 0x08 | 0x20, 0666, 0);
1060 var
converter = Components.classes[
"@mozilla.org/intl/" +
1061 "converter-output-" +
1064 nsIConverterOutputStream);
1065 converter.init(foStream, crtProfile.playlists.encoding,
1067 converter.writeString(playlist);
1071 keepFiles.push(pFile);
1073 failedFiles.push(
"[+] " + pFile.path);
1074 foldersync.central.logEvent(
"sync-sync",
1075 "Writing playlist failed:\n\n" +
1077 "chrome://foldersync/content/" +
1082 if (crtObject.cancel)
1088 var deleteNames = [];
1089 if (crtProfile.flags.doUpdate && (!crtProfile.flags.doDelete))
1090 for each (var
entry in copyFiles){
1091 var Entry = entry.to.clone();
1092 Entry.append(entry.name);
1093 var ePath = Entry.path;
1094 if (!crtProfile.advanced.compareCase)
1095 ePath = ePath.toUpperCase();
1096 deleteNames.push(ePath);
1099 if (crtProfile.flags.doDelete)
1100 for each (var entry
in keepFiles){
1101 var ePath = entry.path;
1102 if (!crtProfile.advanced.compareCase)
1103 ePath = ePath.toUpperCase();
1104 keepNames.push(ePath);
1106 var compStr =
function(a, b){
1111 if (as == bs){
return 0;}
1113 var max = as.length > bs.length ? as.length : bs.length;
1114 while ((as[pos] == bs[pos]) && (pos < max)) {pos++}
1115 var result = as.charCodeAt(pos) - bs.charCodeAt(pos);
1117 return as.length - bs.length;
1120 keepNames.sort(compStr);
1121 deleteNames.sort(compStr);
1123 var compFile =
function(a, b){
1128 if (!crtProfile.advanced.compareCase){
1129 as = as.toUpperCase();
1130 bs = bs.toUpperCase();
1132 return compStr(as, bs);
1134 tFiles.sort(compFile);
1138 for each (var
file in tFiles){
1141 if (numEntries % 1000 == 0)
1142 this._notify({
value:0,
event:
"initing"}, crtObject);
1143 if (crtObject.cancel)
1146 var shouldDelete =
false;
1147 var fPath = file.path;
1148 if (!crtProfile.advanced.compareCase)
1149 fPath = fPath.toUpperCase();
1151 if (crtProfile.flags.doDelete){
1152 while ((compStr(keepNames[kCur],fPath) < 0) &&
1153 (kCur < keepNames.length -1))
1155 if (keepNames[kCur] == fPath)
1156 shouldDelete =
false;
1158 shouldDelete =
true;
1161 while ((compStr(deleteNames[dCur],fPath) < 0) &&
1162 (dCur < deleteNames.length -1))
1164 if (deleteNames[dCur] == fPath)
1165 shouldDelete =
true;
1167 foldersync.central.logEvent(
"sync-sync",
1168 "File '" + file.path +
"' " +
1169 (shouldDelete ?
"will " :
"won't ") +
1172 deleteFiles.push(file);
1176 foldersync.central.logEvent(
"sync-sync",
1177 "Got all information, start sync.", 4);
1178 this._notify({
value:0,
event:
"started-sync"}, crtObject);
1189 this._maxPoints = deleteFiles.length * 10 +
1190 copyFiles.length * 50 +
1191 (crtProfile.flags.doDelete ?
1192 tFolders.length * 1 : 0);
1193 this._crtPoints = 0;
1194 this._lstPoints = 0;
1197 if (!crtObject.cancel)
1198 for each (var file
in deleteFiles){
1200 foldersync.central.logEvent(
"sync-sync",
1201 "Delete '" + file.path +
"'", 5);
1204 failedFiles.push(
"[-] " + file.path);
1205 foldersync.central.logEvent(
"sync-sync",
1206 "Could not delete file '" +
1207 file.path +
"':\n\n" +
1209 "chrome://foldersync/content/" +
1210 "sync.js", e.lineNumber);
1212 if (this._updateTaskPoints(10,crtObject))
1217 if (!crtObject.cancel)
1218 if (crtProfile.flags.doDelete){
1219 for each (var folder
in tFolders){
1222 if (!folder.directoryEntries.hasMoreElements())
1223 folder.remove(
false);
1225 failedFiles.push(
"[-] " + folder.path);
1226 foldersync.central.logEvent(
"sync-sync",
1227 "Failed to delete " +
1228 "empty folder '" + folder.
1229 path +
"':\n\n" + e, 1,
1230 "chrome://foldersync/" +
1234 if (this._updateTaskPoints(1,crtObject))
1240 if (!crtObject.cancel)
1241 for each (var entry
in copyFiles){
1243 foldersync.central.logEvent(
"sync-sync",
1244 "Copy '" + entry.from.path +
1245 "' to '" + entry.to.path +
"' " +
1246 "with the name '" + entry.name +
1248 entry.from.copyTo(entry.to, entry.name);
1250 if (this._OS !=
"Win32"){
1251 var tFile = entry.to.clone();
1252 tFile.append(entry.name);
1253 tFile.lastModifiedTime = entry.from.lastModifiedTime;
1256 failedFiles.push(
"[+] " + entry.from.path +
" > " +
1257 entry.to.path +
" (" + entry.name +
")");
1258 foldersync.central.logEvent(
"sync-sync",
1259 "Could not copy file '" +
1260 entry.from.path +
"' to '" +
1261 entry.to.path +
"':\n\n" +
1263 "chrome://foldersync/content/" +
1264 "sync.js", e.lineNumber);
1266 if (this._updateTaskPoints(50,crtObject))
1271 if ((!crtObject.cancel) && (crtProfile.flags.doRockbox))
1272 foldersync.rockbox.doSync(tFolder.path);
1275 if (crtObject.cancel){
1276 foldersync.central.logEvent(
"sync-sync",
1277 "Sync cancelled \n\n" +
1278 "Target: " + crtSync.
1279 targetFolder +
"\n" +
1280 "Profile: " + crtSync.
1281 profileGUID +
"\n", 4);
1283 value:(this._crtPoints/this._maxPoints)*100,
1288 if (failedFiles.length == 0) {
1289 foldersync.central.logEvent(
"sync-sync",
1290 "Sync completed: \n\n" +
1291 "Target: " + crtSync.targetFolder +
1293 crtSync.profileGUID +
"\n", 4);
1295 this._notify({
value:100,
event:
"completed"}, crtObject);
1297 foldersync.central.logEvent(
"sync-sync",
1298 "Sync completed with errors: " +
1299 "\n\nTarget: " + crtSync.
1300 targetFolder +
"\nProfile: " +
1301 crtSync.profileGUID +
"\n", 4);
1305 event:
"completed-errors",
1311 crtObject = this._getNext();
1313 this._running =
false;
1314 foldersync.central.logEvent(
"sync-sync",
1315 "Sync thread stopped", 4);
1317 this._running =
false;
1318 this._notify({
event:
"fatal"}, {
sync:{}});
1319 foldersync.central.logEvent(
"sync-sync",
1320 "Sync thread terminated " +
1321 "unexpected:\n\n" + e, 1,
1322 "chrome://foldersync/content/sync.js",
1333 _notify:
function(state, syncqueueobject){
1335 foldersync.central.logEvent(
"sync",
1336 "Update listeners:\n\n" +
1337 "State: " + state.event +
"\n" +
1338 " " + state.value +
"\n" +
1339 "Cancelled: " + syncqueueobject.
1341 "GUID:" + syncqueueobject.guid +
"\n" +
1342 "Target: " + syncqueueobject.
1343 sync.targetFolder +
"\n" +
1344 "Profile: " + syncqueueobject.
1345 sync.profileGUID, 5);
1346 for each (var
listener in foldersync.sync._listeners){
1350 foldersync.central.logEvent(
"sync",
1351 "Wasn't able to notify listener '" +
1352 listener +
"':\n\n" + e, 3,
1353 "chrome://foldersync/content/" +
1354 "sync.js", e.lineNumber);
1358 foldersync.central.logEvent(
"sync",
1359 "Listener update terminated " +
1360 "unexpected:\n\n" + e, 1,
1361 "chrome://foldersync/content/sync.js",
1368 foldersync.central.logEvent(
"sync",
"Sync controller " +
1369 "initialisation started.", 5);
1372 this._listeners = [];
1374 foldersync.central.logEvent(
"sync",
"Sync controller started.", 4);
1378 foldersync.central.logEvent(
"sync",
"Sync controller " +
1379 "shutdown started.", 5);
1380 foldersync.central.logEvent(
"sync",
"Sync controller stopped.", 4);
1388 generateSync:
function(folder, profile, plists){
1391 targetFolder: folder,
1392 profileGUID: profile,
1400 generateSyncQueueObject:
function(
sync){
1404 guid: Components.classes[
"@mozilla.org/uuid-generator;1"].
1405 getService(Components.interfaces.nsIUUIDGenerator).generateUUID().
1414 addToQueue:
function(
object){
1416 foldersync.central.logEvent(
"sync",
1417 "Append SyncQueueObject:\n\n" +
1418 "GUID:" +
object.guid +
1419 "\nTarget: " +
object.
sync.targetFolder +
1420 "\nProfile: " +
object.sync.profileGUID, 4);
1421 this.
_queue.push(
object);
1424 foldersync.central.logEvent(
"sync",
1425 "Adding sync object to queue failed:\n\n" +
1427 "chrome://foldersync/content/sync.js",
1435 removeFromQueue:
function(
object){
1437 foldersync.central.logEvent(
"sync",
1438 "Remove SyncQueueObject:\n\n" +
1439 "GUID:" +
object.guid +
1440 "\nTarget: " +
object.
sync.targetFolder +
1441 "\nProfile: " +
object.sync.profileGUID, 4);
1442 var foundindex = -1;
1443 for (var
i = 0;
i < this.
_queue.length;
i++){
1444 if (this.
_queue[
i].guid ==
object.guid){
1449 if (foundindex != -1){
1450 this.
_queue.splice(foundindex,1);
1451 this._notify({
value: 0,
event:
"removed"},
object);
1453 foldersync.central.logEvent(
"sync",
1454 "Removing sync object from queue failed:" +
1455 "\n\nObject is not registered." + e, 2,
1456 "chrome://foldersync/content/sync.js");
1459 foldersync.central.logEvent(
"sync",
1460 "Removing sync object from queue failed:" +
1462 "chrome://foldersync/content/sync.js",
1468 ensureQueueRunning:
function(){
1469 this._threads.sync.ensureRunning();
1473 isSyncing:
function(){
1474 return this._threads.sync.isSyncing();
1480 performSync:
function(
sync){
1482 var so = this.generateSyncQueueObject(
sync);
1483 var result = so.guid;
1484 this.addToQueue(so);
1485 this.ensureQueueRunning();
1488 foldersync.central.logEvent(
"sync",
1489 "Preparing queue for sync failed:\n\n" +
1491 "chrome://foldersync/content/sync.js",
1503 getPFormats:
function(){
1505 {
name:
"playlistformat.m3u", internalName:
"m3u" },
1506 {
name:
"playlistformat.m3uEx", internalName:
"m3uEx" },
1520 foldersync.central.logEvent(
"sync",
1521 "Append listener:\n\n" +
1525 foldersync.central.logEvent(
"sync",
1526 "Adding listener to list failed:\n\n" +
1528 "chrome://foldersync/content/sync.js",
1536 removeListener:
function(
listener){
1538 foldersync.central.logEvent(
"sync",
1539 "Remove listener:\n\n" +
1541 var removed =
false;
1543 for (var
i = 0;
i < this._listeners.length;
i++){
1545 foldersync.central.logEvent(
"sync",
1546 "Removed listener:\n\n" +
1547 this._listeners[
i] +
"\n" +
1549 this._listeners.splice(
i,1);
1555 foldersync.central.logEvent(
"sync",
1556 "Removing listener from list failed:\n\n" +
1558 "is no registered listener.", 2,
1559 "chrome://foldersync/content/sync.js");
1561 foldersync.central.logEvent(
"sync",
1562 "Removing listener from list failed:\n\n" +
1564 "chrome://foldersync/content/sync.js",
1578 generateErrorMessage:
function(state){
1580 if (state.event.split(
"failed-").length > 1){
1582 result.error = foldersync.central.getLocaleString(
"status.failed");
1583 switch (state.event){
1584 case "failed-noprofile":
1585 result.message = foldersync.central.getLocaleString(
"error.profile");
1587 case "failed-invalid":
1588 result.message = foldersync.central.getLocaleString(
"error.invalid");
1590 case "failed-noitems":
1591 result.message = foldersync.central.getLocaleString(
"error.noitems");
1593 case "failed-badsortingschema":
1594 result.message = foldersync.central.getLocaleString(
"error.badsortingschema");
1597 result.message =
null;
1599 result.fatal =
true;
1601 if (state.event ==
"completed-errors"){
1603 result.error = foldersync.central.getLocaleString(
"status.errors");
1604 result.message = foldersync.central.getLocaleString(
"error.some") +
"\n";
1605 result.message += state.errors.join(
"\n");
1606 result.fatal =
false;
1608 if (state.event ==
"fatal"){
1610 result.error = foldersync.central.getLocaleString(
"status.failed");
1611 result.message =
"";
1612 result.fatal =
true;
1618 getQueue:
function(){
1620 return JSON.parse(
JSON.stringify(
this._queue));
GeneratorThread currentThread
dataSBHighestRatedArtists SBProperties rating
sbOSDControlService prototype QueryInterface
getService(Ci.sbIFaceplateManager)
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird SBProperties artist
sbDeviceFirmwareAutoCheckForUpdate prototype _queue
sbDeviceFirmwareAutoCheckForUpdate prototype interfaces
function onUnload()
onUnload - called when the cover preview window unloads.
_getSelectedPageStyle s i