Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

location UI Started #96

Merged
merged 1 commit into from
Oct 4, 2023
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions Assets/GPM.meta

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

8 changes: 8 additions & 0 deletions Assets/GPM/Common.meta

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

8 changes: 8 additions & 0 deletions Assets/GPM/Common/Compress.meta

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

8 changes: 8 additions & 0 deletions Assets/GPM/Common/Compress/Editor.meta

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

35 changes: 35 additions & 0 deletions Assets/GPM/Common/Compress/Editor/GpmCompress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Gpm.Common.Compress.Internal;

namespace Gpm.Common.Compress
{
public enum CompressResultCode
{
SUCCESS,
ERROR_EXTRACT,
ERROR_REMAP,
NOT_SUPPORT_PLATFORM,
NOT_FOUND_EXTRACT_APP,
}

public enum CompressFormat
{
SEVEN_ZIP,
GZIP,
TAR,
ZIP,
TAR_GZ,
}

public static class GpmCompress
{
public static CompressResultCode Extract(string filePath, string outputPath, CompressFormat format)
{
return CompressImplementation.Extract(filePath, outputPath, format);
}

public static CompressResultCode ExtractUnityPackage(string packagePath, string tempPath, string resultPath)
{
return CompressImplementation.UnityPackage.Unpack(packagePath, tempPath, resultPath);
}
}
}
11 changes: 11 additions & 0 deletions Assets/GPM/Common/Compress/Editor/GpmCompress.cs.meta

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

8 changes: 8 additions & 0 deletions Assets/GPM/Common/Compress/Editor/Internal.meta

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

220 changes: 220 additions & 0 deletions Assets/GPM/Common/Compress/Editor/Internal/CompressImplementation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using Gpm.Common.Util;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;




namespace Gpm.Common.Compress.Internal
{
#if CSHARP_7_3_OR_NEWER
using ThirdParty.SharpCompress.Common;
using ThirdParty.SharpCompress.Readers;
#endif

internal static class CompressImplementation
{
#if UNITY_EDITOR_OSX
private static readonly string COMPRESS_PROGRAM_PATH = Path.Combine(Path.GetDirectoryName(EditorApplication.applicationContentsPath), "Contents/Tools/7za");
#elif UNITY_EDITOR_WIN
private static readonly string COMPRESS_PROGRAM_PATH = Path.Combine(Path.GetDirectoryName(EditorApplication.applicationPath), "Data/Tools/7z.exe");
#endif

private static Dictionary<CompressFormat, string> formatExtensions = new Dictionary<CompressFormat, string>
{
{ CompressFormat.SEVEN_ZIP, "7z" },
{ CompressFormat.GZIP, "gzip" },
{ CompressFormat.TAR, "tar" },
{ CompressFormat.ZIP, "zip" }
};
#if CSHARP_7_3_OR_NEWER
internal static CompressResultCode ExtractCode(string filePath, string outputPath)
{
if (Directory.Exists(outputPath) == true)
{
Directory.Delete(outputPath, true);
}

if (Directory.Exists(outputPath) == false)
{
Directory.CreateDirectory(outputPath);
}

try
{
using (var stream = File.OpenRead(filePath))
{
var reader = ReaderFactory.Open(stream);
while (reader.MoveToNextEntry() == true)
{
if (!reader.Entry.IsDirectory)
{
reader.WriteEntryToDirectory(outputPath, new ExtractionOptions()
{
ExtractFullPath = true,
Overwrite = true
});
}
}
}
}
catch (Exception e)
{
UnityEngine.Debug.LogError(string.Format("Extract process error (Message: {0})", e.Message));
return CompressResultCode.ERROR_EXTRACT;
}

return CompressResultCode.SUCCESS;
}
#endif
internal static CompressResultCode Extract(string filePath, string outputPath, CompressFormat format)
{
#if !UNITY_EDITOR_OSX && !UNITY_EDITOR_WIN
return CompressResultCode.NOT_SUPPORT_PLATFORM;
#else
if (File.Exists(COMPRESS_PROGRAM_PATH) == false)
{
throw new FileNotFoundException("Compress executable program", COMPRESS_PROGRAM_PATH);
}

if (Directory.Exists(outputPath) == true)
{
Directory.Delete(outputPath, true);
}

var systemEncoding = Encoding.GetEncoding(CultureInfo.CurrentCulture.TextInfo.OEMCodePage);

var startInfo = new ProcessStartInfo
{
#if UNITY_EDITOR_OSX
FileName = "/bin/bash",
#elif UNITY_EDITOR_WIN
FileName = "cmd.exe",
#endif
Arguments = GetExtractArgument(format, filePath, outputPath),
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = Application.dataPath + "/..",
StandardOutputEncoding = systemEncoding,
StandardErrorEncoding = systemEncoding
};

using (var process = Process.Start(startInfo))
{
try
{
process.WaitForExit();
int exitCode = process.ExitCode;
string stdout = process.StandardOutput.ReadToEnd();
string stderr = process.StandardError.ReadToEnd();

if (exitCode != 0)
{
UnityEngine.Debug.LogError(string.Format("Extract process error (Arguments: {0}, ExitCode: {1}, Output: {2}, Error: {3})", startInfo.Arguments, exitCode, stdout, stderr));
return CompressResultCode.ERROR_EXTRACT;
}
}
catch (Exception e)
{
UnityEngine.Debug.LogError(string.Format("Extract process error (Message: {0})", e.Message));
return CompressResultCode.ERROR_EXTRACT;
}
}

return CompressResultCode.SUCCESS;
#endif
}

private static string GetExtractArgument(CompressFormat format, string filePath, string outputPath)
{
#if !UNITY_EDITOR_OSX && !UNITY_EDITOR_WIN
return string.Empty;
#else
if (format == CompressFormat.TAR_GZ)
{
#if UNITY_EDITOR_OSX
return string.Format(@"-c ""'{0}' x '{1}' -so | '{0}' x -aoa -si -ttar -o'{2}'""", COMPRESS_PROGRAM_PATH, filePath, outputPath);
#elif UNITY_EDITOR_WIN
return string.Format(@"/c """"{0}"" x ""{1}"" -so | ""{0}"" x -aoa -si -ttar -o""{2}""""", COMPRESS_PROGRAM_PATH, filePath, outputPath);
#endif
}

#if UNITY_EDITOR_OSX
return string.Format(@"-c ""'{0}' x '{1}' -t{3} -o'{2}'""", COMPRESS_PROGRAM_PATH, filePath, outputPath, formatExtensions[format]);
#elif UNITY_EDITOR_WIN
return string.Format(@"/c """"{0}"" x ""{1}"" -t{3} -o""{2}""""", COMPRESS_PROGRAM_PATH, filePath, outputPath, formatExtensions[format]);
#endif

#endif
}

public static class UnityPackage
{
public static CompressResultCode Unpack(string packagePath, string tempPath, string resultPath)
{
#if !UNITY_EDITOR_OSX && !UNITY_EDITOR_WIN
return CompressResultCode.NOT_SUPPORT_PLATFORM;
#else
string filename = Path.GetFileNameWithoutExtension(packagePath);
string tempFullPath = GpmPathUtil.Combine(tempPath, filename);

#if CSHARP_7_3_OR_NEWER
CompressResultCode extractResultCode = ExtractCode(packagePath, tempFullPath);
#else
CompressResultCode extractResultCode = Extract(packagePath, tempFullPath, CompressFormat.TAR_GZ);
#endif
if (extractResultCode != CompressResultCode.SUCCESS)
{
return extractResultCode;
}

if (RemapPackageToAsset(tempFullPath, resultPath) == false)
{
return CompressResultCode.ERROR_REMAP;
}

return CompressResultCode.SUCCESS;
}

private static bool RemapPackageToAsset(string originPath, string outputPath)
{
outputPath = outputPath.Replace('/', Path.DirectorySeparatorChar);

try
{
foreach (var directoryInfo in new DirectoryInfo(originPath).GetDirectories())
{
var remapPath = File.ReadAllLines(GpmPathUtil.Combine(directoryInfo.FullName, "pathname")).First();
remapPath = remapPath.Replace('/', Path.DirectorySeparatorChar);

var assetFilePath = GpmPathUtil.Combine(directoryInfo.FullName, "asset");
var metaFilePath = GpmPathUtil.Combine(directoryInfo.FullName, "asset.meta");

GpmFileUtil.MoveFile(assetFilePath, GpmPathUtil.Combine(outputPath, remapPath));
GpmFileUtil.MoveFile(metaFilePath, GpmPathUtil.Combine(outputPath, string.Format("{0}.meta", remapPath)));
}
}
catch (Exception e)
{
UnityEngine.Debug.LogError(string.Format("Remap unity package to asset error (Message: {0})", e.Message));
return false;
}

return true;
#endif
}
}

}
}

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

8 changes: 8 additions & 0 deletions Assets/GPM/Common/GpmCommon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Gpm.Common
{
public static class GpmCommon
{
public const string VERSION = "2.3.1";
public static bool DebugLogEnabled { get; set; }
}
}
11 changes: 11 additions & 0 deletions Assets/GPM/Common/GpmCommon.cs.meta

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

8 changes: 8 additions & 0 deletions Assets/GPM/Common/Indicator.meta

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

8 changes: 8 additions & 0 deletions Assets/GPM/Common/Indicator/Scripts.meta

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

15 changes: 15 additions & 0 deletions Assets/GPM/Common/Indicator/Scripts/GpmIndicator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Gpm.Common.Indicator.Internal;
using System.Collections.Generic;

namespace Gpm.Common.Indicator
{
public sealed class GpmIndicator
{
public const string SERVICE_NAME = "Indicator";

public static void Send(string serviceName, string serviceVersion, Dictionary<string, string> customData, bool ignoreActivation = false)
{
IndicatorImplementation.Instance.Send(serviceName, serviceVersion, customData, ignoreActivation);
}
}
}
11 changes: 11 additions & 0 deletions Assets/GPM/Common/Indicator/Scripts/GpmIndicator.cs.meta

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

Loading
Loading