- First Update

This commit is contained in:
2022-03-07 14:35:38 +09:00
parent 1ab1cfd4ea
commit f53695b228
48 changed files with 17003 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{57098662-9A1B-45E7-B932-5299343629F2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CommonLibrary</RootNamespace>
<AssemblyName>CommonLibrary</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.IO.Compression.ZipFile" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataModel.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Log.cs" />
<Compile Include="Packer.cs" />
<Compile Include="XMLSystem.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CommonLibrary
{
[Serializable]
public struct LauncherPatchInformation // 런처 패치정보
{
public string Version { get; set; } // 런처 버전
public string LauncherUrl { get; set; } // 런처 URL
public string LauncherFileName { get; set; } // 런처 파일명
}
[Serializable]
public struct DataPatchInformation // 패치데이터 정보
{
public string RuntimeVersion { get; set; } // 런타임(자바) 버전
public string RuntimeUrl { get; set; } // 런타임(자바) URL
public string RuntimeFileName { get; set; } // 런타임(자바) 파일명
public string PackageVersion { get; set; } // 패키지(기본데이터) 버전
public string PackageUrl { get; set; } // 패키지(기본데이터) URL
public string PackageFileName { get; set; } // 패키지(기본데이터) 파일명
public List<string> PackageDirectorys { get; set; } // 패키지(기본데이터) 폴더들
public string ComponentVersion { get; set; } // 컴포넌트(패키지외) 버전
public string ComponentUrl { get; set; } // 컴포넌트(패키지외) URl
public List<string> ComponentDirectorys { get; set; } // 패키지(패키지외) 파일명
public List<FileDetail> ComponentList { get; set; } // 컴포넌트(패키지외) 폴더 리스트
}
[Serializable]
public struct FileDetail
{
public string Directory { get; set; }
public string FileName { get; set; }
public long FileSize { get; set; }
public string HashCode { get; set; }
}
}

View File

@@ -0,0 +1,57 @@
using System.Text;
namespace CommonLibrary
{
public static class Extensions
{
public static string PathCombineL(params string[] paths)
{
string directorySeparatorChar = System.IO.Path.AltDirectorySeparatorChar.ToString();
return PathCombine(directorySeparatorChar, paths).Replace("\\", "/");
}
public static string PathCombineW(params string[] paths)
{
string directorySeparatorChar = System.IO.Path.DirectorySeparatorChar.ToString();
return PathCombine(directorySeparatorChar, paths).Replace("/", "\\");
}
private static string PathCombine(string directorySeparator, params string[] paths)
{
if (paths.Length == 0)
{
return string.Empty;
}
StringBuilder path = new StringBuilder();
path.Append(paths[0]);
for (int i = 1; i < paths.Length; i++)
{
if (path.ToString().Substring(path.Length - 1, 1) == directorySeparator)
{
if (paths[i].Substring(0, 1) == directorySeparator)
{
path.Append(paths[i].Substring(1, paths[i].Length - 1));
}
else
{
path.Append(paths[i]);
}
}
else
{
if (paths[i].Substring(0, 1) == directorySeparator)
{
path.Append(paths[i]);
}
else
{
path.Append(directorySeparator);
path.Append(paths[i]);
}
}
}
return path.ToString();
}
}
}

175
CommonLibrary/Log.cs Normal file
View File

@@ -0,0 +1,175 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace CommonLibrary
{
public static class Log
{
//로그파일 이름 규칙 어셈블리명-날짜.log
public static LogLevel logLevel { get; set; }
private static string logDateTime;
static Log()
{
SetLogFile(DateTime.Now.ToString("yyyy-MM-dd")); // Log파일 이름 세팅을 위한 함수 호출
logLevel = LogLevel.Info;
}
/// <summary>
/// 로그 파일 리스너 세팅
/// </summary>
/// <param name="dateTimeString">로그파일 이름에 들어갈 DateTime String</param>
private static void SetLogFile(string dateTimeString)
{
logDateTime = dateTimeString;
if (!System.IO.Directory.Exists("logs"))
{
System.IO.Directory.CreateDirectory("logs");
}
var logFileName = $"logs\\{logDateTime}.log";
Trace.Listeners.Clear();
Trace.Listeners.Add(new TextWriterTraceListener(new FileStream(logFileName, FileMode.Append, FileAccess.Write, FileShare.Read)));
Trace.Write("====================================================================================================// ");
Trace.Write(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Trace.WriteLine(" //====================================================================================================");
Trace.Flush();
}
//FATAL > ERROR > WARN > INFO > DEBUG > TRACE
public static void FATAL(string message)
{
if (LogLevel.FATAL >= logLevel)
{
// Call Location
var stackTrace = new StackTrace();
var methodBase = stackTrace.GetFrame(1).GetMethod();
string location = methodBase.DeclaringType != null
? methodBase.DeclaringType.Name + "/"
: "null/";
location += methodBase.Name;
// Call Location End
WriteLog(LogLevel.FATAL, location + "\t" + message);
}
}
public static void ERROR(string message)
{
if (LogLevel.Error >= logLevel)
{
// Call Location
var stackTrace = new StackTrace();
var methodBase = stackTrace.GetFrame(1).GetMethod();
string location = methodBase.DeclaringType != null
? methodBase.DeclaringType.Name + "/"
: "null/";
location += methodBase.Name;
// Call Location End
WriteLog(LogLevel.Error, location + "\t" + message);
}
}
public static void WARN(string message)
{
if (LogLevel.Warn >= logLevel)
{
// Call Location
var stackTrace = new StackTrace();
var methodBase = stackTrace.GetFrame(1).GetMethod();
string location = methodBase.DeclaringType != null
? methodBase.DeclaringType.Name + "/"
: "null/";
location += methodBase.Name;
// Call Location End
WriteLog(LogLevel.Warn, location + "\t" + message);
}
}
public static void INFO(string message)
{
if (LogLevel.Info >= logLevel)
{
// Call Location
var stackTrace = new StackTrace();
var methodBase = stackTrace.GetFrame(1).GetMethod();
string location = methodBase.DeclaringType != null
? methodBase.DeclaringType.Name + "/"
: "null/";
location += methodBase.Name;
// Call Location End
WriteLog(LogLevel.Info, location + "\t" + message);
}
}
public static void DEBUG(string message)
{
if (LogLevel.Debug >= logLevel)
{
// Call Location
var stackTrace = new StackTrace();
var methodBase = stackTrace.GetFrame(1).GetMethod();
string location = methodBase.DeclaringType != null
? methodBase.DeclaringType.Name + "/"
: "null/";
location += methodBase.Name;
// Call Location End
WriteLog(LogLevel.Debug, location + "\t" + message);
}
}
public static void TRACE(string message)
{
if (LogLevel.Trace >= logLevel)
{
var stackTrace = new StackTrace();
var methodBase = stackTrace.GetFrame(1).GetMethod();
string location = methodBase.DeclaringType != null
? methodBase.DeclaringType.Name + "/"
: "null/";
location += methodBase.Name;
// Call Location End
WriteLog(LogLevel.Debug, location + "\t" + message);
WriteLog(LogLevel.Trace, message);
}
}
/// <summary>
///
/// </summary>
/// <param name="logLevel">enum LogLevel</param>
/// <param name="message">로그 메세지</param>
private static void WriteLog(LogLevel logLevel, string message)
{
string nowDateTime = DateTime.Now.ToString("yyyy-MM-dd");
if (nowDateTime != logDateTime)
{
SetLogFile(nowDateTime);
}
// Log String
var stringBuilder = new StringBuilder();
stringBuilder.Append("[");
stringBuilder.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
stringBuilder.Append("]");
stringBuilder.Append("\t");
stringBuilder.Append(logLevel);
stringBuilder.Append("\t");
stringBuilder.Append(message.Trim());
Trace.WriteLine(stringBuilder.ToString());
Trace.Flush();
}
}
public enum LogLevel
{
Trace,
Debug,
Info,
Warn,
Error,
FATAL
}
}

147
CommonLibrary/Packer.cs Normal file
View File

@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.IO.Compression;
namespace CommonLibrary
{
internal class ProgressStream : Stream
{
private readonly Stream insideStream;
private readonly IProgress<int> insideReadProgress;
private readonly IProgress<int> insideWriteProgress;
public ProgressStream(Stream stream, IProgress<int> readProgress, IProgress<int> writeProgress)
{
insideStream = stream;
insideReadProgress = readProgress;
insideWriteProgress = writeProgress;
}
public override bool CanRead { get { return insideStream.CanRead; } }
public override bool CanSeek { get { return insideStream.CanSeek; } }
public override bool CanWrite { get { return insideStream.CanWrite; } }
public override long Length { get { return insideStream.Length; } }
public override long Position
{
get { return insideStream.Position; }
set { insideStream.Position = value; }
}
public override void Flush()
{
insideStream.Flush();
}
public override long Seek(long offset, SeekOrigin origin)
{
return insideStream.Seek(offset, origin);
}
public override void SetLength(long value)
{
insideStream.SetLength(value);
}
public override int Read(byte[] buffer, int offset, int count)
{
int bytesRead = insideStream.Read(buffer, offset, count);
insideReadProgress?.Report(bytesRead);
return bytesRead;
}
public override void Write(byte[] buffer, int offset, int count)
{
insideStream.Write(buffer, offset, count);
insideWriteProgress?.Report(count);
}
}
public class ProgressPacker
{
public void Pack(string sourceDirectoryName, string packFileName, IProgress<double> progress)
{
sourceDirectoryName = Path.GetFullPath(sourceDirectoryName);
FileInfo[] sourceFiles = new DirectoryInfo(sourceDirectoryName).GetFiles("*", SearchOption.AllDirectories);
double totalBytes = sourceFiles.Sum(f => f.Length);
long currentBytes = 0;
using (ZipArchive zipArchive = ZipFile.Open(packFileName, ZipArchiveMode.Create))
{
foreach (FileInfo file in sourceFiles)
{
string entryName = file.FullName.Substring(sourceDirectoryName.Length + 1);
ZipArchiveEntry entry = zipArchive.CreateEntry(entryName);
entry.LastWriteTime = file.LastWriteTime;
using (Stream inputStream = file.OpenRead())
{
using (Stream outputStream = entry.Open())
{
Stream progressStream = new ProgressStream(inputStream,
new BasicProgress<int>(i =>
{
currentBytes += i;
progress.Report(currentBytes / totalBytes);
}), null);
progressStream.CopyTo(outputStream);
}
}
}
}
}
public void UnPack(string packFileName, string destinationDirectoryName, IProgress<double> progress)
{
using (ZipArchive zipArchive = ZipFile.OpenRead(packFileName))
{
double totalBytes = zipArchive.Entries.Sum(f => f.Length);
long currentBytes = 0;
foreach (ZipArchiveEntry entry in zipArchive.Entries)
{
string fileName = Path.Combine(destinationDirectoryName, entry.FullName);
if (entry.Name == "") continue;
Directory.CreateDirectory(Path.GetDirectoryName(fileName));
using (Stream inputStream = entry.Open())
{
using (Stream outputStream = File.OpenWrite(fileName))
{
Stream progressStream = new ProgressStream(outputStream, null,
new BasicProgress<int>(i =>
{
currentBytes += i;
progress.Report(currentBytes / totalBytes);
}));
inputStream.CopyTo(progressStream);
}
File.SetLastWriteTime(fileName, entry.LastWriteTime.LocalDateTime);
}
}
}
}
}
public class BasicProgress<T> : IProgress<T>
{
private readonly Action<T> actionHandler;
public BasicProgress(Action<T> handler)
{
actionHandler = handler;
}
void IProgress<T>.Report(T value)
{
actionHandler(value);
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("CommonLibrary")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CommonLibrary")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("57098662-9a1b-45e7-b932-5299343629f2")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,84 @@
using System;
using System.IO;
using System.Xml.Serialization;
namespace CommonLibrary
{
public static class XMLSystem
{
public static bool Save<T>(string path, T data) where T : struct
{
if (string.IsNullOrWhiteSpace(path))
{
return false;
}
string directory = Path.GetDirectoryName(System.IO.Path.GetFullPath(path));
if (!System.IO.Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
using (StreamWriter sw = new StreamWriter(path))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces();
xmlSerializerNamespaces.Add("", "");
xmlSerializer.Serialize(sw, data, xmlSerializerNamespaces);
sw.Close();
}
return true;
}
public static T LoadFromPath<T>(string path) where T : struct
{
if (string.IsNullOrWhiteSpace(path))
{
return default;
}
string directory = Path.GetDirectoryName(System.IO.Path.GetFullPath(path));
if (!System.IO.Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
if (!File.Exists(path))
{
return default;
}
using (StreamReader sr = new StreamReader(path))
{
try
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
T data = (T)xmlSerializer.Deserialize(sr);
return data;
}
catch (Exception ex)
{
CommonLibrary.Log.ERROR(ex.Message);
return default;
}
}
}
public static T LoadFromData<T>(string data) where T : struct
{
if (string.IsNullOrWhiteSpace(data))
{
return default;
}
using (StringReader sr = new StringReader(data))
{
try
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
return (T)xmlSerializer.Deserialize(sr);
}
catch (Exception ex)
{
CommonLibrary.Log.ERROR(ex.Message);
return default;
}
}
}
}
}