/
CompileITunesMetadataTaskBase.cs
85 lines (66 loc) · 2.3 KB
/
CompileITunesMetadataTaskBase.cs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Xamarin.MacDev.Tasks;
using Xamarin.MacDev;
namespace Xamarin.iOS.Tasks
{
public abstract class CompileITunesMetadataTaskBase : Task
{
#region Inputs
public string SessionId { get; set; }
[Required]
public string AppBundleDir { get; set; }
public ITaskItem[] ITunesMetadata { get; set; }
[Required]
public ITaskItem OutputPath { get; set; }
#endregion
public override bool Execute ()
{
PDictionary metadata;
Log.LogTaskName ("CompileITunesMetadata");
Log.LogTaskProperty ("AppBundleDir", AppBundleDir);
Log.LogTaskProperty ("ITunesMetadata", ITunesMetadata);
Log.LogTaskProperty ("OutputPath", OutputPath);
if (ITunesMetadata != null) {
if (ITunesMetadata.Length > 1) {
Log.LogError ("Cannot have more than 1 iTunesMetadata.plist.");
return false;
}
var path = ITunesMetadata[0].GetMetadata ("FullPath");
try {
metadata = PDictionary.FromFile (path);
} catch (Exception ex) {
Log.LogError (null, null, null, path, 0, 0, 0, 0, "Error loading '{0}': {1}", path, ex.Message);
return false;
}
} else {
var manifest = Path.Combine (AppBundleDir, "Info.plist");
PDictionary plist;
try {
plist = PDictionary.FromFile (manifest);
} catch (Exception ex) {
Log.LogError (null, null, null, manifest, 0, 0, 0, 0, "Error loading '{0}': {1}", manifest, ex.Message);
return false;
}
var displayName = plist.GetCFBundleDisplayName ();
var bundleVersion = plist.GetCFBundleVersion ();
metadata = new PDictionary ();
metadata.Add ("genre", new PString ("Application"));
if (bundleVersion != null)
metadata.Add ("bundleVersion", (PString) bundleVersion);
if (displayName != null)
metadata.Add ("itemName", (PString) displayName);
metadata.Add ("kind", (PString) "software");
if (displayName != null)
metadata.Add ("playlistName", (PString) displayName);
metadata.Add ("softwareIconNeedsShine", (PBoolean) true);
metadata.Add ("softwareVersionBundleId", (PString) plist.GetCFBundleIdentifier ());
}
Directory.CreateDirectory (Path.GetDirectoryName (OutputPath.ItemSpec));
metadata.Save (OutputPath.ItemSpec, true);
return !Log.HasLoggedErrors;
}
}
}