transport: pass correct channel
[abstract.git] / storage / base / aaManager.cpp
blob58bde3b22fd5bea350eaf1894e07dcfb55c26469
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
3 /*
4 * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
24 #include "nsCOMPtr.h"
25 #include "nsComponentManagerUtils.h"
26 #include "nsServiceManagerUtils.h"
27 #include "nsDirectoryServiceDefs.h"
28 #include "nsIProperties.h"
29 #include "nsIFile.h"
30 #include "nsStringAPI.h"
32 /* Unfrozen API */
33 #include "nsAppDirectoryServiceDefs.h"
35 /* Project includes */
36 #include "aaManager.h"
38 aaManager::aaManager()
42 aaManager::~aaManager()
46 NS_IMPL_ISUPPORTS1(aaManager,
47 aaIManager)
49 /* aaIManager */
50 NS_IMETHODIMP
51 aaManager::TmpFileFromString(const char *aName, PRBool aReplace,
52 nsIFile * *_retval)
54 return TmpFileFromCString(nsDependentCString(aName), aReplace, _retval);
57 NS_IMETHODIMP
58 aaManager::TmpFileFromCString(const nsACString& aName, PRBool aReplace,
59 nsIFile * *_retval)
61 nsresult rv;
63 nsCOMPtr<nsIProperties> dsp;
64 dsp = do_GetService("@mozilla.org/file/directory_service;1", &rv);
65 NS_ENSURE_SUCCESS(rv, rv);
67 nsCOMPtr<nsIFile> file, dir;
68 rv = dsp->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(file));
69 NS_ENSURE_SUCCESS(rv, rv);
71 rv = file->Clone(getter_AddRefs( dir ));
72 NS_ENSURE_SUCCESS(rv, rv);
74 rv = file->AppendNative(aName);
75 NS_ENSURE_SUCCESS(rv, rv);
77 PRBool exists;
78 rv = file->Exists(&exists);
79 NS_ENSURE_SUCCESS(rv, rv);
81 if (exists && aReplace) {
82 rv = file->Remove(PR_FALSE);
83 NS_ENSURE_SUCCESS(rv, rv);
86 NS_IF_ADDREF(*_retval = file);
87 return NS_OK;