Skip to content

Commit

Permalink
+ DIM Package naming utility.
Browse files Browse the repository at this point in the history
+ Fixed saved file encoding to UTF-8 for Daz compatibility.
+ Refactored Code.
  • Loading branch information
Zamods committed Dec 15, 2021
1 parent 5a824cf commit 8990416
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 8 deletions.
File renamed without changes.
27 changes: 27 additions & 0 deletions zamodsPacker/Data Models/PackageNameModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

namespace ZamodsPacker
{
/// <summary>
/// Data structure of DIM package Name.
/// </summary>
public struct PackageNameModel
{
string SourcePrefix { get; }
string ProductSKU { get; }
string PackageID { get; }
string ProductName { get; }

public PackageNameModel(string sourcePrefix, string productSKU, string packageID, string productName)
{
SourcePrefix = sourcePrefix;
ProductSKU = productSKU;
PackageID = packageID;
ProductName = productName;
}

public override string ToString()
{
return $"{SourcePrefix}{ProductSKU}-{PackageID}_{ProductName}.zip";
}
}
}
2 changes: 1 addition & 1 deletion zamodsPacker/Manifesto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task FinalizeAndWriteToFile(string path, string globalID = "REPLACE
finalText += $"\n{MANIFESTFOOTER}";
string finalFilePath = $"{path}\\Manifest.dsx";

await File.WriteAllTextAsync(finalFilePath, finalText);
await File.WriteAllTextAsync(finalFilePath, finalText, encoding: System.Text.Encoding.UTF8);
Console.WriteLine($"Wrote manifest file successfully to path: {finalFilePath}");
}
catch (Exception ex)
Expand Down
160 changes: 160 additions & 0 deletions zamodsPacker/PackageNamer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
using System;

namespace ZamodsPacker
{
/// <summary>
/// Class intented to generate product package name that is compatible with DIM.
/// </summary>
public class PackageNamer
{
public void GeneratePackageName()
{
string sourcePrefix = FormatSourcePrefix();
string productSKU = FormatProductSKU();
string packageID = FormatPackageID();
string productName = FormatProductName();

var packageNameModel = new PackageNameModel(sourcePrefix, productSKU, packageID, productName);
Console.WriteLine(packageNameModel);
Console.ReadKey();
//File.WriteAllText(path, packageNameModel.ToString());
}
private string FormatProductName()
{
string userInput;

Console.WriteLine("Type \"Product Name\" for your package.");
userInput = Console.ReadLine();
PurgeSpacesAndSpecialCharacters(ref userInput);
Console.Clear();

return userInput;
}
private string FormatPackageID()
{
string userInput;
bool isCheckOk;
do
{
Console.WriteLine("Type \"Product ID\" for your package.\nLike: \"01\", \"22\"...");
userInput = Console.ReadLine();
isCheckOk = IsStringDigits(userInput);
if (!isCheckOk)
{
Console.WriteLine($"Provided Product ID: \"{userInput}\" is not digits!");
}
Console.Clear();
} while (!isCheckOk);

LeftStringPadding(ref userInput, "0", 2);

return userInput;
}

private string FormatProductSKU()
{
string userInput;
bool isCheckOk;
do
{
Console.WriteLine("Type \"Product SKU\" for your package.\nLike: \"46535\"...");
userInput = Console.ReadLine();
isCheckOk = IsProductSKUCorrect(userInput);
Console.Clear();
} while (!isCheckOk);

LeftStringPadding(ref userInput, "0", 8);

return userInput;
}

private string FormatSourcePrefix()
{
bool isCheckOk;
string userInput;
do
{
Console.WriteLine("Type \"Source Prefix\" for your package.\nLike: \"IM\", \"DAZ3D\"...");
userInput = Console.ReadLine();
isCheckOk = IsSourcePrefixCorrect(userInput);
Console.Clear();
} while (!isCheckOk);

return userInput.ToUpper();
}

private bool IsProductSKUCorrect(string productSKU)
{
if (!IsStringDigits(productSKU))
{
Console.WriteLine($"Provided Product SKU: \"{productSKU}\" is not digits!");
return false;
}

if (productSKU.Length > 8 || productSKU.Length < 1)
{
Console.WriteLine("Total digits of \"Product SKU\" should be not be greater than 8 and lesser than 1!");
Console.WriteLine($"Your input: {productSKU.Length}");
return false;
}

return true;
}

private bool IsSourcePrefixCorrect(string sourcePrefix)
{
if (!Char.IsLetter(sourcePrefix[0]))
{
Console.WriteLine("First character of \"Source Prefix\" should be capital letter only.");
Console.WriteLine($"Your input: {sourcePrefix[0]}");
return false;
}

if(sourcePrefix.Length > 6 || sourcePrefix.Length < 1)
{
Console.WriteLine("Total characters of \"Source Prefix\" should be not be greater than 7 and lesser than 1!");
Console.WriteLine($"Your input: {sourcePrefix.Length}");
return false;
}

return true;
}

private bool IsStringDigits(string str)
{
foreach (var c in str)
{
if (!Char.IsDigit(c))
{
return false;
}
}
return true;
}

private void LeftStringPadding(ref string source, string padding, int outputLength)
{
if (source.Length < outputLength)
{
int count = outputLength - source.Length;
for (int i = 0; i < count; i++)
{
source = source.Insert(0, padding);
}
}
}

private void PurgeSpacesAndSpecialCharacters(ref string source)
{
string processedStr = "";
foreach(var c in source)
{
if(Char.IsLetter(c))
{
processedStr += c;
}
}
source = processedStr;
}
}
}
16 changes: 15 additions & 1 deletion zamodsPacker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ static void Main(string[] args)
{
int result = 1;

PackerHeading();
Console.WriteLine("Do you want to generate package name?");
Console.WriteLine("Type \"1\" for yes or \"0\" for no!");
result = CheckUserResponse();

if(result == 1)
{
var packageNamer = new PackageNamer();
packageNamer.GeneratePackageName();
}
Console.Clear();

PackerHeading();
Console.WriteLine("Do you want to create manifest & supplement files for more than one product?");
Console.WriteLine("Type \"1\" for yes or \"0\" for no!");
Expand Down Expand Up @@ -57,11 +69,13 @@ private static async Task OneTimeExecution()

PackerHeading();
Console.WriteLine("Pass GLOBALID! \nTip: Check it in metadata of your product!");
Console.WriteLine("Content\\Runtime\\Support\\yourproduct.dsx");
string globalID = Console.ReadLine();
Console.Clear();

PackerHeading();
Console.WriteLine("Pass Product Name to generate \"Supplement.dsx\"! \nTip: Check it in metadata of your product!");
Console.WriteLine("Content\\Runtime\\Support\\yourproduct.dsx");
string productName = Console.ReadLine();
Console.Clear();

Expand Down Expand Up @@ -133,7 +147,7 @@ private static void DisplayAddedInput(string path, string globalID, string produ

private static void PackerHeading()
{
Console.WriteLine("zamodsPacker Alpha v.0.0.1\n");
Console.WriteLine("zamodsPacker Alpha v.0.0.2\n");
Console.WriteLine("Manifest and Supplement generator for Dad Studio aKA Daz Studio.\n");
Console.WriteLine("Links: https://shorturl.at/jquBG");
Console.WriteLine("Github: https://github.com/Zamods/zamodsPackerAlpha");
Expand Down
6 changes: 2 additions & 4 deletions zamodsPacker/Supplemento.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class Supplemento
{
const string SUPPLEMENTHEADER = "<ProductSupplement VERSION=\"0.1\">";
const string SUPPLEMENTFOOTER = "</ProductSupplement>";
const string INSTALLTYPE = "<InstallTypes VALUE=\"Content\">";
const string PRODUCTTAGS = "<ProductTags VALUE=\"DAZStudio4_5\">";

/// <summary>
Expand All @@ -26,14 +25,13 @@ public async Task FinalizeAndWriteToFile(string path, string productName= "REPLA
{
string PRODUCTNAME = $"<ProductName VALUE=\"{productName}\"/>";
string finalText = SUPPLEMENTHEADER;

finalText += $"\n {PRODUCTNAME}";
finalText += $"\n {INSTALLTYPE}";
finalText += $"\n {PRODUCTTAGS}";
finalText += $"\n{SUPPLEMENTFOOTER}";

string finalFilePath = $"{path}\\Supplement.dsx";

await File.WriteAllTextAsync(finalFilePath, finalText);
await File.WriteAllTextAsync(finalFilePath, finalText, encoding: System.Text.Encoding.UTF8);
Console.WriteLine($"Wrote supplement file successfully to path: {finalFilePath}");
}
catch (Exception ex)
Expand Down
10 changes: 8 additions & 2 deletions zamodsPacker/ZamodsPacker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>0.0.1</Version>
<Version>0.0.2</Version>
<Company>zamods</Company>
<Authors>zamods</Authors>
<Description>Console utility to generate DAZ manifest file.</Description>
<Description>Console utility to generate DAZ manifest &amp; supplement files and DIM package name.</Description>
<PackageReleaseNotes>Alpha release.</PackageReleaseNotes>
<PackageId>zamodsPacker</PackageId>
<Product>zamodsPacker</Product>
Expand All @@ -18,12 +18,18 @@
<Platforms>AnyCPU;x86</Platforms>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/Zamods/zamodsPackerAlpha</RepositoryUrl>
<NoWin32Manifest>true</NoWin32Manifest>
<StartupObject>ZamodsPacker.Program</StartupObject>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>true</Optimize>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>true</Optimize>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\..\..\Desktop\Desktop\bitmap.png">
<Pack>True</Pack>
Expand Down

0 comments on commit 8990416

Please sign in to comment.