Skip to content

Commit

Permalink
Added support for PackageSize and Languages.
Browse files Browse the repository at this point in the history
  • Loading branch information
samco-msft committed Oct 3, 2019
1 parent aab5673 commit 9d7f000
Show file tree
Hide file tree
Showing 11 changed files with 921 additions and 14 deletions.
5 changes: 5 additions & 0 deletions DiceWebSampleApps.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UwpNetNativeApp", "UwpNetNa
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UwpCppApp", "UwpCppApp\UwpCppApp.vcxproj", "{C1127118-934E-4B73-81AC-4FD8DA7F2C96}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{B8A13E19-4290-496A-B4E8-7C6CA3E7D6F5}"
ProjectSection(SolutionItems) = preProject
Scripts\DiceWebUtils.ps1 = Scripts\DiceWebUtils.ps1
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Expand Down
67 changes: 67 additions & 0 deletions Scripts/DiceWebUtils.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

function InflateDataFile([string] $filePath, [float] $sizeInMB) {

if ([string]::IsNullOrWhiteSpace($filePath)) {
throw [ArgumentException] "$filePath cannot be null or white space"
}

if ($sizeInMB -lt 0) {
throw [ArgumentException] "$sizeInMB cannot be smaller than 0"
}

$fullPath = [System.IO.Path]::GetFullPath($filePath)

$workingDrive = [System.IO.DriveInfo]::new(@([System.IO.Path]::GetPathRoot($fullPath)))
if ($workingDrive.AvailableFreeSpace -lt ($sizeInMB * [Math]::Pow(1024, 2)) * 3)
{
throw "Not enough space on drive to create data file"
}

$stream = [System.IO.FileStream]::new($fullPath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::ReadWrite)
try {
# Do not fail, just do not inflate
if ($sizeInMB -eq 0) {
return;
}

# Block that is used to generate random data
$blockSize = 1024*8;
$data = [System.Byte[]]::new($blockSize)

# The number of blocks required to accomodate for 1Mb
$blocksPerMb = [Math]::Pow(1024, 2)/$blockSize

# Fill with randomly generated data
$randomGenerator = [System.Random]::new()

for ($i = 0; $i -lt $sizeInMB*$blocksPerMb; $i++) {
$randomGenerator.NextBytes($data)
$stream.Write($data, 0, $data.Length)
}
} finally {
$stream.Close();
}
}

function CreateLanguageResources([string] $stringsPath, $languages, [string] $defaultLang = "en-us") {
# assume there will be a resource for en-us
$defaultPath = [System.IO.Path]::GetFullPath((Join-Path (Join-Path $stringsPath $defaultLang) "Resources.resw"))
if (-not (Test-Path $defaultPath)) {
throw "Cannot find $defaultPath"
}

# create a copy of the default resource for other languages
$defaultContent = Get-Content -Raw -Path $defaultPath
foreach ($lang in $languages) {
if ($lang -ine $defaultLang) {
$langContent = $defaultContent.Replace($defaultLang, $lang);
$langPath = Join-Path $stringsPath $lang
mkdir $langPath -Force | Out-Null
Set-Content -Value $langContent -Path (Join-Path $langPath "Resources.resw") -Force
}
}
}


Loading

0 comments on commit 9d7f000

Please sign in to comment.