SquareDash/Library/PackageCache/com.unity.services.mediation@1.0.5/Editor/Build/FileContentAppender.cs
kingjuulian06 0efb85038a Arbeit 2
2023-11-21 22:03:49 +01:00

49 lines
1.5 KiB
C#

#if UNITY_ANDROID
using System;
using System.IO;
using System.Text.RegularExpressions;
using Unity.Services.Mediation;
using UnityEngine;
namespace Unity.Mediation.Build.Editor
{
static class FileContentAppender
{
const string k_ReadFileError = "Issue reading gradle properties file. Aborting UpdateDependencies patch.";
const string k_WriteFileError = "Issue writing gradle properties file. Aborting UpdateDependencies patch.";
internal static bool AppendContentToFile(string filePath, string appendContent, string regex)
{
var buildGradleContents = "";
try
{
buildGradleContents = File.ReadAllText(filePath);
}
catch (Exception)
{
MediationLogger.Log(k_ReadFileError);
return false;
}
var settingPresentRegex = new Regex(regex,
RegexOptions.Compiled | RegexOptions.IgnoreCase);
if (!settingPresentRegex.IsMatch(buildGradleContents))
{
buildGradleContents += appendContent;
try
{
File.WriteAllText(filePath, buildGradleContents);
}
catch (Exception)
{
MediationLogger.Log(k_WriteFileError);
return false;
}
return true;
}
return false;
}
}
}
#endif