Skip to content

Commit 17440bc

Browse files
committed
Add project files.
1 parent 3727a2c commit 17440bc

File tree

6 files changed

+312
-0
lines changed

6 files changed

+312
-0
lines changed

.github/workflows/app-release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish application
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
release:
8+
name: Release
9+
strategy:
10+
matrix:
11+
kind: ['windows']
12+
include:
13+
- kind: windows
14+
os: windows-latest
15+
target: win-x64
16+
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
22+
- name: Setup dotnet
23+
uses: actions/setup-dotnet@v1
24+
with:
25+
dotnet-version: 6.0.x
26+
27+
- name: Build
28+
shell: bash
29+
run: |
30+
# Define some variables for things we need
31+
tag=$(git describe --tags --abbrev=0)
32+
release_name="cf-java-gpu-fix-$tag"
33+
# Build everything
34+
dotnet publish cf-java-gpu-fix/cf-java-gpu-fix.csproj --runtime "${{ matrix.target }}" -c Release -o "$release_name" --self-contained
35+
# Pack files
36+
if [ "${{ matrix.target }}" == "win-x64" ]; then
37+
7z a -tzip "${release_name}.zip" "./${release_name}/*"
38+
else
39+
tar czvf "${release_name}.tar.gz" "$release_name"
40+
fi
41+
# Delete output directory
42+
rm -r "$release_name"
43+
- name: Publish
44+
uses: softprops/action-gh-release@v1
45+
with:
46+
files: "cf-java-gpu-fix-*"
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: '31 3 * * 3'
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ 'csharp' ]
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v3
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v2
31+
with:
32+
languages: ${{ matrix.language }}
33+
34+
- name: Autobuild
35+
uses: github/codeql-action/autobuild@v2
36+
37+
38+
- name: Perform CodeQL Analysis
39+
uses: github/codeql-action/analyze@v2

.github/workflows/dotnet-ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: .NET Continuous Integration
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
name: Build GPU fixer
12+
strategy:
13+
matrix:
14+
kind: ['windows']
15+
include:
16+
- kind: windows
17+
os: windows-latest
18+
target: win-x64
19+
20+
runs-on: ${{ matrix.os }}
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
26+
- name: Setup dotnet
27+
uses: actions/setup-dotnet@v1
28+
with:
29+
dotnet-version: 6.0.x
30+
31+
- name: Restore dependencies
32+
run: dotnet restore
33+
34+
- name: Build
35+
shell: bash
36+
run: |
37+
dotnet publish cf-java-gpu-fix/cf-java-gpu-fix.csproj --runtime "${{ matrix.target }}" -c Release -o published --self-contained

cf-java-gpu-fix.sln

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32611.2
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cf-java-gpu-fix", "cf-java-gpu-fix\cf-java-gpu-fix.csproj", "{DB6A9139-4DBA-4540-A679-64254252807B}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5A2FB001-3A27-4C77-B728-1B439EAFAE7B}"
9+
ProjectSection(SolutionItems) = preProject
10+
.github\workflows\app-release.yml = .github\workflows\app-release.yml
11+
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
12+
.github\workflows\dotnet-ci.yml = .github\workflows\dotnet-ci.yml
13+
EndProjectSection
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{DB6A9139-4DBA-4540-A679-64254252807B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{DB6A9139-4DBA-4540-A679-64254252807B}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{DB6A9139-4DBA-4540-A679-64254252807B}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{DB6A9139-4DBA-4540-A679-64254252807B}.Release|Any CPU.Build.0 = Release|Any CPU
25+
EndGlobalSection
26+
GlobalSection(SolutionProperties) = preSolution
27+
HideSolutionNode = FALSE
28+
EndGlobalSection
29+
GlobalSection(ExtensibilityGlobals) = postSolution
30+
SolutionGuid = {EA0CD6A5-03BF-4B80-A711-60A6130F54B2}
31+
EndGlobalSection
32+
EndGlobal

cf-java-gpu-fix/Program.cs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using Microsoft.Win32;
2+
using System.Collections.Concurrent;
3+
using System.Security.Principal;
4+
5+
Console.WriteLine("Hi! I will attempt to set so that your javaw.exe will use the GPU!");
6+
7+
const string GPURegKey = @"Software\Microsoft\DirectX\UserGpuPreferences";
8+
9+
var javaExecutables = new List<string>();
10+
11+
var winIdentity = new WindowsPrincipal(WindowsIdentity.GetCurrent());
12+
13+
if (!winIdentity.IsInRole(WindowsBuiltInRole.Administrator))
14+
{
15+
Console.WriteLine();
16+
17+
Console.WriteLine("Error: You need to run this program as an administrator");
18+
Console.WriteLine("Right click me and use \"Run as administrator\"");
19+
20+
Console.WriteLine();
21+
22+
Console.WriteLine("(I need it, since I'm gonna rewrite some stuff in your registry)");
23+
24+
Console.ReadLine();
25+
26+
return -1;
27+
}
28+
29+
Console.WriteLine();
30+
31+
Console.WriteLine("[INFO] Checking for Overwolf/CurseForge registry keys");
32+
var cfRegKey = Registry.CurrentUser.OpenSubKey(@"Software\Overwolf\CurseForge\");
33+
if (cfRegKey != null)
34+
{
35+
var cfMCRoot = cfRegKey.GetValue("minecraft_root") as string;
36+
37+
if (!string.IsNullOrWhiteSpace(cfMCRoot))
38+
{
39+
Console.WriteLine($"[INFO] Found it! Modding path is: {cfMCRoot}");
40+
var cfJavaExecutables = GetJavaExecutablesFromPath(cfMCRoot, "javaw.exe");
41+
Console.WriteLine($"[INFO] Found {cfJavaExecutables.Count} executables, adding to list");
42+
javaExecutables.AddRange(cfJavaExecutables.Select(j => j.FullName));
43+
}
44+
}
45+
else
46+
{
47+
Console.WriteLine("[INFO] Didn't find Overwolf/CurseForge.. anyhow..");
48+
}
49+
50+
Console.WriteLine();
51+
52+
if (javaExecutables.Count == 0)
53+
{
54+
Console.WriteLine("[INFO] Well, this was awkward, we haven't found any \"important\" java executables.");
55+
Console.WriteLine("[INFO] So.. have a nice day!");
56+
}
57+
else
58+
{
59+
Console.WriteLine($"[INFO] Do you want to continue before setting things in the registry? Gonna write {javaExecutables.Count} new keys. [Y/N]");
60+
var acceptedKeys = new[] { ConsoleKey.Y, ConsoleKey.N };
61+
ConsoleKey key;
62+
do
63+
{
64+
key = Console.ReadKey(true).Key;
65+
if (!acceptedKeys.Contains(key))
66+
{
67+
Console.WriteLine($"[ERROR] That was {key}, not Y or N, try again..");
68+
}
69+
} while (!acceptedKeys.Contains(key));
70+
71+
if (key == ConsoleKey.N)
72+
{
73+
Console.WriteLine("[INFO] Ok, exiting! Bye!");
74+
return 0;
75+
}
76+
77+
Console.WriteLine($"[INFO] Fixing {javaExecutables.Count} executables");
78+
79+
var gpuKey = Registry.CurrentUser.OpenSubKey(GPURegKey, true);
80+
if (gpuKey != null)
81+
{
82+
foreach (var java in javaExecutables)
83+
{
84+
Console.WriteLine($"[INFO] Fixing \"{java}\" for you!");
85+
gpuKey.SetValue(java, "GpuPreference=2;");
86+
}
87+
88+
gpuKey.Close();
89+
}
90+
91+
Console.WriteLine("[INFO] All done! Happy playing!");
92+
}
93+
94+
Console.ReadLine();
95+
96+
return 0;
97+
98+
ConcurrentStack<FileInfo> GetJavaExecutablesFromPath(string path, string searchPattern = "javaw.exe")
99+
{
100+
string[] IgnoredFolders = new string[] {
101+
"\\$RECYCLE.BIN",
102+
"\\System Volume Information",
103+
"\\Recovery",
104+
"\\xtp",
105+
"\\Backups"
106+
};
107+
108+
var files = new ConcurrentStack<FileInfo>();
109+
110+
var rootFolderFiles = new DirectoryInfo(path).GetFiles();
111+
112+
foreach (var f in rootFolderFiles)
113+
{
114+
files.Push(f);
115+
}
116+
117+
var directories = Directory.GetDirectories(path).Where(d => !IgnoredFolders.Any(i => d.EndsWith(i))).ToList();
118+
Parallel.ForEach(directories, dir =>
119+
{
120+
try
121+
{
122+
var _files = new DirectoryInfo(dir).EnumerateFiles(searchPattern, SearchOption.AllDirectories).Where(d => !d.Attributes.HasFlag(FileAttributes.Directory)).ToArray();
123+
if (_files.Length > 0)
124+
{
125+
files.PushRange(_files);
126+
}
127+
}
128+
catch
129+
{
130+
}
131+
});
132+
133+
return files;
134+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<RootNamespace>cf_java_gpu_fix</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<PublishSingleFile>true</PublishSingleFile>
10+
<PublishTrimmed>true</PublishTrimmed>
11+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
12+
</PropertyGroup>
13+
14+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
15+
<DebugType>embedded</DebugType>
16+
</PropertyGroup>
17+
18+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
19+
<DebugType>embedded</DebugType>
20+
</PropertyGroup>
21+
22+
</Project>

0 commit comments

Comments
 (0)