add content dev tear up/tear down

This commit is contained in:
nilllzz 2018-02-22 17:58:56 +01:00
parent e11bd9639e
commit 4a3c803608
14 changed files with 424 additions and 43 deletions

18
.gitignore vendored
View File

@ -301,8 +301,16 @@ Network Trash Folder
Temporary Items
.apdisk
# Must include
!2.5DHero/
!2.5DHero/2.5DHero/
!2.5DHero/2.5DHero/Debug/
!2.5DHero/2.5DHero/Debug/**/*
# ignore /lib/save
lib/save/
# ignore binaries in p3d project
p3d/**/*.exe
p3d/**/*.dll
p3d/**/*.xnb
# ignore generated files/folders by the game's exe in the p3d project
p3d/ContentPacks/
p3d/GameModes/
p3d/save/
p3d/log.dat

22
P3D.sln
View File

@ -15,6 +15,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{7877D883
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PostBuild", "lib\tools\PostBuild\PostBuild.csproj", "{3B2AEA8E-4384-48D8-B26B-2C67466A1352}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TearUp", "lib\tools\TearUp\TearUp.csproj", "{417FEA8A-9334-4938-9370-519EF1551B05}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TearDown", "lib\tools\TearDown\TearDown.csproj", "{0AE314A4-6005-48C7-BCD4-33E4C5057CFD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -55,6 +59,22 @@ Global
{3B2AEA8E-4384-48D8-B26B-2C67466A1352}.Release|Any CPU.Build.0 = Release|Any CPU
{3B2AEA8E-4384-48D8-B26B-2C67466A1352}.ReleaseNoContent|Any CPU.ActiveCfg = Release|Any CPU
{3B2AEA8E-4384-48D8-B26B-2C67466A1352}.ReleaseNoContent|Any CPU.Build.0 = Release|Any CPU
{417FEA8A-9334-4938-9370-519EF1551B05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{417FEA8A-9334-4938-9370-519EF1551B05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{417FEA8A-9334-4938-9370-519EF1551B05}.DebugNoContent|Any CPU.ActiveCfg = Debug|Any CPU
{417FEA8A-9334-4938-9370-519EF1551B05}.DebugNoContent|Any CPU.Build.0 = Debug|Any CPU
{417FEA8A-9334-4938-9370-519EF1551B05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{417FEA8A-9334-4938-9370-519EF1551B05}.Release|Any CPU.Build.0 = Release|Any CPU
{417FEA8A-9334-4938-9370-519EF1551B05}.ReleaseNoContent|Any CPU.ActiveCfg = Release|Any CPU
{417FEA8A-9334-4938-9370-519EF1551B05}.ReleaseNoContent|Any CPU.Build.0 = Release|Any CPU
{0AE314A4-6005-48C7-BCD4-33E4C5057CFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0AE314A4-6005-48C7-BCD4-33E4C5057CFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0AE314A4-6005-48C7-BCD4-33E4C5057CFD}.DebugNoContent|Any CPU.ActiveCfg = Debug|Any CPU
{0AE314A4-6005-48C7-BCD4-33E4C5057CFD}.DebugNoContent|Any CPU.Build.0 = Debug|Any CPU
{0AE314A4-6005-48C7-BCD4-33E4C5057CFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0AE314A4-6005-48C7-BCD4-33E4C5057CFD}.Release|Any CPU.Build.0 = Release|Any CPU
{0AE314A4-6005-48C7-BCD4-33E4C5057CFD}.ReleaseNoContent|Any CPU.ActiveCfg = Release|Any CPU
{0AE314A4-6005-48C7-BCD4-33E4C5057CFD}.ReleaseNoContent|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -64,6 +84,8 @@ Global
{ED665F9B-07F4-4415-BD72-A728CF1EA909} = {3CE8099E-129D-40F9-8D23-005DFF32E2A2}
{7877D883-AA51-4C27-ADA5-C4F85F86F4EE} = {3CE8099E-129D-40F9-8D23-005DFF32E2A2}
{3B2AEA8E-4384-48D8-B26B-2C67466A1352} = {7877D883-AA51-4C27-ADA5-C4F85F86F4EE}
{417FEA8A-9334-4938-9370-519EF1551B05} = {7877D883-AA51-4C27-ADA5-C4F85F86F4EE}
{0AE314A4-6005-48C7-BCD4-33E4C5057CFD} = {7877D883-AA51-4C27-ADA5-C4F85F86F4EE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8FE3951F-DE18-41FF-A035-32DF597A91F2}

View File

@ -14026,7 +14026,9 @@
<Content Include="Content\Songs\wind.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Textures\chess.png" />
<Content Include="Content\Textures\chess.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="meta">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@ -42,10 +42,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -11,6 +11,8 @@ namespace PostBuild
static void Main(string[] args)
{
// copies all binaries from /p3d/bin/debug to /lib/build
// find solution folder
var dir = AppDomain.CurrentDomain.BaseDirectory;
string solutionFile = null;

View File

@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PostBuild")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PostBuild")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3b2aea8e-4384-48d8-b26b-2c67466a1352")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

BIN
lib/tools/TearDown.exe Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

View File

@ -0,0 +1,170 @@
using System;
using System.IO;
using System.Linq;
namespace TearDown
{
class Program
{
private const string SOLUTION_FILENAME = "P3D.sln";
private const string P3D_DIR = "p3d/";
private const string PROJECT_HOOK = " <Content Include=\"Pokemon3D.ico\" />";
static void Main(string[] args)
{
Console.WriteLine("Starting teardown");
// delete all binaries from /p3d
// delete generated files/folders from /p3d:
// - log.dat
// - GameModes/
// - ContentPacks/
// move (copy and delete) the folder /p3d/save to /lib/save
// check for all files in /p3d/content if they exist in the .vbproj file and add them, if they don't
Console.WriteLine("Find solution folder...");
// find solution folder
var dir = AppDomain.CurrentDomain.BaseDirectory;
string solutionFolder = null;
do
{
var files = Directory.GetFiles(dir);
foreach (var file in files)
{
var fileName = Path.GetFileName(file);
if (fileName == SOLUTION_FILENAME)
{
solutionFolder = dir;
}
}
if (solutionFolder == null)
{
// go one folder up and try again
dir = new DirectoryInfo(dir).Parent.FullName;
}
} while (solutionFolder == null);
Console.WriteLine($"Found solution folder at {solutionFolder}");
// delete all binaries from /p3d
var p3dFolder = Path.Combine(solutionFolder, P3D_DIR);
var binaries = GetFiles(p3dFolder, new[] { "*.exe", "*.dll", "*.xnb" }, SearchOption.AllDirectories);
foreach (var file in binaries)
{
var normalized = file.Replace("/", "\\");
// do not delete files in working /bin or /obj folders
if (!normalized.Contains("\\bin\\") &&
!normalized.Contains("\\obj\\"))
{
File.Delete(file);
Console.WriteLine($"Deleted binary at {file}");
}
}
// delete generated files/folders from /p3d:
// - log.dat
// - GameModes/
// - ContentPacks/
var logFile = Path.Combine(p3dFolder, "log.dat");
if (File.Exists(logFile))
{
File.Delete(logFile);
Console.WriteLine($"Deleted log file at {logFile}");
}
var gameModesFolder = Path.Combine(p3dFolder, "GameModes");
if (Directory.Exists(gameModesFolder))
{
Directory.Delete(gameModesFolder, true);
Console.WriteLine($"Deleted GameModes folder at {gameModesFolder}");
}
var contentPacksFolder = Path.Combine(p3dFolder, "ContentPacks");
if (Directory.Exists(contentPacksFolder))
{
Directory.Delete(contentPacksFolder, true);
Console.WriteLine($"Deleted ContentPacks folder at {contentPacksFolder}");
}
// move (copy and delete) the folder /p3d/save to /lib/save
var saveFolder = Path.Combine(p3dFolder, "save");
if (Directory.Exists(saveFolder))
{
var targetSaveFolder = Path.Combine(solutionFolder, "lib/save");
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(saveFolder, targetSaveFolder, true);
Directory.Delete(saveFolder, true);
Console.WriteLine($"Moved save folder to {targetSaveFolder}");
}
// check for all files in /p3d/content if they exist in the .vbproj file and add them, if they don't
{
var projFile = Path.Combine(p3dFolder, "p3d.vbproj");
var contentFolder = Path.Combine(p3dFolder, "Content");
var contentUri = new Uri(contentFolder);
var files = GetFiles(contentFolder, new[] { "*.dat", "*.poke", "*.trainer", "*.png", "*.ogg", "*.wav" }, SearchOption.AllDirectories);
var projContent = File.ReadAllText(projFile);
var startIndex = projContent.IndexOf(PROJECT_HOOK);
var changes = false;
var checkedCount = 0;
Console.WriteLine($"Checking {files.Length} content files for inclusion in .vbproj");
foreach (var file in files)
{
var fileUri = new Uri(file);
var relative = contentUri.MakeRelativeUri(fileUri).ToString();
var entry = GetProjectContentFileEntry(relative);
if (!projContent.Contains(entry))
{
Console.WriteLine($"Content file {relative} not found in project file.");
projContent = projContent.Insert(startIndex, entry + Environment.NewLine);
changes = true;
}
checkedCount++;
if (checkedCount % 500 == 0)
{
Console.WriteLine($"Done checking {checkedCount}...");
}
}
Console.WriteLine($"Done checking {checkedCount}...");
if (changes)
{
Console.WriteLine("Changes found in Content directory, applying to vbproj.");
File.WriteAllText(projFile, projContent);
}
}
Console.WriteLine("Teardown complete");
Console.ReadLine();
}
private static string GetProjectContentFileEntry(string contentFile)
{
contentFile = contentFile
.Replace("/", "\\")
.Replace("%20", " ");
contentFile = Uri.EscapeDataString(contentFile)
.Replace("%5C", "\\")
.Replace("%20", " ");
return
$" <Content Include=\"{contentFile}\">" + Environment.NewLine +
$" <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>" + Environment.NewLine +
$" </Content>";
}
private static string[] GetFiles(string dir, string[] filters, SearchOption searchOption)
{
return filters.SelectMany(filter => Directory.GetFiles(dir, filter, searchOption)).ToArray();
}
}
}

View File

@ -0,0 +1,54 @@
<?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>{0AE314A4-6005-48C7-BCD4-33E4C5057CFD}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>TearDown</RootNamespace>
<AssemblyName>TearDown</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Core" />
<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="Program.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

BIN
lib/tools/TearUp.exe Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

View File

@ -0,0 +1,91 @@
using System;
using System.IO;
namespace TearUp
{
class Program
{
private const string SOLUTION_FILENAME = "P3D.sln";
private const string OUTPUT_DIR = "p3d/";
static void Main(string[] args)
{
Console.WriteLine("Starting tearup");
// will move all files from lib/build to p3d/
// will move the /lib/save folder to p3d/save
Console.WriteLine("Find solution folder...");
// find solution folder
var dir = AppDomain.CurrentDomain.BaseDirectory;
string solutionFolder = null;
do
{
var files = Directory.GetFiles(dir);
foreach (var file in files)
{
var fileName = Path.GetFileName(file);
if (fileName == SOLUTION_FILENAME)
{
solutionFolder = dir;
}
}
if (solutionFolder == null)
{
// go one folder up and try again
dir = new DirectoryInfo(dir).Parent.FullName;
}
} while (solutionFolder == null);
Console.WriteLine($"Found solution folder at {solutionFolder}");
var libFolder = Path.Combine(solutionFolder, "lib");
var buildFolder = Path.Combine(libFolder, "build");
var targetFolder = Path.Combine(solutionFolder, OUTPUT_DIR);
if (Directory.Exists(buildFolder) && Directory.Exists(targetFolder))
{
Console.WriteLine($"Copy files from {buildFolder} to {targetFolder}.");
var buildFolderUri = new Uri(buildFolder);
foreach (var file in Directory.GetFiles(buildFolder, "*.*", SearchOption.AllDirectories))
{
var fileUri = new Uri(file);
var relative = buildFolderUri.MakeRelativeUri(fileUri).ToString();
relative = relative.Remove(0, "build\\".Length);
var targetFile = Path.Combine(targetFolder, relative);
var targetDir = Path.GetDirectoryName(targetFile);
// create dir
if (!Directory.Exists(targetDir))
{
Directory.CreateDirectory(targetDir);
Console.WriteLine($"Created directory at {targetDir}");
}
File.Copy(file, targetFile, true);
Console.WriteLine($"Copied to {targetFile}");
}
}
else
{
Console.WriteLine($"Either the build folder at {buildFolder} or the target folder at {targetFolder} does not exist.");
}
// copy save folder
var saveFolder = Path.Combine(libFolder, "save");
if (Directory.Exists(saveFolder))
{
var targetDir = Path.Combine(targetFolder, "save");
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(saveFolder, targetDir, true);
}
Console.ReadLine();
}
}
}

View File

@ -0,0 +1,54 @@
<?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>{417FEA8A-9334-4938-9370-519EF1551B05}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>TearUp</RootNamespace>
<AssemblyName>TearUp</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Core" />
<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="Program.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>