| 340 | | var newDir = this._newScriptDir; |
|---|
| 341 | | if (newDir.exists()) return newDir; |
|---|
| 342 | | |
|---|
| 343 | | var oldDir = this._oldScriptDir; |
|---|
| 344 | | if (oldDir.exists()) return oldDir; |
|---|
| 345 | | |
|---|
| 346 | | // if we called this function, we want a script dir. |
|---|
| 347 | | // but, at this branch, neither the old nor new exists, so create one |
|---|
| 348 | | newDir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); |
|---|
| 349 | | |
|---|
| 350 | | var defaultConfigFile = getContentDir(); |
|---|
| 351 | | defaultConfigFile.append("default-config.xml"); |
|---|
| 352 | | |
|---|
| 353 | | defaultConfigFile.copyTo(newDir, "config.xml"); |
|---|
| 354 | | defaultConfigFile.permissions = 0644; |
|---|
| 355 | | |
|---|
| 356 | | return newDir; |
|---|
| 357 | | }, |
|---|
| 358 | | |
|---|
| 359 | | get _newScriptDir() { |
|---|
| 367 | | get _oldScriptDir() { |
|---|
| 368 | | var file = getContentDir(); |
|---|
| 369 | | file.append("scripts"); |
|---|
| 370 | | return file; |
|---|
| | 345 | /** |
|---|
| | 346 | * Create an empty configuration if none exist. |
|---|
| | 347 | */ |
|---|
| | 348 | _initScriptDir: function() { |
|---|
| | 349 | var dir = this._scriptDir; |
|---|
| | 350 | |
|---|
| | 351 | if (!dir.exists()) { |
|---|
| | 352 | dir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); |
|---|
| | 353 | |
|---|
| | 354 | var configStream = getWriteStream(this._configFile); |
|---|
| | 355 | var xml = "<UserScriptConfig/>"; |
|---|
| | 356 | configStream.write(xml, xml.length); |
|---|
| | 357 | configStream.close(); |
|---|
| | 358 | } |
|---|
| 374 | | getMatchingScripts: function(testFunc) { return this._scripts.filter(testFunc); } |
|---|
| | 362 | getMatchingScripts: function(testFunc) { return this._scripts.filter(testFunc); }, |
|---|
| | 363 | |
|---|
| | 364 | /** |
|---|
| | 365 | * Checks whether the version has changed since the last run and performs |
|---|
| | 366 | * any necessary upgrades. |
|---|
| | 367 | */ |
|---|
| | 368 | _updateVersion: function() { |
|---|
| | 369 | log("> GM_updateVersion"); |
|---|
| | 370 | |
|---|
| | 371 | // this is the last version which has been run at least once |
|---|
| | 372 | var initialized = GM_prefRoot.getValue("version", "0.0"); |
|---|
| | 373 | |
|---|
| | 374 | if (GM_compareVersions(initialized, "0.8") == -1) |
|---|
| | 375 | this._pointEightBackup(); |
|---|
| | 376 | |
|---|
| | 377 | // update the currently initialized version so we don't do this work again. |
|---|
| | 378 | var extMan = Components.classes["@mozilla.org/extensions/manager;1"] |
|---|
| | 379 | .getService(Components.interfaces.nsIExtensionManager); |
|---|
| | 380 | |
|---|
| | 381 | var item = extMan.getItemForID(GM_GUID); |
|---|
| | 382 | GM_prefRoot.setValue("version", item.version); |
|---|
| | 383 | |
|---|
| | 384 | log("< GM_updateVersion"); |
|---|
| | 385 | }, |
|---|
| | 386 | |
|---|
| | 387 | /** |
|---|
| | 388 | * In Greasemonkey 0.8 there was a format change to the gm_scripts folder and |
|---|
| | 389 | * testing found several bugs where the entire folder would get nuked. So we |
|---|
| | 390 | * are paranoid and backup the folder the first time 0.8 runs. |
|---|
| | 391 | */ |
|---|
| | 392 | _pointEightBackup: function() { |
|---|
| | 393 | var scriptDir = this._scriptDir; |
|---|
| | 394 | var scriptDirBackup = scriptDir.clone(); |
|---|
| | 395 | scriptDirBackup.leafName += "_08bak"; |
|---|
| | 396 | if (scriptDir.exists() && !scriptDirBackup.exists()) |
|---|
| | 397 | scriptDir.copyTo(scriptDirBackup.parent, scriptDirBackup.leafName); |
|---|
| | 398 | } |
|---|