OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. |
| 4 |
| 5 #include "app/app_paths.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" |
| 10 #include "base/path_service.h" |
| 11 |
| 12 namespace app { |
| 13 |
| 14 bool PathProvider(int key, FilePath* result) { |
| 15 // Assume that we will not need to create the directory if it does not exist. |
| 16 // This flag can be set to true for the cases where we want to create it. |
| 17 bool create_dir = false; |
| 18 |
| 19 FilePath cur; |
| 20 switch (key) { |
| 21 case app::DIR_THEMES: |
| 22 if (!PathService::Get(base::DIR_MODULE, &cur)) |
| 23 return false; |
| 24 cur = cur.Append(FILE_PATH_LITERAL("themes")); |
| 25 create_dir = true; |
| 26 break; |
| 27 case app::DIR_LOCALES: |
| 28 if (!PathService::Get(base::DIR_MODULE, &cur)) |
| 29 return false; |
| 30 #if defined(OS_MACOSX) |
| 31 // On Mac, locale files are in Contents/Resources, a sibling of the |
| 32 // App dir. |
| 33 cur = cur.DirName(); |
| 34 cur = cur.Append(FILE_PATH_LITERAL("Resources")); |
| 35 #else |
| 36 cur = cur.Append(FILE_PATH_LITERAL("locales")); |
| 37 #endif |
| 38 create_dir = true; |
| 39 break; |
| 40 // The following are only valid in the development environment, and |
| 41 // will fail if executed from an installed executable (because the |
| 42 // generated path won't exist). |
| 43 case app::DIR_TEST_DATA: |
| 44 if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur)) |
| 45 return false; |
| 46 cur = cur.Append(FILE_PATH_LITERAL("app")); |
| 47 cur = cur.Append(FILE_PATH_LITERAL("test")); |
| 48 cur = cur.Append(FILE_PATH_LITERAL("data")); |
| 49 if (!file_util::PathExists(cur)) // we don't want to create this |
| 50 return false; |
| 51 break; |
| 52 default: |
| 53 return false; |
| 54 } |
| 55 |
| 56 if (create_dir && !file_util::PathExists(cur) && |
| 57 !file_util::CreateDirectory(cur)) |
| 58 return false; |
| 59 |
| 60 *result = cur; |
| 61 return true; |
| 62 } |
| 63 |
| 64 // This cannot be done as a static initializer sadly since Visual Studio will |
| 65 // eliminate this object file if there is no direct entry point into it. |
| 66 void RegisterPathProvider() { |
| 67 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); |
| 68 } |
| 69 |
| 70 } // namespace app |
OLD | NEW |