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: */
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"
25 #include "nsComponentManagerUtils.h"
26 #include "nsServiceManagerUtils.h"
27 #include "nsDirectoryServiceDefs.h"
28 #include "nsIProperties.h"
30 #include "nsStringAPI.h"
33 #include "nsAppDirectoryServiceDefs.h"
35 /* Project includes */
36 #include "aaManager.h"
38 aaManager::aaManager()
42 aaManager::~aaManager()
46 NS_IMPL_ISUPPORTS1(aaManager
,
51 aaManager::TmpFileFromString(const char *aName
, PRBool aReplace
,
54 return TmpFileFromCString(nsDependentCString(aName
), aReplace
, _retval
);
58 aaManager::TmpFileFromCString(const nsACString
& aName
, PRBool aReplace
,
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
);
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
);