Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions SourceCode/AgLibrary/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@ public static void FileSaveSystemEvents()
{
if (logsDirectory != "")
{
using (StreamWriter writer = new StreamWriter(logsDirectory, true))
try
{
using (StreamWriter writer = new StreamWriter(logsDirectory, true))
{
writer.Write(sbEvents);
}
}
catch
{
// suppressing an edge-case error for eg if someone has onedrive client locking the file
}
finally
{
writer.Write(sbEvents);
sbEvents.Clear();
}
}
Expand Down
6 changes: 5 additions & 1 deletion SourceCode/Updater/AgOpenGPS.Updater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugType>full</DebugType>
</PropertyGroup>

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

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions SourceCode/Updater/Forms/FormUpdate.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 3 additions & 46 deletions SourceCode/Updater/Forms/FormUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public partial class FormUpdate : Form
private string _currentVersion;
private _updateSource currentSource;
private string _installPath;
private readonly string _gitHubToken;
private ReleaseInfo _availableUpdate;
private string _localUpdatePath;
private string _localUpdateVersion;
Expand All @@ -29,14 +28,13 @@ public partial class FormUpdate : Form

private enum _updateSource { Web, Local }

public FormUpdate(string currentVersion = null, string installPath = null, string gitHubToken = null)
public FormUpdate(string currentVersion = null, string installPath = null)
{
InitializeComponent();

_updateService = new UpdateService();
_currentVersion = currentVersion ?? UpdateService.GetCurrentVersion();
_installPath = installPath ?? UpdateService.GetCurrentApplicationPath();
_gitHubToken = gitHubToken;
currentSource = _updateSource.Web;

// Handle command line arguments
Expand Down Expand Up @@ -91,9 +89,6 @@ private void FormUpdate_Load(object sender, EventArgs e)
// Display current version
lblCurrentVersion.Text = $"Current Version: {_currentVersion}";

// Update GitHub status indicator
UpdateGitHubStatus();

// Auto-detect local update
bool foundLocal = CheckForLocalUpdate();

Expand Down Expand Up @@ -132,44 +127,6 @@ private bool CheckForLocalUpdate()
return found;
}

private void UpdateGitHubStatus()
{
// Check if we have a GitHub token (from command line or hardcoded)
bool hasToken = !string.IsNullOrEmpty(_gitHubToken) ||
HasHardcodedGitHubToken();

if (hasToken)
{
lblGitHubStatus.Text = "🔐 Official";
lblGitHubStatus.ForeColor = System.Drawing.Color.FromArgb(100, 255, 100); // Bright green
lblGitHubStatus.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
}
else
{
lblGitHubStatus.Text = "🔓 Anonymous";
lblGitHubStatus.ForeColor = System.Drawing.Color.FromArgb(180, 180, 180); // Gray
lblGitHubStatus.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
}
}

private bool HasHardcodedGitHubToken()
{
try
{
// Check if GithubReleaseService has a hardcoded token
using (var service = new GithubReleaseService())
{
// The service uses hardcoded token if no token is passed and one exists
// We can check this by seeing if it adds an Authorization header
return service.HasAuthToken();
}
}
catch
{
return false;
}
}

private void UpdateSourceUI()
{
if (currentSource == _updateSource.Web)
Expand Down Expand Up @@ -370,7 +327,7 @@ private async System.Threading.Tasks.Task CheckForUpdatesAsync()
SetStatus("Checking GitHub releases...");
bool includePrerelease = chkIncludePrerelease.Checked;
var (hasUpdate, releaseInfo, message) = await _updateService.CheckForUpdate(
_currentVersion, includePrerelease, _gitHubToken);
_currentVersion, includePrerelease);

_availableUpdate = releaseInfo;

Expand Down Expand Up @@ -510,7 +467,7 @@ private async System.Threading.Tasks.Task InstallUpdateAsync(CancellationToken t
});

var (downloaded, dlPath, downloadMsg) = await _updateService.DownloadUpdate(
_availableUpdate, tempDir, progress, _gitHubToken);
_availableUpdate, tempDir, progress);

token.ThrowIfCancellationRequested();

Expand Down
11 changes: 5 additions & 6 deletions SourceCode/Updater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ internal static class Program
[STAThread]
private static void Main()
{
if (!System.Diagnostics.Debugger.IsAttached)
{
System.Diagnostics.Debugger.Launch();
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

// Parse command line arguments
string currentVersion = null;
string installPath = null;
string gitHubToken = null;
bool showFirmwareUpdate = false;

var args = Environment.GetCommandLineArgs();
Expand All @@ -37,10 +40,6 @@ private static void Main()
{
installPath = args[++i];
}
else if (arg.Equals("--github-token", StringComparison.OrdinalIgnoreCase) && i + 1 < args.Length)
{
gitHubToken = args[++i];
}
else if (arg.Equals("--firmware", StringComparison.OrdinalIgnoreCase))
{
showFirmwareUpdate = true;
Expand All @@ -54,7 +53,7 @@ private static void Main()
}
else
{
Application.Run(new FormUpdate(currentVersion, installPath, gitHubToken));
Application.Run(new FormUpdate(currentVersion, installPath));
}
}
}
Expand Down
16 changes: 1 addition & 15 deletions SourceCode/Updater/Services/GithubReleaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,15 @@ public class GithubReleaseService : IDisposable
private const string DefaultRepository = "AgOpenGPS";
private const string GithubApiUrl = "https://api.github.com";

// GitHub Personal Access Token for updater (read-only, increases rate limit to 5000/hr)
private const string GitHubToken = "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";

private readonly HttpClient _httpClient;
private readonly string _owner;
private readonly string _repository;
private readonly string _authToken;

public GithubReleaseService(string owner = null, string repository = null, string authToken = null)
public GithubReleaseService(string owner = null, string repository = null)
{
_owner = owner ?? DefaultOwner;
_repository = repository ?? DefaultRepository;
// Use provided token or fall back to default read-only token
_authToken = authToken ?? GitHubToken;

_httpClient = new HttpClient
{
Expand All @@ -44,10 +39,6 @@ public GithubReleaseService(string owner = null, string repository = null, strin
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json"));
_httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("AgOpenGPS-Updater", "1.0"));

if (!string.IsNullOrEmpty(_authToken))
{
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", _authToken);
}
}

/// <summary>
Expand Down Expand Up @@ -328,11 +319,6 @@ public async Task<ReleaseInfo> CheckForUpdate(string currentVersion, bool includ
/// <summary>
/// Checks if this service has an authentication token.
/// </summary>
public bool HasAuthToken()
{
return !string.IsNullOrEmpty(_authToken);
}

public void Dispose()
{
_httpClient?.Dispose();
Expand Down
8 changes: 4 additions & 4 deletions SourceCode/Updater/Services/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class UpdateService
/// Checks for updates and returns the release info if an update is available.
/// </summary>
public async Task<(bool HasUpdate, ReleaseInfo ReleaseInfo, string Message)> CheckForUpdate(
string currentVersion, bool includePrerelease = false, string gitHubToken = null)
string currentVersion, bool includePrerelease = false)
{
try
{
using (var githubService = new GithubReleaseService(authToken: gitHubToken))
using (var githubService = new GithubReleaseService())
{
var updateInfo = await githubService.CheckForUpdate(currentVersion, includePrerelease);

Expand All @@ -52,7 +52,7 @@ public class UpdateService
/// Downloads an update release to the specified path.
/// </summary>
public async Task<(bool Success, string DownloadPath, string Message)> DownloadUpdate(
ReleaseInfo release, string targetDirectory, IProgress<double> progress = null, string gitHubToken = null)
ReleaseInfo release, string targetDirectory, IProgress<double> progress = null)
{
try
{
Expand All @@ -77,7 +77,7 @@ public class UpdateService

string downloadPath = Path.Combine(targetDirectory, Path.GetFileName(asset.Name));

using (var githubService = new GithubReleaseService(authToken: gitHubToken))
using (var githubService = new GithubReleaseService())
{
await githubService.DownloadAsset(asset.BrowserDownloadUrl, downloadPath, progress);
}
Expand Down
Loading