192 lines
6.4 KiB
C#
192 lines
6.4 KiB
C#
using NLog;
|
|
using Server.System;
|
|
using System.Diagnostics;
|
|
|
|
namespace Server.Git
|
|
{
|
|
public abstract class AbstractGit
|
|
{
|
|
public Crypto crypto = new Crypto();
|
|
private static readonly NLog.ILogger logger = LogManager.GetCurrentClassLogger();
|
|
public bool isRestart;
|
|
string _repositoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "excel");
|
|
|
|
public List<Sheet> sheets;
|
|
|
|
public string repositoryPath { get { return _repositoryPath; } }
|
|
|
|
/// <summary>
|
|
/// 가장먼저 시작해야 하는 스크립트
|
|
/// </summary>
|
|
public void Init()
|
|
{
|
|
restart:
|
|
isRestart = false;
|
|
Pull();
|
|
if (isRestart)
|
|
goto restart;
|
|
string excel = ChangeScript();
|
|
if (isRestart)
|
|
goto restart;
|
|
Push(excel);
|
|
if (isRestart)
|
|
goto restart;
|
|
DataSet();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 엑셀 불러오기, 저장, 혹은 배포 까지 작업해야하는 함수
|
|
/// </summary>
|
|
public abstract string ChangeScript();
|
|
|
|
private void Pull()
|
|
{
|
|
if (!Directory.Exists(_repositoryPath))
|
|
{
|
|
Directory.CreateDirectory(_repositoryPath);
|
|
RepositorySet($"clone {Statics.remoteUrl} {_repositoryPath}", null);
|
|
|
|
//main브렌치로 세팅
|
|
RepositorySet("branch -m main", _repositoryPath);
|
|
RepositorySet("branch --set-upstream-to=origin/main main", _repositoryPath);
|
|
}
|
|
|
|
// pull 명령어 실행
|
|
RepositorySet("pull", _repositoryPath);
|
|
}
|
|
|
|
private static void RepositorySet(string command, string workingDirectory)
|
|
{
|
|
ProcessStartInfo psi = new ProcessStartInfo
|
|
{
|
|
FileName = "git",
|
|
Arguments = command,
|
|
WorkingDirectory = workingDirectory,
|
|
RedirectStandardOutput = true,
|
|
RedirectStandardError = true,
|
|
UseShellExecute = false,
|
|
CreateNoWindow = true,
|
|
EnvironmentVariables = { ["GIT_ASKPASS"] = "echo" }
|
|
};
|
|
using (Process process = new Process { StartInfo = psi })
|
|
{
|
|
process.Start();
|
|
process.WaitForExit();
|
|
|
|
// Git 명령 실행 결과 출력
|
|
logger.Info(process.StandardOutput.ReadToEnd());
|
|
}
|
|
}
|
|
|
|
private void Push(string excel)
|
|
{
|
|
if (excel == "")
|
|
{
|
|
return;
|
|
}
|
|
|
|
//json 저장
|
|
using (StreamWriter writer = new StreamWriter(repositoryPath + @"/excel.json"))
|
|
{
|
|
writer.Write(excel);
|
|
logger.Info($"save file : {repositoryPath + @"/excel.json"}");
|
|
}
|
|
//이곳에서 json변경후 저장
|
|
//압축
|
|
//string EncryptoExcel = crypto.Compress(excel);
|
|
//암호화
|
|
ProtocolProcessor.cryptoData = crypto.Compress(excel);
|
|
|
|
// 스테이징
|
|
RepositorySet("add .", repositoryPath);
|
|
|
|
// 커밋
|
|
RepositorySet($"commit -m \"update excel data\"", repositoryPath);
|
|
|
|
// 푸시
|
|
RepositorySet("push origin main", repositoryPath);
|
|
|
|
|
|
logger.Info("version : " + ProtocolProcessor.version);
|
|
if (ProtocolProcessor.version == "")
|
|
{
|
|
ProtocolProcessor.version = Statics.dynamicDataSQL.SelectName("version").value;
|
|
logger.Info("Select version : " + ProtocolProcessor.version);
|
|
}
|
|
else
|
|
{
|
|
Statics.dynamicDataSQL.Update(1, ProtocolProcessor.version);
|
|
logger.Info("Update version : " + ProtocolProcessor.version);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 모든 파일리스트 반환
|
|
/// </summary>
|
|
/// <param name="directoryPath">검색할 폴더 경로</param>
|
|
/// <param name="extension">확장자</param>
|
|
/// <returns></returns>
|
|
public List<string> GetFiles(string directoryPath, string extension)
|
|
{
|
|
List<string> xlsxFileList = new List<string>();
|
|
|
|
try
|
|
{
|
|
string[] files = Directory.GetFiles(directoryPath);
|
|
|
|
foreach (string file in files)
|
|
{
|
|
if (Path.GetExtension(file).Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
xlsxFileList.Add(file);
|
|
}
|
|
}
|
|
|
|
string[] subdirectories = Directory.GetDirectories(directoryPath);
|
|
foreach (string subdirectory in subdirectories)
|
|
{
|
|
//git시스템 파일은 뛰어넘기
|
|
if (subdirectory == directoryPath + "\\.git")
|
|
continue;
|
|
|
|
//제귀
|
|
xlsxFileList.AddRange(GetFiles(subdirectory, extension));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
}
|
|
|
|
return xlsxFileList;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 엑셀 데이터 저장
|
|
/// </summary>
|
|
public void DataSet()
|
|
{
|
|
int index = -1;
|
|
index = sheets.FindIndex(n => n.name == Statics.equipmentExcel.sheetName);
|
|
if(index != -1)
|
|
Statics.equipmentExcel.init(sheets[index]);
|
|
index = sheets.FindIndex(n => n.name == Statics.randomRewardExcel.sheetName);
|
|
if (index != -1)
|
|
Statics.randomRewardExcel.init(sheets[index]);
|
|
index = sheets.FindIndex(n => n.name == Statics.rewardExcel.sheetName);
|
|
if (index != -1)
|
|
Statics.rewardExcel.init(sheets[index]);
|
|
index = sheets.FindIndex(n => n.name == Statics.shopItemExcel.sheetName);
|
|
if (index != -1)
|
|
Statics.shopItemExcel.init(sheets[index]);
|
|
index = sheets.FindIndex(n => n.name == Statics.consumableItemExcel.sheetName);
|
|
if (index != -1)
|
|
Statics.consumableItemExcel.init(sheets[index]);
|
|
index = sheets.FindIndex(n => n.name == Statics.resetShopItemExcel.sheetName);
|
|
if (index != -1)
|
|
Statics.resetShopItemExcel.init(sheets[index]);
|
|
}
|
|
}
|
|
}
|