6 if (typeof foldersync ==
'undefined') {
42 var
TAG = {
"Album":1,
"Title":3,
"PlayCount":14,
"Rating":15,
"Flags":20 };
43 var
FLAG = {
"Deleted":1 };
45 foldersync.rockbox = {
49 doSync:
function(
path){
50 foldersync.central.logEvent(
"Rockbox",
"Sync started.", 4);
53 var
Cc = Components.classes;
54 var
Ci = Components.interfaces;
56 foldersync.central.logEvent(
"Rockbox",
"mainLibrary: "+songlib, 5);
57 var rockpath = this._findpath(
path);
61 var idxdb = this._fopen(rockpath+
"/database_idx.tcd");
63 foldersync.central.logEvent(
"Rockbox",
"idx database not found.", 1,
64 "chrome://foldersync/content/rockbox.js");
67 var adb = this._fopen(rockpath+
"/database_1.tcd");
69 foldersync.central.logEvent(
"Rockbox",
"album database (1) not found.",
71 "chrome://foldersync/content/rockbox.js");
75 var tdb = this._fopen(rockpath+
"/database_3.tcd");
77 foldersync.central.logEvent(
"Rockbox",
"title database (3) not found.",
79 "chrome://foldersync/content/rockbox.js");
80 adb.fclose(); idxdb.fclose();
85 idxhdr[
i] = this._swapi(idxdb.fgeti());
88 if(idxhdr[0] != DB_VERSION)
89 foldersync.central.logEvent(
"Rockbox",
"Incompatible file version.",
91 "chrome://foldersync/content/rockbox.js");
94 while( idxdb.available() >= TAG_COUNT*4 ) {
97 idxtags[
i] = this._swapi(idxdb.fgeti());
98 if( (idxtags[TAG.Flags] & FLAG.Deleted) != 0 )
100 adb.fseek(DB_PREFIX + idxtags[TAG.Album]);
101 var album = adb.fgets();
102 tdb.fseek(DB_PREFIX + idxtags[TAG.Title]);
103 var title = tdb.fgets();
108 if( idxtags[TAG.PlayCount] > 0 ) {
109 var cnv = Cc[
'@mozilla.org/intl/scriptableunicodeconverter'].
111 cnv.charset =
"UTF-8";
112 album = cnv.ConvertToUnicode(album); cnv.Finish();
113 title = cnv.ConvertToUnicode(title); cnv.Finish();
114 foldersync.central.logEvent(
"Rockbox", album +
":" + title +
115 " [" + idxtags[TAG.PlayCount] +
118 var
key = Cc[
"@songbirdnest.com/Songbird/Properties/" +
119 "MutablePropertyArray;1"].
121 key.appendProperty(SBProperties.albumName, album);
122 key.appendProperty(SBProperties.trackName, title);
124 var item = songlib.getItemsByProperties(key);
126 foldersync.central.logEvent(
"Rockbox",
"Missing: " +
127 album +
":" + title +
" [" +
128 idxtags[TAG.PlayCount] +
"]",
129 3,
"chrome://foldersync/" +
130 "content/rockbox.js");
134 if(item.length == 1) {
136 var media = item.enumerate().getNext();
137 media.setProperty(SBProperties.playCount,
138 Number(media.getProperty(SBProperties.
140 idxtags[TAG.PlayCount]);
141 var
pos = idxdb.ftell();
142 idxdb.fseek( pos-( TAG_COUNT - TAG.PlayCount )*4 );
145 if(idxtags[TAG.Rating] != 0)
147 media.setProperty(SBProperties.rating,
148 idxtags[TAG.Rating]/2);
156 foldersync.central.logEvent(
"Rockbox",
"Sync finished.", 4);
159 _findpath:
function(
path) {
160 var
path = path +
"/";
161 var chk = Components.classes[
"@mozilla.org/file/local;1"].
163 while(path.length > 0) {
164 chk.initWithPath(path+
".rockbox");
165 foldersync.central.logEvent(
"Rockbox",
"Chk:"+chk.path, 5);
168 path = (path.split(/(\/)/).slice(0, -3).join(
""));
174 return (
i>>>24 | (
i>>>8 & 0xFF00) | (
i<<8 & 0xFF0000) |
i<<24 );
177 _fopen:
function(filename) {
179 var f = Components.classes[
"@mozilla.org/file/local;1"].
181 f.initWithPath(filename);
185 var is = Components.classes[
"@mozilla.org/network/" +
186 "file-input-stream;1"].
189 is.init(f, 0x04, -1,
null);
190 is.QueryInterface(Components.interfaces.nsISeekableStream);
192 var bis = Components.classes[
"@mozilla.org/binaryinputstream;1"].
194 nsIBinaryInputStream);
195 bis.setInputStream(is);
197 var
os = Components.classes[
"@mozilla.org/network/" +
198 "file-output-stream;1"].
200 nsIFileOutputStream);
201 os.init(f, 0x04, -1,
null);
202 os.QueryInterface(Components.interfaces.nsISeekableStream);
204 var bos = Components.classes[
"@mozilla.org/binaryoutputstream;1"].
206 nsIBinaryOutputStream);
207 bos.setOutputStream(os);
209 foldersync.central.logEvent(
"Rockbox",
"File exception:\n\n" + e, 1,
210 "chrome://foldersync/content/rockbox.js",
216 "bis": bis,
"bos": bos,
217 "available":
function() {
return this.is.available(); },
218 "fclose":
function() { this.bis.close(); this.is.close(); this.bos.close(); this.os.close(); },
219 "ftell":
function() {
return this.is.tell(); },
220 "fseek":
function(
pos) { this.is.seek(0,pos); this.os.seek(0,pos); },
221 "fgetc":
function() {
return this.bis.read8(); },
222 "fgeti":
function() {
return this.bis.read32(); },
223 "fgets":
function() { rs=
"";
while((rc=this.bis.read8())!=0){rs=rs+
String.fromCharCode(rc);}
return rs; },
224 "fputi":
function(
i) { this.bos.write32(
i); },
getService(Ci.sbIFaceplateManager)
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird SBProperties playCount
Javascript wrappers for common library tasks.
_getSelectedPageStyle s i