Skip to content

Commit 41f11cd

Browse files
CopilotJusterZhu
andcommitted
Use host app's base directory for InstallPath default
Changed default InstallPath from %APPDATA%/~/.config to AppDomain.CurrentDomain.BaseDirectory. This: - Extracts path from host program's runtime location - Requires no admin privileges (uses app's own directory) - Aligns with existing codebase pattern (Thread.GetDomain().BaseDirectory) - More universal and highly available across deployments Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
1 parent eb45659 commit 41f11cd

4 files changed

Lines changed: 20 additions & 18 deletions

File tree

src/c#/CoreTest/Shared/ConfiginfoBuilderTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,18 @@ public void Build_GeneratesPlatformSpecificDefaults()
140140
// Assert
141141
Assert.NotNull(config.InstallPath);
142142

143+
// InstallPath should be the current application's base directory
144+
Assert.Equal(AppDomain.CurrentDomain.BaseDirectory, config.InstallPath);
145+
143146
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
144147
{
145148
// Windows-specific assertions
146149
Assert.Contains("App.exe", config.AppName);
147-
Assert.Contains("GeneralUpdate", config.InstallPath);
148150
}
149151
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
150152
{
151153
// Linux-specific assertions
152154
Assert.DoesNotContain(".exe", config.AppName);
153-
Assert.Contains(".config", config.InstallPath);
154-
Assert.Contains("GeneralUpdate", config.InstallPath);
155155
}
156156
}
157157

@@ -531,7 +531,8 @@ public void Build_OnWindows_GeneratesWindowsDefaults()
531531

532532
// Assert
533533
Assert.Contains("App.exe", config.AppName);
534-
Assert.Contains("GeneralUpdate", config.InstallPath);
534+
// Should use the current application's base directory
535+
Assert.Equal(AppDomain.CurrentDomain.BaseDirectory, config.InstallPath);
535536
// Windows script should be empty
536537
Assert.Empty(config.Script);
537538
}
@@ -556,8 +557,8 @@ public void Build_OnLinux_GeneratesLinuxDefaults()
556557

557558
// Assert
558559
Assert.DoesNotContain(".exe", config.AppName);
559-
Assert.Contains(".config", config.InstallPath);
560-
Assert.Contains("GeneralUpdate", config.InstallPath);
560+
// Should use the current application's base directory
561+
Assert.Equal(AppDomain.CurrentDomain.BaseDirectory, config.InstallPath);
561562
// Linux should have a default permission script
562563
Assert.NotEmpty(config.Script);
563564
Assert.Contains("chmod", config.Script);

src/c#/GeneralUpdate.Common/Shared/Object/ConfiginfoBuilder-Usage.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@ var config = new ConfiginfoBuilder(
2626
The builder automatically detects the runtime platform and sets appropriate defaults:
2727

2828
### Windows Platform
29-
- **Install Path**: `%APPDATA%\GeneralUpdate`
29+
- **Install Path**: Current application's base directory (via `AppDomain.CurrentDomain.BaseDirectory`)
3030
- **App Names**: Uses `.exe` extension (e.g., `App.exe`)
3131
- **Script**: Empty (Windows doesn't typically need permission scripts)
3232
- **Path Separator**: Backslash (`\`) - handled automatically by .NET
3333
- **Black Formats**: `.log`, `.tmp` (from `ConfiginfoBuilder.DefaultBlackFormats`)
3434

3535
### Linux Platform
36-
- **Install Path**: `~/.config/GeneralUpdate`
36+
- **Install Path**: Current application's base directory (via `AppDomain.CurrentDomain.BaseDirectory`)
3737
- **App Names**: No `.exe` extension (e.g., `app`)
3838
- **Script**: Default chmod script for granting execution permissions
3939
- **Path Separator**: Forward slash (`/`) - handled automatically by .NET
4040
- **Black Formats**: `.log`, `.tmp` (from `ConfiginfoBuilder.DefaultBlackFormats`)
4141

42+
**Note**: The install path defaults to the current application's running directory, which does not require administrator privileges and automatically extracts the location from the host program.
43+
4244
## Customizing Configuration
4345

4446
You can override any default value using the fluent API:
@@ -252,12 +254,12 @@ var config = new ConfiginfoBuilder(updateUrl, token, scheme).Build();
252254
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
253255
{
254256
Console.WriteLine($"Windows config: {config.InstallPath}");
255-
// Output: Windows config: C:\Users\Username\AppData\Roaming\GeneralUpdate
257+
// Output: Windows config: C:\MyApp\ (current application directory)
256258
}
257259
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
258260
{
259261
Console.WriteLine($"Linux config: {config.InstallPath}");
260-
// Output: Linux config: /home/username/.config/GeneralUpdate
262+
// Output: Linux config: /opt/myapp/ (current application directory)
261263
}
262264
```
263265

src/c#/GeneralUpdate.Common/Shared/Object/ConfiginfoBuilder.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ private void InitializePlatformDefaults()
9898
/// </summary>
9999
private void InitializeWindowsDefaults()
100100
{
101-
// Use APPDATA for configuration storage on Windows
102-
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
103-
_installPath = Path.Combine(appDataPath, "GeneralUpdate");
101+
// Use the current application's base directory (no admin privileges required)
102+
// This extracts the path from the host program's runtime location
103+
_installPath = AppDomain.CurrentDomain.BaseDirectory;
104104

105105
// Windows uses backslash as path separator (handled automatically by Path.Combine)
106106
// Set Windows-specific executable names
@@ -116,10 +116,9 @@ private void InitializeWindowsDefaults()
116116
/// </summary>
117117
private void InitializeLinuxDefaults()
118118
{
119-
// Use ~/.config for configuration storage on Linux (XDG Base Directory Specification)
120-
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
121-
var configPath = Path.Combine(homeDirectory, ".config");
122-
_installPath = Path.Combine(configPath, "GeneralUpdate");
119+
// Use the current application's base directory (no admin privileges required)
120+
// This extracts the path from the host program's runtime location
121+
_installPath = AppDomain.CurrentDomain.BaseDirectory;
123122

124123
// Linux uses forward slash as path separator (handled automatically by Path.Combine)
125124
// Linux executables typically don't have .exe extension

src/c#/GeneralUpdate.Common/Shared/Object/README-ConfiginfoBuilder.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The builder automatically adapts based on your runtime environment:
3434

3535
| Aspect | Windows | Linux |
3636
|--------|---------|-------|
37-
| Install Path | `%APPDATA%\GeneralUpdate` | `~/.config/GeneralUpdate` |
37+
| Install Path | Current app directory | Current app directory |
3838
| App Names | `App.exe` | `app` |
3939
| Script | Empty | chmod script |
4040
| Path Separator | `\` (automatic) | `/` (automatic) |

0 commit comments

Comments
 (0)