29 #include <nsIFileURL.h>
30 #include <nsDirectoryServiceUtils.h>
31 #include <nsComponentManagerUtils.h>
32 #include <nsServiceManagerUtils.h>
76 LOG(
"%s: Setting up a task writer instance", __FUNCTION__);
80 mNetUtil = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
81 NS_ENSURE_SUCCESS(rv, rv);
84 nsCOMPtr<nsIFile> taskFile;
85 rv = NS_GetSpecialDirectory(NS_APP_APPLICATION_REGISTRY_DIR,
86 getter_AddRefs(taskFile));
87 NS_ENSURE_SUCCESS(rv, rv);
91 NS_ENSURE_SUCCESS(rv, rv);
93 PRBool exists = PR_FALSE;
94 rv = taskFile->Exists(&exists);
95 NS_ENSURE_SUCCESS(rv, rv);
99 PRUint32 curNumeralExtension = 0;
102 leafName.AppendInt(++curNumeralExtension);
104 rv = taskFile->SetNativeLeafName(leafName);
105 NS_ENSURE_SUCCESS(rv, rv);
107 rv = taskFile->Exists(&exists);
108 NS_ENSURE_SUCCESS(rv, rv);
111 rv = taskFile->Create(nsIFile::NORMAL_FILE_TYPE, 0600);
112 NS_ENSURE_SUCCESS(rv, rv);
114 rv = taskFile->GetPath(mTaskFilepath);
115 NS_ENSURE_SUCCESS(rv, rv);
117 LOG(
"%s: Creating task file at '%s'",
118 __FUNCTION__, NS_ConvertUTF16toUTF8(mTaskFilepath).
get());
122 mOutputStream.open(mTaskFilepath.get());
124 mOutputStream.open(NS_ConvertUTF16toUTF8(mTaskFilepath).
get());
140 LOG(
"%s: Done writing task file at '%s'",
141 __FUNCTION__, mTaskFilepath.get());
143 mOutputStream.close();
150 LOG(
"%s Writing header '%s'",
166 LOG(
"%s Writing header '%s'",
182 NS_ENSURE_ARG_POINTER(aMediaList);
184 LOG(
"%s Writing header '%s'",
189 nsString mediaListName;
190 rv = aMediaList->GetName(mediaListName);
191 NS_ENSURE_SUCCESS(rv, rv);
194 rv = mNetUtil->EscapeString(NS_ConvertUTF16toUTF8(mediaListName),
195 nsINetUtil::ESCAPE_URL_PATH,
197 NS_ENSURE_SUCCESS(rv, rv);
213 NS_ENSURE_ARG_POINTER(aMediaList);
216 nsString mediaListName;
217 rv = aMediaList->GetName(mediaListName);
218 NS_ENSURE_SUCCESS(rv, rv);
221 if (aIsMainLibrary) {
225 rv = mNetUtil->EscapeString(NS_ConvertUTF16toUTF8(mediaListName),
226 nsINetUtil::ESCAPE_URL_PATH, escaped);
227 NS_ENSURE_SUCCESS(rv, rv);
230 LOG(
"%s: Writing header '%s' for medialist name '%s'",
251 LOG(
"%s: Writing header '%s' for updated items",
270 NS_ENSURE_ARG_POINTER(aMediaItem);
274 nsCOMPtr<nsIURI> contentUri;
275 rv = aMediaItem->GetContentSrc(getter_AddRefs(contentUri));
276 NS_ENSURE_SUCCESS(rv, rv);
278 nsCOMPtr<nsIFileURL> contentFileURL = do_QueryInterface(contentUri, &rv);
279 if (NS_FAILED(rv) || !contentFileURL) {
281 NS_WARNING(
"WARNING: Tried to write a remote mediaitem resource!");
285 nsCOMPtr<nsIFile> contentFile;
286 rv = contentFileURL->GetFile(getter_AddRefs(contentFile));
287 NS_ENSURE_SUCCESS(rv, rv);
289 nsString itemContentPath;
290 rv = contentFile->GetPath(itemContentPath);
291 NS_ENSURE_SUCCESS(rv, rv);
293 PRBool exists = PR_FALSE;
294 rv = contentFile->Exists(&exists);
295 NS_ENSURE_SUCCESS(rv, rv);
296 NS_ENSURE_TRUE(exists, NS_ERROR_FILE_NOT_FOUND);
299 rv = mNetUtil->EscapeString(NS_ConvertUTF16toUTF8(itemContentPath),
300 nsINetUtil::ESCAPE_URL_PATH, escaped);
301 NS_ENSURE_SUCCESS(rv, rv);
304 rv = aMediaItem->GetGuid(guid);
305 NS_ENSURE_SUCCESS(rv, rv);
307 LOG(
"%s: Writing added track '%s'",
308 __FUNCTION__, escaped.get());
310 mOutputStream << NS_LossyConvertUTF16toASCII(guid).get()
321 NS_ENSURE_ARG_POINTER(aMediaItem);
328 NS_ENSURE_SUCCESS(rv, rv);
329 NS_ENSURE_TRUE(!iTunesID.IsEmpty(), NS_ERROR_FAILURE);
332 nsCOMPtr<nsIURI> contentUri;
333 rv = aMediaItem->GetContentSrc(getter_AddRefs(contentUri));
334 NS_ENSURE_SUCCESS(rv, rv);
336 nsCOMPtr<nsIFileURL> contentFileURL = do_QueryInterface(contentUri, &rv);
337 if (NS_FAILED(rv) || !contentFileURL) {
339 NS_WARNING(
"WARNING: Tried to write a remote mediaitem resource!");
343 nsCOMPtr<nsIFile> contentFile;
344 rv = contentFileURL->GetFile(getter_AddRefs(contentFile));
345 NS_ENSURE_SUCCESS(rv, rv);
347 nsString itemContentPath;
348 rv = contentFile->GetPath(itemContentPath);
349 NS_ENSURE_SUCCESS(rv, rv);
351 PRBool exists = PR_FALSE;
352 rv = contentFile->Exists(&exists);
353 NS_ENSURE_SUCCESS(rv, rv);
354 NS_ENSURE_TRUE(exists, NS_ERROR_FILE_NOT_FOUND);
357 rv = mNetUtil->EscapeString(NS_ConvertUTF16toUTF8(itemContentPath),
358 nsINetUtil::ESCAPE_URL_PATH, escaped);
359 NS_ENSURE_SUCCESS(rv, rv);
361 LOG(
"%s: Writing updated track '%s' -> '%s'",
363 NS_LossyConvertUTF16toASCII(iTunesID).
get(),
366 mOutputStream << NS_LossyConvertUTF16toASCII(iTunesID).get()
377 NS_ENSURE_ARG_POINTER(aMediaList);
381 rv = aMediaList->GetName(listName);
382 NS_ENSURE_SUCCESS(rv, rv);
385 rv = mNetUtil->EscapeString(NS_ConvertUTF16toUTF8(listName),
386 nsINetUtil::ESCAPE_URL_PATH, escaped);
387 NS_ENSURE_SUCCESS(rv, rv);
389 LOG(
"%s: Writing media list name '%s'",
390 __FUNCTION__, escaped.get());
392 mOutputStream << mCurOutputIndex++
404 nsresult rv = mNetUtil->EscapeString(NS_ConvertUTF16toUTF8(aString),
405 nsINetUtil::ESCAPE_URL_PATH, escaped);
406 NS_ENSURE_SUCCESS(rv, rv);
408 LOG(
"%s: Writing string '%s'",
409 __FUNCTION__, escaped.get());
411 mOutputStream << mCurOutputIndex++
#define SB_PRLOG_SETUP(x)
#define SB_PROPERTY_ITUNES_GUID