blob: 77e8cc6c64054eb0cb69ba87e945a4bb123f6336 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/utility/media_galleries/itunes_pref_parser_win.h"
#include "base/base64.h"
#include "base/strings/string_util.h"
#include "chrome/utility/media_galleries/iapps_xml_utils.h"
#include "third_party/libxml/chromium/libxml_utils.h"
namespace itunes {
base::FilePath::StringType FindLibraryLocationInPrefXml(
const std::string& pref_xml_data) {
XmlReader reader;
base::FilePath::StringType result;
if (!reader.Load(pref_xml_data))
return result;
// Find the plist node and then search within that tag.
if (!iapps::SeekToNodeAtCurrentDepth(&reader, "plist"))
return result;
if (!reader.Read())
return result;
if (!iapps::SeekToNodeAtCurrentDepth(&reader, "dict"))
return result;
if (!iapps::SeekInDict(&reader, "User Preferences"))
return result;
if (!iapps::SeekToNodeAtCurrentDepth(&reader, "dict"))
return result;
if (!iapps::SeekInDict(&reader, "iTunes Library XML Location:1"))
return result;
if (!iapps::SeekToNodeAtCurrentDepth(&reader, "data"))
return result;
std::string pref_value;
if (!reader.ReadElementContent(&pref_value))
return result;
// The data is a base64 encoded wchar_t*. Because Base64Decode uses
// std::strings, the result has to be casted to a wchar_t*.
std::string data;
if (!base::Base64Decode(base::CollapseWhitespaceASCII(pref_value, true),
&data))
return result;
return base::FilePath::StringType(
reinterpret_cast<const wchar_t*>(data.data()), data.size() / 2);
}
} // namespace itunes
|