Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Mods/I18NAppName.projmods
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"group": "",
"i18n_name": [],
"libs": [],
"frameworks": [],
"headerpaths": [],
"files": [],
"folders": [],
"excludes": ["^.*.meta$", "^.*.mdown$", "^.*.pdf$"],
"compiler_flags": [],
"linker_flags": []
}
25 changes: 17 additions & 8 deletions PBX Editor/PBXObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,21 @@ public PBXContainerItemProxy( string guid, PBXDictionary dictionary ) : base( gu
}
}

public class PBXReferenceProxy : PBXObject
{
public PBXReferenceProxy() : base() {
}

public PBXReferenceProxy( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
}
}
public class PBXReferenceProxy : PBXObject
{
public PBXReferenceProxy() : base() {
}

public PBXReferenceProxy( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
}
}

public class PBXTargetDependency : PBXObject
{
public PBXTargetDependency() : base() {
}

public PBXTargetDependency( string guid, PBXDictionary dictionary ) : base( guid, dictionary ) {
}
}
}
32 changes: 20 additions & 12 deletions PBX Editor/PBXParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,26 @@ public string ResolveName( string guid )

return null;
}
else if( entity is PBXNativeTarget )
{
PBXNativeTarget obj = (PBXNativeTarget)entity;
//Debug.LogWarning ("PBXNativeTarget " + guid + " " + obj.ToString());

if( obj.data.ContainsKey( "name" ) ) {
//Debug.Log ("PBXNativeTarget " + (string)obj.data[ "name" ] + " " + guid);
return (string)obj.data[ "name" ];
}

return null;
}
else if( entity is PBXNativeTarget )
{
PBXNativeTarget obj = (PBXNativeTarget)entity;
//Debug.LogWarning ("PBXNativeTarget " + guid + " " + obj.ToString());

if( obj.data.ContainsKey( "name" ) ) {
//Debug.Log ("PBXNativeTarget " + (string)obj.data[ "name" ] + " " + guid);
return (string)obj.data[ "name" ];
}

return null;
}
else if( entity is PBXContainerItemProxy )
{
return "PBXContainerItemProxy";
}
else if( entity is PBXTargetDependency )
{
return "PBXTargetDependency";
}
else if( entity is XCBuildConfiguration )
{
XCBuildConfiguration obj = (XCBuildConfiguration)entity;
Expand Down
Empty file modified PBX Editor/PBXVariantGroup.cs
100644 → 100755
Empty file.
Empty file modified Plist/Plist.cs
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions Readme.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ After the Unity's building phase, OnPostProcessBuild in XCodePostProcess.cs will
In these setting files, specify the fields using a json pattern.

* group:The group name in Xcode to which files and folders will added by this projmods file
* i18n_name:The application name internationalization, format for “language : application name”
* libs:The name of libs should be added in Xcode Build Phases, libz.dylib for example. If you want to import a .a lib to Xcode, add it as a file(in "files")
* frameworks:The name of framework should be added in Xcode Build Phases, Security.framework for example. If you want to add a third party framework, add it using a relative path to `files` section instead of here.
* headerpaths:Header Search Paths in Build Setting of Xcode
Expand All @@ -36,6 +37,7 @@ One example, the following file will add all files in /iOS/KKKeychain to the Xco
{
"group": "KKKeychain",
"libs": [],
"i18n_name": [ "en:English","zh-Hans:简体中文","zh-Hant:繁体中文”],
"frameworks": ["Security.framework"],
"headerpaths": [],
"files": [],
Expand Down
6 changes: 6 additions & 0 deletions XCMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public ArrayList libs {
return _libs;
}
}

public ArrayList i18n_name {
get {
return (ArrayList)_datastore["i18n_name"];
}
}

public ArrayList frameworks {
get {
Expand Down
11 changes: 7 additions & 4 deletions XCPlist.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ public XCPlist(string plistPath)
public void Process(Hashtable plist)
{
Dictionary<string, object> dict = (Dictionary<string, object>)PlistCS.Plist.readPlist(plistPath);
foreach( DictionaryEntry entry in plist)
{
this.AddPlistItems((string)entry.Key, entry.Value, dict);
}
if(plist != null)
{
foreach( DictionaryEntry entry in plist)
{
this.AddPlistItems((string)entry.Key, entry.Value, dict);
}
}
if (plistModified)
{
PlistCS.Plist.writeXml(dict, plistPath);
Expand Down
73 changes: 69 additions & 4 deletions XCProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public partial class XCProject : System.IDisposable
private PBXSortedDictionary<PBXBuildFile> _buildFiles;
private PBXSortedDictionary<PBXGroup> _groups;
private PBXSortedDictionary<PBXFileReference> _fileReferences;
private PBXDictionary<PBXNativeTarget> _nativeTargets;
private PBXDictionary<PBXNativeTarget> _nativeTargets;
private PBXDictionary<PBXContainerItemProxy> _containerItemProxy;
private PBXDictionary<PBXTargetDependency> _targetDependency;

private PBXDictionary<PBXFrameworksBuildPhase> _frameworkBuildPhases;
private PBXDictionary<PBXResourcesBuildPhase> _resourcesBuildPhases;
Expand Down Expand Up @@ -236,6 +238,24 @@ public PBXDictionary<PBXCopyFilesBuildPhase> copyBuildPhases {
}
}

public PBXDictionary<PBXContainerItemProxy> containerItemProxy {
get {
if( _containerItemProxy == null ) {
_containerItemProxy = new PBXDictionary<PBXContainerItemProxy>( _objects );
}
return _containerItemProxy;
}
}

public PBXDictionary<PBXTargetDependency> targetDependency {
get {
if( _targetDependency == null ) {
_targetDependency = new PBXDictionary<PBXTargetDependency>( _objects );
}
return _targetDependency;
}
}

#endregion


Expand Down Expand Up @@ -334,7 +354,7 @@ public object GetObject( string guid )
return _objects[guid];
}

public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false )
public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false, bool IsI18NName = false )
{
//Debug.Log("AddFile " + filePath + ", " + parent + ", " + tree + ", " + (createBuildFiles? "TRUE":"FALSE") + ", " + (weak? "TRUE":"FALSE") );

Expand Down Expand Up @@ -372,7 +392,10 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
if( parent == null ) {
parent = _rootGroup;
}

if(IsI18NName)
{
filePath = absPath.Substring( absPath.LastIndexOf("/", absPath.IndexOf(".lproj")) + 1 );
}
//Check if there is already a file
PBXFileReference fileReference = GetFile( System.IO.Path.GetFileName( filePath ) );
if( fileReference != null ) {
Expand All @@ -381,6 +404,7 @@ public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tr
}

fileReference = new PBXFileReference( filePath, (TreeEnum)System.Enum.Parse( typeof(TreeEnum), tree ) );

parent.AddChild( fileReference );
fileReferences.Add( fileReference );
results.Add( fileReference.guid, fileReference );
Expand Down Expand Up @@ -779,6 +803,45 @@ public void ApplyMod( XCMod mod )
XCPlist plist = new XCPlist (plistPath);
plist.Process(mod.plist);

Debug.Log ("Adding I18N name...");
if(mod.i18n_name != null && mod.i18n_name.Count > 0){
Dictionary<string, object> dict = (Dictionary<string, object>)PlistCS.Plist.readPlist(plistPath);
if(dict.ContainsKey("CFBundleDisplayName"))
{
dict.Remove("CFBundleDisplayName");
}
dict["LSHasLocalizedDisplayName"] = true;
PlistCS.Plist.writeXml(dict, plistPath);

var variant = new PBXVariantGroup("InfoPlist.strings", null, "GROUP");
// mark variants
variantGroups.Add(variant);
// add variant to project
_rootGroup.AddChild(variant);

foreach (string entry in mod.i18n_name)
{
string[] filename = entry.Split( ':' );
string folder = this.projectRootPath + "/" + filename[0] + ".lproj";
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
string filePath = folder + "/InfoPlist.strings";
string content = "\"CFBundleDisplayName\" = \"" + filename[1] + "\";\n";
content += "\"CFBundleName\" = \"" + filename[1] + "\";\n";
File.WriteAllText(filePath, content);

var result = AddFile( filePath, variant, "GROUP", true, false, true );
foreach (var item in result.Keys)
{
PBXFileReference fileReference = (PBXFileReference)result[item];
fileReference.Remove("name");
fileReference.Add("name",filename[1]);
}
}
}

this.Consolidate();
}

Expand All @@ -793,7 +856,9 @@ public void Consolidate()
consolidated.Append<PBXFileReference>( this.fileReferences );//sort!
consolidated.Append<PBXFrameworksBuildPhase>( this.frameworkBuildPhases );
consolidated.Append<PBXGroup>( this.groups );//sort!
consolidated.Append<PBXNativeTarget>( this.nativeTargets );
consolidated.Append<PBXNativeTarget>( this.nativeTargets );
consolidated.Append<PBXContainerItemProxy>( this.containerItemProxy );
consolidated.Append<PBXTargetDependency>( this.targetDependency );
consolidated.Add( project.guid, project.data );//TODO this should be named PBXProject?
consolidated.Append<PBXResourcesBuildPhase>( this.resourcesBuildPhases );
consolidated.Append<PBXShellScriptBuildPhase>( this.shellScriptBuildPhases );
Expand Down
16 changes: 11 additions & 5 deletions XCodePostProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ public static class XCodePostProcess
[PostProcessBuild(999)]
public static void OnPostProcessBuild( BuildTarget target, string pathToBuiltProject )
{
if (target != BuildTarget.iPhone) {
Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
return;
}

#if UNITY_5
if (target != BuildTarget.iOS) {
Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
return;
}
#else
if (target != BuildTarget.iPhone) {
Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
return;
}
#endif
// Create a new project object from build target
XCProject project = new XCProject( pathToBuiltProject );

Expand Down