Skip to content

Commit

Permalink
Fix some Codefactor issues & rewrite part of the build-plugin script …
Browse files Browse the repository at this point in the history
…to use functions & associative array
  • Loading branch information
Mrcubix committed Apr 3, 2024
1 parent 73357f1 commit 4c9ce00
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 82 deletions.
9 changes: 8 additions & 1 deletion Touch-Gestures-0.6.x/Touch-Gestures.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
<DebugType>embedded</DebugType>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="'$(OTDVersion)' == 'OTD06'">
<ProjectReference Include="../Touch-Gestures.Lib/Touch-Gestures.Lib.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(OTDVersion)' == ''">
<ProjectReference Include="../Touch-Gestures.Lib/Touch-Gestures.Lib-0.6.x.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../.modules/OpenTabletDriver.External-0.6.x/.modules/OpenTabletDriver/OpenTabletDriver.Desktop/OpenTabletDriver.Desktop.csproj" />
<ProjectReference Include="../.modules/OTD.EnhancedOutputMode-0.6.x/OTD.EnhancedOutputMode.Lib/OTD.EnhancedOutputMode.Lib.csproj" />
</ItemGroup>
Expand Down
6 changes: 1 addition & 5 deletions Touch-Gestures.Installer/TouchGesturesInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class TouchGesturesInstaller : ITool

private readonly DirectoryInfo OTDEnhancedOutputModeDirectory = null!;


private readonly string dependenciesResourcePath = $"Touch-Gestures.Installer{AssemblySuffix}.Touch-Gestures-{OTD_VERSION}.zip";

public TouchGesturesInstaller()
Expand Down Expand Up @@ -132,10 +131,7 @@ public bool Install(Assembly assembly, string group, string resourcePath, Direct
return true;
}

public void Dispose()
{

}
public void Dispose() {}

[BooleanProperty("Force Install", ""),
DefaultPropertyValue(false),
Expand Down
4 changes: 2 additions & 2 deletions Touch-Gestures.Lib/Entities/SerializableProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void Add(Gesture gesture)
break;
default:
throw new ArgumentException("Unknown gesture type.");
};
}
}

public void Remove(Gesture gesture)
Expand All @@ -78,7 +78,7 @@ public void Remove(Gesture gesture)
break;
default:
throw new ArgumentException("Unknown gesture type.");
};
}
}

private void AddPinch(SerializablePinchGesture pinchGesture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public static class PluginSettingsStoreExtensions

public static bool SetBindingValue(this PluginSettingStore store, TypeInfo plugin, string? value)
{

if (store.Settings.Any())
{
if (store.Settings.Count == 1)
Expand Down
37 changes: 32 additions & 5 deletions Touch-Gestures.Lib/Touch-Gestures.Lib.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk" InitialTargets="EnsureOTDVersion">

<!-- Do not build the solution, it won't work with multi-targetting -->

<Target Name="EnsureOTDVersion" BeforeTargets="PrepareForBuild">
<!-- Default to OTD 0.5.x -->
<PropertyGroup Condition="'$(OTDVersion)' == ''">
<OTDVersion>OTD05</OTDVersion>
</PropertyGroup>
</Target>

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>preview</LangVersion>
<RootNamespace>TouchGestures.Lib</RootNamespace>
<NoWarn>$(NoWarn); NETSDK1138; VSTHRD200</NoWarn>
<Nullable>enable</Nullable>
<!-- TODO: Change obj path to obj/0.5.x to avoid conflicts with 0.6.x (.NET bug) -->
</PropertyGroup>

<!-- Target Frameworks -->

<PropertyGroup Condition="'$(OTDVersion)' == 'OTD05' Or '$(OTDVersion)' == ''">
<TargetFramework>net5.0</TargetFramework>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(OTDVersion)' == 'OTD06'">
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<!-- Debug Symbols -->

<!-- Only Embed debug symbols for the Release configuration -->
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DebugType>embedded</DebugType>
</PropertyGroup>

<!-- Dependencies -->

<!-- Only for OTD 0.5.x (Running on .NET 5) -->
<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<ProjectReference Include="../.modules/OpenTabletDriver.External/.modules/OpenTabletDriver/OpenTabletDriver.Desktop/OpenTabletDriver.Desktop.csproj" PrivateAssets="all" />
<ProjectReference Include="../.modules/OpenTabletDriver.External/OpenTabletDriver.External.Common/OpenTabletDriver.External.Common.csproj" />
</ItemGroup>

<!-- Only for OTD 0.6.x (Running on .NET 6) -->
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<ProjectReference Include="../.modules/OpenTabletDriver.External-0.6.x/.modules/OpenTabletDriver/OpenTabletDriver.Desktop/OpenTabletDriver.Desktop.csproj" PrivateAssets="all" />
<ProjectReference Include="../.modules/OpenTabletDriver.External-0.6.x/OpenTabletDriver.External.Common/OpenTabletDriver.External.Common.csproj" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion Touch-Gestures.Tests/Lib/RotationGestureTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class RotateGestureTest
public static readonly Rectangle BOUNDS = new(0, 0, 100, 100);
public static readonly Vector2 ORIGIN = new(50, 50);


#endregion

#region Constructor
Expand Down
4 changes: 2 additions & 2 deletions Touch-Gestures.Tests/Samples/PinchSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public static TouchPoint[][] GeneratePinchReportsTowardsTarget(int n, TouchPoint
report[0] = new TouchPoint
{
TouchID = 0,
Position = new Vector2(firstPoint.Position.X + firstXIncrement * i, firstPoint.Position.Y + firstYIncrement * i),
Position = new Vector2(firstPoint.Position.X + (firstXIncrement * i), firstPoint.Position.Y + (firstYIncrement * i)),
};

report[1] = new TouchPoint
{
TouchID = 1,
Position = new Vector2(secondPoint.Position.X + secondXIncrement * i, secondPoint.Position.Y + secondYIncrement * i),
Position = new Vector2(secondPoint.Position.X + (secondXIncrement * i), secondPoint.Position.Y + (secondYIncrement * i)),
};

reports[i] = report;
Expand Down
144 changes: 87 additions & 57 deletions build-plugin.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
#!/bin/sh
#!/usr/bin/env bash

versions=("0.5.x" "0.6.x")
# ------------------------- Variables ------------------------- #

declare -rA versions=(
["0.5.x"]="OTD05"
["0.6.x"]="OTD06"
)

declare -rA suffixes=(
["OTD05"]=""
["OTD06"]="-0.6.x"
)

main=("Touch-Gestures.dll"
"Touch-Gestures.Lib.dll"
"OpenTabletDriver.External.Common.dll"
"Newtonsoft.Json.dll"
"StreamJsonRpc.dll"
"Touch-Gestures.pdb"
"Touch-Gestures.Lib.pdb"
"OpenTabletDriver.External.Common.pdb")

# ------------------------- Arguments ------------------------- #

donotzip=false

Expand All @@ -9,20 +30,9 @@ then
donotzip=true
fi

echo ""
echo "Creating build directory structure"
echo ""

for version in "${versions[@]}"
do
suffix=""

# if version is not 0.5.x, suffix plugin project with version
if [ $version != "0.5.x" ];
then
suffix="-$version"
fi
# ------------------------- Functions ------------------------- #

create_build_structure () {
# Check if build directory exists
if [ -d "build" ];
then
Expand All @@ -41,7 +51,9 @@ do
fi
fi
fi
}

create_plugin_structure () {
(
cd build

Expand All @@ -65,36 +77,12 @@ do
fi
fi
)
}

echo ""
echo "Building Touch-Gestures"
echo ""

echo "Building Touch-Gestures$suffix"

#Build the plugin, exit on failure
if ! dotnet publish "Touch-Gestures$suffix" -c Release -p:noWarn='"NETSDK1138;VSTHRD200"' -o temp/plugin/$version;
then
echo "Failed to build Touch-Gestures for $version"
exit 1
fi

echo ""
echo "Moving necessary files to build/plugin"
echo ""

main=("Touch-Gestures.dll"
"Touch-Gestures.Lib.dll"
"OpenTabletDriver.External.Common.dll"
"Newtonsoft.Json.dll"
"StreamJsonRpc.dll"
"Touch-Gestures.pdb"
"Touch-Gestures.Lib.pdb"
"OpenTabletDriver.External.Common.pdb")

move_files () {
(
temp=temp/plugin/$version
build=build/plugin/$version
local temp=temp/plugin/$version
local build=build/plugin/$version

if [ -d $temp ] && [ -d $build ];
then
Expand Down Expand Up @@ -124,25 +112,15 @@ do
cd ../../../$build
zip -r Touch-Gestures-$version.zip ./*
fi

else
echo "Failed to find temp or build folder for $version"
exit 1
fi
)
}

if [ $? -ne 0 ];
then
echo "Failed to move necessary files to build/plugin"
exit 1
fi

# if donotzip is set to true, then skip the installer build
if [ $donotzip == true ];
then
echo "Skipping installer build for $version"
continue
fi

build_installer () {
echo ""
echo "Building the installer"
echo ""
Expand All @@ -168,6 +146,58 @@ do
exit 1
fi
)
}

# ------------------------- Main ------------------------- #

echo ""
echo "Creating build directory structure"
echo ""

create_build_structure

for version in "${!versions[@]}"
do
# Get suffix for the version (0.5.x -> OTD05 -> "")
version_code=${versions[${version}]}
suffix=${suffixes[${version_code}]}

create_plugin_structure

echo ""
echo "Building Touch-Gestures"
echo ""

echo "Building Touch-Gestures$suffix"

#Build the plugin, exit on failure
if ! dotnet publish "Touch-Gestures$suffix" -c Release -p:noWarn='"NETSDK1138;VSTHRD200"' -o temp/plugin/$version -p:OTDVersion=$version_code;
then
echo "Failed to build Touch-Gestures for $version"
exit 1
fi

echo ""
echo "Moving necessary files to build/plugin"
echo ""

# Move files contained in variable main to build/plugin
move_files

if [ $? -ne 0 ];
then
echo "Failed to move necessary files to build/plugin"
exit 1
fi

# if donotzip is set to true, then skip the installer build
if [ $donotzip == true ];
then
echo "Skipping installer build for $version"
continue
fi

build_installer $version $suffix

done

Expand All @@ -176,4 +206,4 @@ rm -rf "temp/"

echo ""
echo "Plugins Build complete"
echo ""
echo ""
24 changes: 17 additions & 7 deletions build-ux.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
#!/usr/bin/env bash

# ------------------------- Variables ------------------------- #

donotzip=false

Expand All @@ -7,6 +9,18 @@ then
donotzip=true
fi

# ------------------------- Functions ------------------------- #

zip_dir_contents () {
echo "Zipping $f"
(
cd $1
zip -r $2 *
)
}

# ------------------------- Main ------------------------- #

if [ -d "./build/ux" ]; then
rm -rf ./build/ux/*
fi
Expand All @@ -21,7 +35,7 @@ platforms=("linux-x64" "linux-arm64" "linux-arm" "win-x64" "win-x86" "win-arm64"
for platform in "${platforms[@]}"
do
# build the desktop on linux & windows
dotnet publish Touch-Gestures.UX.Desktop -c Release -p:noWarn='"NETSDK1138;VSTHRD200"' -r $platform -o build/ux/$platform
dotnet publish Touch-Gestures.UX.Desktop -c Release -p:noWarn='"NETSDK1138;VSTHRD200"' -r $platform -o build/ux/$platform -p:OTDVersion=OTD06
done

find ./build/ux -name "*.pdb" -type f -delete
Expand All @@ -38,11 +52,7 @@ fi

for f in *; do
if [ -d "$f" ]; then
echo "Zipping $f"
(
cd "$f"
zip -r "../Touch-Gestures.UX-$f.zip" *
)
zip_dir_contents $f "../Touch-Gestures.UX-$f.zip"
fi
done
)
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash

versions=("0.5.x" "0.6.x")

Expand Down

0 comments on commit 4c9ce00

Please sign in to comment.