Skip to content

Commit

Permalink
Installer created for khernet.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemalcs committed Apr 3, 2021
1 parent dfd043f commit d9925f7
Show file tree
Hide file tree
Showing 87 changed files with 2,435 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>set bin_directory=..\..\..\..\..\..\bin\Khernet.Core
IF not exist %25lib_directory%25 mkdir %25bin_directory%25

copy /Y $(TargetDir) %25bin_directory%25</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
40 changes: 13 additions & 27 deletions Khernet.Core/Engine/Khernet.Core.Common/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public enum StorageType

public class Storage
{
public const string CONFIGURATION_FILE = "config";

public const string FIREBIRD_LIBRARY = "fbclient.dll";

public const string MESSAGE_DB = "msgdb";

public const string FILE_DB = "stgdb";

private readonly string dataFolder = "data";

/// <summary>
/// The path of file system where FIREBIRD engine is located.
/// </summary>
Expand All @@ -29,7 +39,7 @@ public string EngineAddress
get
{
var assembly = System.Reflection.Assembly.GetEntryAssembly();
return Path.Combine(Path.GetDirectoryName(assembly.Location), "dbin\\fbclient.dll");
return Path.Combine(Path.GetDirectoryName(assembly.Location), "firebird", "fbclient.dll");
}
}

Expand Down Expand Up @@ -57,7 +67,7 @@ public string RepoAddress
get
{
var assembly = System.Reflection.Assembly.GetEntryAssembly();
return Path.Combine(Path.GetDirectoryName(assembly.Location), "kdata\\E7FE8601FEAE.KND");
return Path.Combine(Path.GetDirectoryName(assembly.Location), this.dataFolder, MESSAGE_DB);
}
}

Expand All @@ -69,7 +79,7 @@ public string FileRepoAddress
get
{
var assembly = System.Reflection.Assembly.GetEntryAssembly();
return Path.Combine(Path.GetDirectoryName(assembly.Location), "kdata\\KL732418.KND");
return Path.Combine(Path.GetDirectoryName(assembly.Location), this.dataFolder, FILE_DB);
}
}

Expand All @@ -85,30 +95,6 @@ public string CacheAddress
}
}

/// <summary>
/// The path of file system where FFMPEG library is located.
/// </summary>
public string MediaToolsAddress
{
get
{
var assembly = System.Reflection.Assembly.GetEntryAssembly();
return Path.Combine(Path.GetDirectoryName(assembly.Location), "tls");
}
}

/// <summary>
/// The path of file system where VLC library is located.
/// </summary>
public string VLCLibX86Address
{
get
{
var assembly = System.Reflection.Assembly.GetEntryAssembly();
return Path.Combine(Path.GetDirectoryName(assembly.Location), "libvlc", "win-x86");
}
}

/// <summary>
/// Gets a connection string to a specific database based on <see cref="StorageType"/> enumeration.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\Khernet.App.Container.1.0.11\build\Khernet.App.Container.targets" Condition="Exists('..\..\packages\Khernet.App.Container.1.0.11\build\Khernet.App.Container.targets')" />
<Import Project="..\..\packages\Khernet.App.Container.1.1.0\build\Khernet.App.Container.targets" Condition="Exists('..\..\packages\Khernet.App.Container.1.1.0\build\Khernet.App.Container.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Este proyecto hace referencia a los paquetes NuGet que faltan en este equipo. Use la restauración de paquetes NuGet para descargarlos. Para obtener más información, consulte http://go.microsoft.com/fwlink/?LinkID=322105. El archivo que falta es {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Khernet.App.Container.1.0.11\build\Khernet.App.Container.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Khernet.App.Container.1.0.11\build\Khernet.App.Container.targets'))" />
<Error Condition="!Exists('..\..\packages\Khernet.App.Container.1.1.0\build\Khernet.App.Container.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Khernet.App.Container.1.1.0\build\Khernet.App.Container.targets'))" />
</Target>
<PropertyGroup>
<PostBuildEvent>set bin_directory=..\..\..\..\..\..\bin\Khernet.Core
IF not exist %25lib_directory%25 mkdir %25bin_directory%25

copy /Y $(TargetDir) %25bin_directory%25</PostBuildEvent>
</PropertyGroup>
</Project>
47 changes: 1 addition & 46 deletions Khernet.Core/Engine/Khernet.Core.Container/ResourceContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,12 @@ namespace Khernet.Core.Resources
{
public class ResourceContainer
{
/// <summary>
/// Get the configuration file (FIREBIRD database) for application.
/// </summary>
/// <returns>An array of bytes containing FIREBIRD database.</returns>
public byte[] GetConfigurationFile()
{
return GetResource("CONFIG_zip");
}

/// <summary>
/// Get the FIREBIRD database libraries.
/// </summary>
/// <returns>A <see cref="byte"/> array of zip file containing FIREBIRD libraries.</returns>
public byte[] GetDataBaseEngine()
{
return GetResource("FIREBIRD");
}

/// <summary>
/// Get the database to store data used by application for example: chat messages, contact list.
/// </summary>
/// <returns>A <see cref="byte"/> array of zip file containing database.</returns>
public byte[] GetApplicationDataBase()
{
return GetResource("KH_zip");
}

/// <summary>
/// Get FFMPEG libraries to read and write media files
/// </summary>
/// <returns>A <see cref="byte"/> array of zip file containing FFMPEG libraries</returns>
public byte[] GetMediaTools()
{
return GetResource("tls_zip");
}

/// <summary>
/// Get VLC libraries to play audio and video files.
/// </summary>
/// <returns>A <see cref="byte"/> array of zip file containing VLC libraries.</returns>
public byte[] GetVLCLibrary()
{
return GetResource("vlc_x86_zip");
}

/// <summary>
/// Gets a resource that is embedded into assembly.
/// </summary>
/// <param name="assetName">The name of resource to get.</param>
/// <returns>A <see cref="byte"/> array containing the resource.</returns>
private byte[] GetResource(string assetName)
public byte[] GetResource(string assetName)
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();

Expand Down
2 changes: 1 addition & 1 deletion Khernet.Core/Engine/Khernet.Core.Container/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Khernet.App.Container" version="1.0.11" targetFramework="net40" />
<package id="Khernet.App.Container" version="1.1.0" targetFramework="net40" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>set bin_directory=..\..\..\..\..\..\bin\Khernet.Core
IF not exist %25lib_directory%25 mkdir %25bin_directory%25

copy /Y $(TargetDir) %25bin_directory%25</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>set bin_directory=..\..\..\..\..\..\bin\Khernet.Core
IF not exist %25lib_directory%25 mkdir %25bin_directory%25

copy /Y $(TargetDir) %25bin_directory%25</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
86 changes: 8 additions & 78 deletions Khernet.Core/Engine/Khernet.Core.Host/RegionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,13 @@ private bool ValidateDatabase()

public void Build()
{
if (!ValidateDatabase())
{
InstallDatabaseEngine();
}
if (!ValidateDatabase())
{
CreateDatabases();
}
Storage storage = new Storage();
if (!Directory.Exists(storage.CacheAddress))
Directory.CreateDirectory(storage.CacheAddress);

if (!Directory.Exists(storage.MediaToolsAddress))
{
Directory.CreateDirectory(storage.MediaToolsAddress);
UnPackMediaTools();
}

if (!Directory.Exists(storage.VLCLibX86Address))
{
Directory.CreateDirectory(storage.VLCLibX86Address);
UnPackVLCLib();
}
}

public bool IsInitialized()
Expand All @@ -68,71 +52,41 @@ public bool IsInitialized()
return storage.VerifyInitialization();
}

private void InstallDatabaseEngine()
{
try
{
//Create folder to store FIREBIRD database engine files
Storage storage = new Storage();
string firebirdEnginePath = Path.GetDirectoryName(storage.EngineAddress);

if (!Directory.Exists(firebirdEnginePath))
{
Directory.CreateDirectory(firebirdEnginePath);
}

ResourceContainer rc = new ResourceContainer();

using (MemoryStream memStream = new MemoryStream(rc.GetDataBaseEngine()))
{
Compressor compressor = new Compressor();
compressor.UnZipFile(memStream, firebirdEnginePath);
}
}
catch (Exception exception)
{
LogDumper.WriteLog(exception);
throw;
}
}

private void CreateDatabases()
{
try
{
//Create database for configurations and a database to store data of application
Storage storage = new Storage();
string repositoryPath = Path.GetDirectoryName(storage.RepoAddress);

if (!Directory.Exists(repositoryPath))
{
Directory.CreateDirectory(repositoryPath);
}

//Rename the existing file if someone is found
RenameExistingFile(storage.ConfigAddress);

ResourceContainer rc = new ResourceContainer();

//Decompress ZIP file with configuration database
using (MemoryStream memStream = new MemoryStream(rc.GetConfigurationFile()))
using (MemoryStream memStream = new MemoryStream(rc.GetResource(Storage.CONFIGURATION_FILE)))
{
Compressor compressor = new Compressor();
compressor.UnZipFile(memStream, Path.GetDirectoryName(storage.ConfigAddress));

File.Move(Path.Combine(Path.GetDirectoryName(storage.ConfigAddress), "CONFIG"), storage.ConfigAddress);
File.Move(Path.Combine(Path.GetDirectoryName(storage.ConfigAddress), Storage.CONFIGURATION_FILE), storage.ConfigAddress);
}

//Rename the existing file if someone is found
RenameExistingFile(storage.RepoAddress);

//Decompress ZIP file with application database
using (MemoryStream memStream = new MemoryStream(rc.GetApplicationDataBase()))
using (MemoryStream memStream2 = new MemoryStream(rc.GetResource(Storage.MESSAGE_DB)))
{
Compressor compressor = new Compressor();
compressor.UnZipFile(memStream, Path.GetDirectoryName(storage.RepoAddress));

File.Move(Path.Combine(Path.GetDirectoryName(storage.RepoAddress), "KH"), storage.RepoAddress);
Compressor compressor2 = new Compressor();
compressor2.UnZipFile(memStream2, Path.GetDirectoryName(storage.RepoAddress));
File.Move(Path.Combine(Path.GetDirectoryName(storage.RepoAddress), Storage.MESSAGE_DB), storage.RepoAddress);
}
}
catch (Exception exception)
Expand All @@ -142,30 +96,6 @@ private void CreateDatabases()
}
}

private void UnPackMediaTools()
{
ResourceContainer rc = new ResourceContainer();
using (MemoryStream memStream = new MemoryStream(rc.GetMediaTools()))
{
Compressor compressor = new Compressor();
Storage storage = new Storage();

compressor.UnZipFile(memStream, storage.MediaToolsAddress);
}
}

private void UnPackVLCLib()
{
ResourceContainer rc = new ResourceContainer();
using (MemoryStream memStream = new MemoryStream(rc.GetVLCLibrary()))
{
Compressor compressor = new Compressor();
Storage storage = new Storage();

compressor.UnZipFile(memStream, storage.VLCLibX86Address);
}
}

private string RenameExistingFile(string fileName)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>set bin_directory=..\..\..\..\..\..\bin\Khernet.Core
IF not exist %25lib_directory%25 mkdir %25bin_directory%25

copy /Y $(TargetDir) %25bin_directory%25</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>set bin_directory=..\..\..\..\..\..\bin\Khernet.Core
IF not exist %25lib_directory%25 mkdir %25bin_directory%25

copy /Y $(TargetDir) %25bin_directory%25</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>set bin_directory=..\..\..\..\..\..\bin\Khernet.Core
IF not exist %25lib_directory%25 mkdir %25bin_directory%25

copy /Y $(TargetDir) %25bin_directory%25</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>set bin_directory=..\..\..\..\..\..\bin\Khernet.Core
IF not exist %25lib_directory%25 mkdir %25bin_directory%25

copy /Y $(TargetDir) %25bin_directory%25</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Loading

0 comments on commit d9925f7

Please sign in to comment.