Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save abelevtsov/d9e22ac638dcbcae0318564af905a4ec to your computer and use it in GitHub Desktop.
Save abelevtsov/d9e22ac638dcbcae0318564af905a4ec to your computer and use it in GitHub Desktop.

Revisions

  1. @yourpalmark yourpalmark revised this gist Aug 15, 2013. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions IncrementBuildVersion.cs
    Original file line number Diff line number Diff line change
    @@ -16,10 +16,7 @@
    */

    /**
    * Based on: https://gist.github.com/darktable/3679999
    * Uses: https://github.com/darktable/PlistCS
    *
    * Additional gists: https://gist.github.com/darktable
    * https://gist.github.com/yourpalmark/6231952
    */

    #define PLIST_CS
  2. @yourpalmark yourpalmark revised this gist Aug 14, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion IncrementBuildVersion.cs
    Original file line number Diff line number Diff line change
    @@ -48,7 +48,7 @@ static void Init()
    [PostProcessBuild]
    public static void OnPostProcessBuild(BuildTarget target, string buildPath)
    {
    if (!(target == BuildTarget.iPhone))
    if (target != BuildTarget.iPhone)
    {
    return;
    }
  3. @yourpalmark yourpalmark revised this gist Aug 14, 2013. 1 changed file with 128 additions and 111 deletions.
    239 changes: 128 additions & 111 deletions IncrementBuildVersion.cs
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,28 @@
    /* **************************************************************************
    Copyright 2012 Calvin Rien
    (http://the.darktable.com)
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    ************************************************************************** */

    // if you've got PlistCS (https://github.com/darktable/PlistCS/downloads)
    // this script will automatically update the Info.plist version number
    // #define PLIST_CS
    /**
    * Copyright 2012 Calvin Rien
    * (http://the.darktable.com)
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    * http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */

    /**
    * Based on: https://gist.github.com/darktable/3679999
    * Uses: https://github.com/darktable/PlistCS
    *
    * Additional gists: https://gist.github.com/darktable
    */

    #define PLIST_CS

    using System.IO;
    using System.Text.RegularExpressions;
    @@ -31,93 +35,106 @@ limitations under the License.
    using PlistCS;
    #endif

    public class IncrementBuildVersion : ScriptableObject {

    [MenuItem("Tools/Increment Build Number")]
    static void Init() {
    IncrementBuild("");
    }

    [PostProcessBuild] // Requires Unity 3.5.2+
    public static void OnPostProcessBuild(BuildTarget target, string buildPath) {
    if (!(target == BuildTarget.iPhone)) {
    return;
    }

    IncrementBuild(buildPath);
    }

    public static void IncrementBuild(string buildPath) {
    var settingsPath = Path.GetDirectoryName(Application.dataPath);
    settingsPath = Path.Combine(settingsPath, "ProjectSettings");
    settingsPath = Path.Combine(settingsPath, "ProjectSettings.asset");

    if (!File.Exists(settingsPath)) {
    Debug.LogError("Couldn't find project settings file.");
    return;
    }

    var lines = File.ReadAllLines(settingsPath);

    if (!lines[0].StartsWith("%YAML")) {
    Debug.LogError("Project settings file needs to be serialized as a text asset. (Check 'Project Settings->Editor')");
    return;
    }

    string pattern = @"^(\s*iPhoneBundleVersion:\s*)([\d\.]+)$";
    bool success = false;

    System.Version version = null;

    for (int i=0; i<lines.Length; i++) {
    var line = lines[i];

    if (!Regex.IsMatch(line, pattern)) {
    continue;
    }

    var match = Regex.Match(line, pattern);

    version = new System.Version(match.Groups[2].Value);

    var major = version.Major < 0 ? 0 : version.Major;
    var minor = version.Minor < 0 ? 0 : version.Minor;
    var build = version.Build < 0 ? 0 : version.Build;
    var revision = version.Revision < 0 ? 0 : version.Revision;

    version = new System.Version(major, minor, build, revision + 1);

    line = match.Groups[1].Value + version;

    lines[i] = line;
    success = true;

    break;
    }

    if (!success) {
    Debug.LogError("Couldn't find bundle version in ProjectSettings.asset");
    return;
    }

    File.WriteAllLines(settingsPath, lines);

    Debug.Log("Build version: " + version);

    #if PLIST_CS
    var plistPath = Path.Combine(buildPath, "Info.plist");

    if (!File.Exists(plistPath)) {
    Debug.LogWarning("Couldn't find Info.plist in build output.");
    return;
    }

    // modify plist
    var plist = (Dictionary<string,object>) Plist.readPlist(plistPath);

    plist["CFBundleVersion"] = version.ToString();

    Plist.writeXml(plist, plistPath);
    #endif
    }
    }
    public class IncrementBuildVersion : ScriptableObject
    {
    /*
    [MenuItem("Tools/Increment Build Number")]
    static void Init()
    {
    IncrementBuild("");
    }
    */

    [PostProcessBuild]
    public static void OnPostProcessBuild(BuildTarget target, string buildPath)
    {
    if (!(target == BuildTarget.iPhone))
    {
    return;
    }

    IncrementBuild(buildPath);
    }

    public static void IncrementBuild(string buildPath)
    {
    var settingsPath = Path.GetDirectoryName(Application.dataPath);
    settingsPath = Path.Combine(settingsPath, "ProjectSettings");
    settingsPath = Path.Combine(settingsPath, "ProjectSettings.asset");

    if (!File.Exists(settingsPath))
    {
    Debug.LogError("Couldn't find project settings file.");
    return;
    }

    var lines = File.ReadAllLines(settingsPath);

    if (!lines[0].StartsWith("%YAML"))
    {
    Debug.LogError("Project settings file needs to be serialized as a text asset. (Check 'Project Settings->Editor')");
    return;
    }

    string pattern = @"^(\s*iPhoneBundleVersion:\s*)([\d\.]+)$";
    bool success = false;

    System.Version version = null;

    for (int i=0; i<lines.Length; i++)
    {
    var line = lines[i];

    if (!Regex.IsMatch(line, pattern))
    {
    continue;
    }

    var match = Regex.Match(line, pattern);

    version = new System.Version(match.Groups[2].Value);

    var major = version.Major < 0 ? 0 : version.Major;
    var minor = version.Minor < 0 ? 0 : version.Minor;
    var build = version.Build < 0 ? 0 : version.Build;
    var revision = version.Revision < 0 ? 0 : version.Revision;

    version = new System.Version(major, minor, build, revision + 1);

    line = match.Groups[1].Value + version;

    lines[i] = line;
    success = true;

    break;
    }

    if (!success)
    {
    Debug.LogError("Couldn't find bundle version in ProjectSettings.asset");
    return;
    }

    File.WriteAllLines(settingsPath, lines);

    Debug.Log("Build version: " + version);

    #if PLIST_CS
    var plistPath = Path.Combine(buildPath, "Info.plist");

    if (!File.Exists(plistPath))
    {
    Debug.LogWarning("Couldn't find Info.plist in build output.");
    return;
    }

    // modify plist
    var plist = (Dictionary<string,object>) Plist.readPlist(plistPath);

    plist["CFBundleShortVersionString"] = version.Major.ToString() + "." + version.Minor.ToString() + "." + version.Build.ToString();
    plist["CFBundleVersion"] = version.Revision.ToString();

    Plist.writeXml(plist, plistPath);
    #endif
    }
    }
  4. @darktable darktable revised this gist Oct 26, 2012. 1 changed file with 48 additions and 16 deletions.
    64 changes: 48 additions & 16 deletions IncrementBuildVersion.cs
    Original file line number Diff line number Diff line change
    @@ -15,36 +15,49 @@ You may obtain a copy of the License at
    limitations under the License.
    ************************************************************************** */

    // if you've got PlistCS (https://github.com/darktable/PlistCS/downloads)
    // this script will automatically update the Info.plist version number
    // #define PLIST_CS

    using System.IO;
    using System.Text.RegularExpressions;
    using UnityEditor;
    using UnityEditor.Callbacks;
    using UnityEngine;
    using System.Collections.Generic;

    #if PLIST_CS
    using PlistCS;
    #endif

    public class IncrementBuildVersion : ScriptableObject {

    [MenuItem("Tools/Increment Build Number")]
    static void Init() {
    IncrementBuild(BuildTarget.iPhone, "");
    IncrementBuild("");
    }

    [PostProcessBuild]
    // Requires Unity 3.5+
    public static void IncrementBuild(BuildTarget target, string buildPath) {
    if (!(target == BuildTarget.Android || target == BuildTarget.iPhone)) {
    [PostProcessBuild] // Requires Unity 3.5.2+
    public static void OnPostProcessBuild(BuildTarget target, string buildPath) {
    if (!(target == BuildTarget.iPhone)) {
    return;
    }

    var path = Path.GetDirectoryName(Application.dataPath);
    path = Path.Combine(path, "ProjectSettings");
    path = Path.Combine(path, "ProjectSettings.asset");
    IncrementBuild(buildPath);
    }

    public static void IncrementBuild(string buildPath) {
    var settingsPath = Path.GetDirectoryName(Application.dataPath);
    settingsPath = Path.Combine(settingsPath, "ProjectSettings");
    settingsPath = Path.Combine(settingsPath, "ProjectSettings.asset");

    if (!File.Exists(path)) {
    if (!File.Exists(settingsPath)) {
    Debug.LogError("Couldn't find project settings file.");
    return;
    }

    var lines = File.ReadAllLines(path);
    var lines = File.ReadAllLines(settingsPath);

    if (!lines[0].StartsWith("%YAML")) {
    Debug.LogError("Project settings file needs to be serialized as a text asset. (Check 'Project Settings->Editor')");
    @@ -54,6 +67,8 @@ public static void IncrementBuild(BuildTarget target, string buildPath) {
    string pattern = @"^(\s*iPhoneBundleVersion:\s*)([\d\.]+)$";
    bool success = false;

    System.Version version = null;

    for (int i=0; i<lines.Length; i++) {
    var line = lines[i];

    @@ -63,7 +78,7 @@ public static void IncrementBuild(BuildTarget target, string buildPath) {

    var match = Regex.Match(line, pattern);

    var version = new System.Version(match.Groups[2].Value);
    version = new System.Version(match.Groups[2].Value);

    var major = version.Major < 0 ? 0 : version.Major;
    var minor = version.Minor < 0 ? 0 : version.Minor;
    @@ -77,15 +92,32 @@ public static void IncrementBuild(BuildTarget target, string buildPath) {
    lines[i] = line;
    success = true;

    Debug.Log("Next version number: " + version);

    break;
    }

    if (success) {
    File.WriteAllLines(path, lines);
    } else {
    if (!success) {
    Debug.LogError("Couldn't find bundle version in ProjectSettings.asset");
    return;
    }

    File.WriteAllLines(settingsPath, lines);

    Debug.Log("Build version: " + version);

    #if PLIST_CS
    var plistPath = Path.Combine(buildPath, "Info.plist");

    if (!File.Exists(plistPath)) {
    Debug.LogWarning("Couldn't find Info.plist in build output.");
    return;
    }

    // modify plist
    var plist = (Dictionary<string,object>) Plist.readPlist(plistPath);

    plist["CFBundleVersion"] = version.ToString();

    Plist.writeXml(plist, plistPath);
    #endif
    }
    }
  5. @darktable darktable revised this gist Sep 11, 2012. 1 changed file with 14 additions and 9 deletions.
    23 changes: 14 additions & 9 deletions IncrementBuildVersion.cs
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,6 @@ You may obtain a copy of the License at
    limitations under the License.
    ************************************************************************** */

    using System.IO;
    using System.Text.RegularExpressions;
    using UnityEditor;
    @@ -29,7 +28,8 @@ static void Init() {
    IncrementBuild(BuildTarget.iPhone, "");
    }

    [PostProcessBuild] // Requires Unity 3.5+
    [PostProcessBuild]
    // Requires Unity 3.5+
    public static void IncrementBuild(BuildTarget target, string buildPath) {
    if (!(target == BuildTarget.Android || target == BuildTarget.iPhone)) {
    return;
    @@ -39,6 +39,11 @@ public static void IncrementBuild(BuildTarget target, string buildPath) {
    path = Path.Combine(path, "ProjectSettings");
    path = Path.Combine(path, "ProjectSettings.asset");

    if (!File.Exists(path)) {
    Debug.LogError("Couldn't find project settings file.");
    return;
    }

    var lines = File.ReadAllLines(path);

    if (!lines[0].StartsWith("%YAML")) {
    @@ -60,14 +65,12 @@ public static void IncrementBuild(BuildTarget target, string buildPath) {

    var version = new System.Version(match.Groups[2].Value);

    var nextVer = new int[4];

    nextVer[0] = version.Major < 0 ? 0 : version.Major;
    nextVer[1] = version.Minor < 0 ? 0 : version.Minor;
    nextVer[2] = version.Build < 0 ? 0 : version.Build;
    nextVer[3] = version.Revision < 0 ? 0 : version.Revision;
    var major = version.Major < 0 ? 0 : version.Major;
    var minor = version.Minor < 0 ? 0 : version.Minor;
    var build = version.Build < 0 ? 0 : version.Build;
    var revision = version.Revision < 0 ? 0 : version.Revision;

    version = new System.Version(nextVer[0], nextVer[1], nextVer[2], nextVer[3] + 1);
    version = new System.Version(major, minor, build, revision + 1);

    line = match.Groups[1].Value + version;

    @@ -81,6 +84,8 @@ public static void IncrementBuild(BuildTarget target, string buildPath) {

    if (success) {
    File.WriteAllLines(path, lines);
    } else {
    Debug.LogError("Couldn't find bundle version in ProjectSettings.asset");
    }
    }
    }
  6. @darktable darktable revised this gist Sep 8, 2012. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions IncrementBuildVersion.cs
    Original file line number Diff line number Diff line change
    @@ -60,8 +60,6 @@ public static void IncrementBuild(BuildTarget target, string buildPath) {

    var version = new System.Version(match.Groups[2].Value);

    Debug.Log(version.MajorRevision);

    var nextVer = new int[4];

    nextVer[0] = version.Major < 0 ? 0 : version.Major;
  7. @darktable darktable revised this gist Sep 8, 2012. 1 changed file with 12 additions and 2 deletions.
    14 changes: 12 additions & 2 deletions IncrementBuildVersion.cs
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ public static void IncrementBuild(BuildTarget target, string buildPath) {
    return;
    }

    string pattern = @"(^\s*iPhoneBundleVersion:\s*)([\d\.]+)$";
    string pattern = @"^(\s*iPhoneBundleVersion:\s*)([\d\.]+)$";
    bool success = false;

    for (int i=0; i<lines.Length; i++) {
    @@ -59,7 +59,17 @@ public static void IncrementBuild(BuildTarget target, string buildPath) {
    var match = Regex.Match(line, pattern);

    var version = new System.Version(match.Groups[2].Value);
    version = new System.Version(version.Major, version.Minor, version.Build, version.Revision + 1);

    Debug.Log(version.MajorRevision);

    var nextVer = new int[4];

    nextVer[0] = version.Major < 0 ? 0 : version.Major;
    nextVer[1] = version.Minor < 0 ? 0 : version.Minor;
    nextVer[2] = version.Build < 0 ? 0 : version.Build;
    nextVer[3] = version.Revision < 0 ? 0 : version.Revision;

    version = new System.Version(nextVer[0], nextVer[1], nextVer[2], nextVer[3] + 1);

    line = match.Groups[1].Value + version;

  8. @darktable darktable created this gist Sep 8, 2012.
    78 changes: 78 additions & 0 deletions IncrementBuildVersion.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,78 @@
    /* **************************************************************************
    Copyright 2012 Calvin Rien
    (http://the.darktable.com)
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    ************************************************************************** */

    using System.IO;
    using System.Text.RegularExpressions;
    using UnityEditor;
    using UnityEditor.Callbacks;
    using UnityEngine;

    public class IncrementBuildVersion : ScriptableObject {

    [MenuItem("Tools/Increment Build Number")]
    static void Init() {
    IncrementBuild(BuildTarget.iPhone, "");
    }

    [PostProcessBuild] // Requires Unity 3.5+
    public static void IncrementBuild(BuildTarget target, string buildPath) {
    if (!(target == BuildTarget.Android || target == BuildTarget.iPhone)) {
    return;
    }

    var path = Path.GetDirectoryName(Application.dataPath);
    path = Path.Combine(path, "ProjectSettings");
    path = Path.Combine(path, "ProjectSettings.asset");

    var lines = File.ReadAllLines(path);

    if (!lines[0].StartsWith("%YAML")) {
    Debug.LogError("Project settings file needs to be serialized as a text asset. (Check 'Project Settings->Editor')");
    return;
    }

    string pattern = @"(^\s*iPhoneBundleVersion:\s*)([\d\.]+)$";
    bool success = false;

    for (int i=0; i<lines.Length; i++) {
    var line = lines[i];

    if (!Regex.IsMatch(line, pattern)) {
    continue;
    }

    var match = Regex.Match(line, pattern);

    var version = new System.Version(match.Groups[2].Value);
    version = new System.Version(version.Major, version.Minor, version.Build, version.Revision + 1);

    line = match.Groups[1].Value + version;

    lines[i] = line;
    success = true;

    Debug.Log("Next version number: " + version);

    break;
    }

    if (success) {
    File.WriteAllLines(path, lines);
    }
    }
    }