| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 { | 34 { |
| 35 ShowUsage(); | 35 ShowUsage(); |
| 36 return; | 36 return; |
| 37 } | 37 } |
| 38 | 38 |
| 39 if (action == "show") | 39 if (action == "show") |
| 40 { | 40 { |
| 41 std::string pref; | 41 std::string pref; |
| 42 argumentStream >> pref; | 42 argumentStream >> pref; |
| 43 | 43 |
| 44 AdblockPlus::JsValuePtr value = filterEngine.GetPref(pref); | 44 auto value = filterEngine.GetPref(pref); |
| 45 if (value->IsUndefined()) | 45 if (value.IsUndefined()) |
| 46 std::cout << "No such preference" << std::endl; | 46 std::cout << "No such preference" << std::endl; |
| 47 else | 47 else |
| 48 { | 48 { |
| 49 if (value->IsString()) | 49 if (value.IsString()) |
| 50 std::cout << "(string) "; | 50 std::cout << "(string) "; |
| 51 else if (value->IsNumber()) | 51 else if (value.IsNumber()) |
| 52 std::cout << "(number) "; | 52 std::cout << "(number) "; |
| 53 else if (value->IsBool()) | 53 else if (value.IsBool()) |
| 54 std::cout << "(bool) "; | 54 std::cout << "(bool) "; |
| 55 else | 55 else |
| 56 std::cout << "(unknown type) "; | 56 std::cout << "(unknown type) "; |
| 57 std::cout << value->AsString() << std::endl; | 57 std::cout << value.AsString() << std::endl; |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 else if (action == "set") | 60 else if (action == "set") |
| 61 { | 61 { |
| 62 std::string pref; | 62 std::string pref; |
| 63 argumentStream >> pref; | 63 argumentStream >> pref; |
| 64 | 64 |
| 65 AdblockPlus::JsValuePtr current = filterEngine.GetPref(pref); | 65 auto current = filterEngine.GetPref(pref); |
| 66 if (current->IsUndefined()) | 66 if (current.IsUndefined()) |
| 67 std::cout << "No such preference" << std::endl; | 67 std::cout << "No such preference" << std::endl; |
| 68 else if (current->IsString()) | 68 else if (current.IsString()) |
| 69 { | 69 { |
| 70 std::string value; | 70 std::string value; |
| 71 std::getline(argumentStream, value); | 71 std::getline(argumentStream, value); |
| 72 filterEngine.SetPref(pref, filterEngine.GetJsEngine()->NewValue(value)); | 72 filterEngine.SetPref(pref, filterEngine.GetJsEngine()->NewValue(value)); |
| 73 } | 73 } |
| 74 else if (current->IsNumber()) | 74 else if (current.IsNumber()) |
| 75 { | 75 { |
| 76 int64_t value; | 76 int64_t value; |
| 77 argumentStream >> value; | 77 argumentStream >> value; |
| 78 filterEngine.SetPref(pref, filterEngine.GetJsEngine()->NewValue(value)); | 78 filterEngine.SetPref(pref, filterEngine.GetJsEngine()->NewValue(value)); |
| 79 } | 79 } |
| 80 else if (current->IsBool()) | 80 else if (current.IsBool()) |
| 81 { | 81 { |
| 82 bool value; | 82 bool value; |
| 83 argumentStream >> value; | 83 argumentStream >> value; |
| 84 filterEngine.SetPref(pref, filterEngine.GetJsEngine()->NewValue(value)); | 84 filterEngine.SetPref(pref, filterEngine.GetJsEngine()->NewValue(value)); |
| 85 } | 85 } |
| 86 else | 86 else |
| 87 std::cout << "Cannot set a preference of unknown type" << std::endl; | 87 std::cout << "Cannot set a preference of unknown type" << std::endl; |
| 88 } | 88 } |
| 89 else | 89 else |
| 90 throw NoSuchCommandError(name + " " + action); | 90 throw NoSuchCommandError(name + " " + action); |
| 91 } | 91 } |
| 92 | 92 |
| 93 std::string PrefsCommand::GetDescription() const | 93 std::string PrefsCommand::GetDescription() const |
| 94 { | 94 { |
| 95 return "Get and set preferences"; | 95 return "Get and set preferences"; |
| 96 } | 96 } |
| 97 | 97 |
| 98 std::string PrefsCommand::GetUsage() const | 98 std::string PrefsCommand::GetUsage() const |
| 99 { | 99 { |
| 100 return name + " [show PREF|set PREF VALUE]"; | 100 return name + " [show PREF|set PREF VALUE]"; |
| 101 } | 101 } |
| OLD | NEW |