Skip to content

Commit

Permalink
Initial implementation of itchio upload.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaser324 committed May 4, 2016
1 parent 5121667 commit 58183f8
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 8 deletions.
135 changes: 135 additions & 0 deletions Editor/Upload/UploadItch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using UnityEngine;
using UnityEditor;
using System.IO;

namespace UnityBuild
{

public class UploadItch : PostBuildAction
{
private const string WINDOWS = "windows";
private const string OSX = "osx";
private const string LINUX = "linux";

#region MenuItems

[MenuItem("Build/Upload/itch.io/Execute", false, 50)]
private static void UploadAll()
{
for (int i = 0; i < BuildProject.platforms.Count; i++)
{
BuildPlatform platform = BuildProject.platforms[i];
PerformUpload(platform);
}
}

[MenuItem("Build/Upload/itch.io/Auto Upload")]
private static void ToggleAutoUpload()
{
EditorPrefs.SetBool("buildUploadItchAuto", !EditorPrefs.GetBool("buildUploadItchAuto", false));
}

[MenuItem("Build/Upload/itch.io/Auto Upload", true)]
private static bool ToggleAutoUploadValidate()
{
Menu.SetChecked("Build/Upload/itch.io/Auto Upload", EditorPrefs.GetBool("buildUploadItchAuto", false));
return true;
}

#endregion

#region Public Methods

public override void Execute(BuildPlatform platform)
{
if (EditorPrefs.GetBool("buildUploadItchAuto", false))
PerformUpload(platform);
}

#endregion

#region Private Methods

private static void PerformUpload(BuildPlatform platform)
{
if (!platform.buildEnabled)
return;

string absolutePath = Path.GetFullPath(platform.buildPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);

if (File.Exists(absolutePath))
{
Debug.Log("UploadItch: Upload Failed - Build does not exist for platform " + platform.name + " - " + absolutePath);
return;
}

string channel = GetChannelName(platform.target);
if (string.IsNullOrEmpty(channel))
{
Debug.Log("UploadItch: Upload Failed - Unknown platform " + platform.name);
return;
}

string arguments = "push \"" + absolutePath + "\" " + UploadItchSettings.itchUserName + "/" + UploadItchSettings.itchGameName + ":" + channel;

if (!string.IsNullOrEmpty(UploadItchSettings.versionNumber))
{
arguments += "--userversion " + UploadItchSettings.versionNumber;
}

System.Diagnostics.Process uploadProc = new System.Diagnostics.Process();
uploadProc.StartInfo.FileName = UploadItchSettings.butlerPath;
uploadProc.StartInfo.Arguments =
arguments;
uploadProc.StartInfo.CreateNoWindow = false;
uploadProc.StartInfo.UseShellExecute = false;
uploadProc.Start();
}

private static string GetChannelName(BuildTarget target)
{
switch (target)
{
// Windows
case BuildTarget.StandaloneWindows:
return WINDOWS + "-x86";
case BuildTarget.StandaloneWindows64:
return WINDOWS + "-x64";

// Linux
case BuildTarget.StandaloneLinux:
return LINUX + "-x86";
case BuildTarget.StandaloneLinux64:
return LINUX + "-x64";
case BuildTarget.StandaloneLinuxUniversal:
return LINUX + "-universal";

// OSX
case BuildTarget.StandaloneOSXIntel:
return OSX + "-intel";
case BuildTarget.StandaloneOSXIntel64:
return OSX + "-intel64";
case BuildTarget.StandaloneOSXUniversal:
return OSX + "-universal";

default:
return null;
}
}

#endregion

#region Public Properties

public override int priority
{
get
{
return 1000;
}
}

#endregion
}

}
12 changes: 12 additions & 0 deletions Editor/Upload/UploadItch.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions Editor/Upload/UploadItchSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using UnityEngine;
using UnityEditor;

public class UploadItchSettings
{
#region Constants

private const string _butlerPath = @"D:\User\Chase\Downloads\game-dev\butler\butler.exe";
private const string _itchUserName = "supersystems";
private const string _itchGameName = "butler-test";

#endregion

#region Public Properties

public static string versionNumber
{
get
{
return string.Empty;
}
}

public static string butlerPath
{
get
{
return _butlerPath;
}
}

public static string itchUserName
{
get
{
return _itchUserName;
}
}

public static string itchGameName
{
get
{
return _itchGameName;
}
}

#endregion
}
12 changes: 12 additions & 0 deletions Editor/Upload/UploadItchSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file removed Editor/Upload/blank.txt
Empty file.
8 changes: 0 additions & 8 deletions Editor/Upload/blank.txt.meta

This file was deleted.

0 comments on commit 58183f8

Please sign in to comment.