27 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
28 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
29 Components.utils.import(
"resource://app/jsmodules/sbLocalDatabaseMigrationUtils.jsm");
30 Components.utils.import(
"resource://app/jsmodules/SBJobUtils.jsm");
32 const Cc = Components.classes;
33 const Ci = Components.interfaces;
34 const Cr = Components.results;
37 dump(
"----++++----++++sbLibraryMigration " +
40 "\n----++++----++++\n");
45 SBLocalDatabaseMigrationUtils.BaseMigrationHandler.call(
this);
47 this.fromVersion = 11;
49 this.versionString = this.fromVersion +
" to " +
58 __proto__: SBLocalDatabaseMigrationUtils.BaseMigrationHandler.prototype,
59 classDescription:
'Songbird Migration Handler for converting utf16 to utf8 storage.',
60 classID: Components.ID(
"{E313D2F1-D1BE-4683-963F-5F43C5245C6C}"),
61 contractID: SBLocalDatabaseMigrationUtils.baseHandlerContractID +
"utf16 to utf8",
66 migrate:
function sbLibraryMigration_migrate(aLibrary) {
68 this._databaseGUID = aLibrary.databaseGuid;
69 this._databaseLocation = aLibrary.databaseLocation;
71 dump(
"Migrating " + this._databaseLocation.spec +
this._databaseGUID +
"\n");
73 this._databaseLocation.QueryInterface(
Ci.nsIFileURL).file;
74 var dbEngine =
Cc[
"@songbirdnest.com/Songbird/DatabaseEngine;1"]
75 .getService(
Ci.sbIDatabaseEngine);
78 var oldLibDumpFile = dbParentDir.clone();
79 oldLibDumpFile.append(this._databaseGUID +
".txt");
80 if (oldLibDumpFile.exists()) {
81 oldLibDumpFile.remove(
false);
83 oldLibDumpFile.create(
Ci.nsIFile.NORMAL_FILE_TYPE, 0777);
85 dbEngine.dumpDatabase(this._databaseGUID, oldLibDumpFile);
88 dbEngine.closeDatabase(this._databaseGUID);
91 var oldLibraryFile = dbParentDir.clone();
92 oldLibraryFile.append(this._databaseGUID +
".db");
95 var tempOldLibFile = dbParentDir.clone();
96 tempOldLibFile.append(
"old_" + oldLibraryFile.leafName);
97 if (tempOldLibFile.exists()) {
98 tempOldLibFile.remove(
false);
100 oldLibraryFile.moveTo(oldLibraryFile.parent, tempOldLibFile.leafName);
102 var query = this._createQuery();
103 query.addQuery(
"begin");
104 this._createLibrary(query);
107 query.addQuery(
"drop table if exists media_items");
108 query.addQuery(
"drop table if exists media_list_types");
109 query.addQuery(
"drop table if exists properties");
110 query.addQuery(
"drop table if exists resource_properties");
111 query.addQuery(
"drop table if exists library_metadata");
112 query.addQuery(
"drop table if exists simple_media_lists");
113 query.addQuery(
"drop table if exists library_media_item");
114 query.addQuery(
"drop table if exists resource_properties_fts");
121 var fileInputStream =
Cc[
"@mozilla.org/network/file-input-stream;1"]
122 .createInstance(
Ci.nsIFileInputStream);
123 fileInputStream.init(oldLibDumpFile, 1, 0, 0);
125 var inputStream =
Cc[
"@mozilla.org/intl/converter-input-stream;1"]
126 .createInstance(
Ci.nsIConverterInputStream);
127 inputStream.init(fileInputStream,
"UTF-8", 16384,
128 Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
129 inputStream = inputStream.QueryInterface(
Ci.nsIUnicharLineInputStream);
132 var curQueryStr =
"";
135 cont = inputStream.readLine(curLine);
136 curQueryStr += curLine.value;
139 if (curQueryStr.charAt(curQueryStr.length - 1) ==
";") {
142 if (!curQueryStr.match(
"INSERT INTO sqlite_master.*resource_properties_fts_all")) {
143 query.addQuery(curQueryStr);
151 query.addQuery(
"update library_metadata set value = '"
152 + this.toVersion +
"' where name = 'version'");
153 query.addQuery(
"commit");
156 query.setAsyncQuery(
true);
157 query.execute(retval);
158 dump(
"Database execute\n");
159 var sip =
Cc[
"@mozilla.org/supports-interface-pointer;1"]
160 .createInstance(
Ci.nsISupportsInterfacePointer);
164 this._titleText =
"Library Migration Helper";
165 this._statusText =
"Converting Database Format...";
166 this.migrationQuery = query;
168 this.startNotificationTimer();
169 SBJobUtils.showProgressDialog(sip.data,
null, 0);
170 this.stopNotificationTimer();
172 tempOldLibFile.remove(
false);
173 oldLibDumpFile.remove(
false);
176 dump(
"Exception occured: " + e);
181 _createQuery:
function sbLibraryMigration_createQuery() {
182 var query =
Cc[
"@songbirdnest.com/Songbird/DatabaseQuery;1"]
183 .createInstance(
Ci.sbIDatabaseQuery);
184 query.databaseLocation = this._databaseLocation;
185 query.setDatabaseGUID(this._databaseGUID);
189 _createLibrary :
function sbLibraryMigration_createLibrary(query) {
193 var
ioService = Components.classes[
"@mozilla.org/network/io-service;1"]
194 .getService(Components.interfaces.nsIIOService);
196 var schemaURI = ioService.newURI(
"chrome://songbird/content/library/localdatabase/schema.sql",
null,
null);
197 var channel = ioService.newChannelFromURI(schemaURI);
198 var stream = channel.open();
200 var converterStream = Components.classes[
"@mozilla.org/intl/converter-input-stream;1"]
201 .createInstance(Components.interfaces.nsIConverterInputStream);
203 converterStream.init(stream,
206 Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
210 var bytesRead = converterStream.readString(0xFFFFFFFF, result);
212 while (bytesRead > 0) {
213 response += result.value;
214 bytesRead = converterStream.readString(0xFFFFFFFF, result);
217 converterStream.close();
220 const colonNewline =
";\n";
222 var posEnd = response.indexOf(colonNewline);
223 while (posEnd >= 0) {
224 query.addQuery(response.substring(posStart, posEnd));
225 posStart = posEnd + 2;
226 posEnd = response.indexOf(colonNewline, posStart);
230 dump(
"Exception: " + e);
240 return XPCOMUtils.generateModule([
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function sbLibraryMigration()
sbDeviceFirmwareAutoCheckForUpdate prototype classID
function NSGetModule(compMgr, fileSpec)