mirror of
https://github.com/ShareX/ShareX.git
synced 2025-12-27 23:44:52 +00:00
Code refactoring
This commit is contained in:
parent
4c866a3c64
commit
d208732231
@ -102,28 +102,28 @@ namespace ShareX.HelpersLib
|
||||
btnCancel = new Button();
|
||||
txtInputText = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
//
|
||||
// btnOK
|
||||
//
|
||||
//
|
||||
resources.ApplyResources(btnOK, "btnOK");
|
||||
btnOK.Name = "btnOK";
|
||||
btnOK.UseVisualStyleBackColor = true;
|
||||
btnOK.Click += btnOK_Click;
|
||||
//
|
||||
//
|
||||
// btnCancel
|
||||
//
|
||||
//
|
||||
resources.ApplyResources(btnCancel, "btnCancel");
|
||||
btnCancel.Name = "btnCancel";
|
||||
btnCancel.UseVisualStyleBackColor = true;
|
||||
btnCancel.Click += btnCancel_Click;
|
||||
//
|
||||
//
|
||||
// txtInputText
|
||||
//
|
||||
//
|
||||
resources.ApplyResources(txtInputText, "txtInputText");
|
||||
txtInputText.Name = "txtInputText";
|
||||
//
|
||||
//
|
||||
// InputBox
|
||||
//
|
||||
//
|
||||
AcceptButton = btnOK;
|
||||
resources.ApplyResources(this, "$this");
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
|
||||
@ -3094,4 +3094,4 @@ namespace ShareX.HelpersLib
|
||||
return Convert.ToBase64String(imageBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -327,4 +327,4 @@ namespace ShareX.ScreenCaptureLib
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,9 +52,9 @@ namespace ShareX
|
||||
}
|
||||
}
|
||||
|
||||
private const string UploadersConfigFileName = "UploadersConfig.json";
|
||||
private const string UploadersConfigFileNamePrefix = "UploadersConfig";
|
||||
private const string UploadersConfigFileNameExtension = ".json";
|
||||
private const string UploadersConfigFileNamePrefix = "UploadersConfig";
|
||||
private const string UploadersConfigFileNameExtension = "json";
|
||||
private const string UploadersConfigFileName = UploadersConfigFileNamePrefix + "." + UploadersConfigFileNameExtension;
|
||||
|
||||
private static string UploadersConfigFilePath
|
||||
{
|
||||
@ -201,13 +201,13 @@ namespace ShareX
|
||||
return UploadersConfigFileName;
|
||||
}
|
||||
|
||||
if (Settings?.UseMachineSpecificUploadersConfig == true)
|
||||
if (Settings != null && Settings.UseMachineSpecificUploadersConfig)
|
||||
{
|
||||
string sanitizedMachineName = FileHelpers.SanitizeFileName(Environment.MachineName);
|
||||
|
||||
if (!string.IsNullOrEmpty(sanitizedMachineName))
|
||||
{
|
||||
string machineSpecificFileName = $"{UploadersConfigFileNamePrefix}-{sanitizedMachineName}{UploadersConfigFileNameExtension}";
|
||||
string machineSpecificFileName = $"{UploadersConfigFileNamePrefix}-{sanitizedMachineName}.{UploadersConfigFileNameExtension}";
|
||||
string machineSpecificPath = Path.Combine(destinationFolder, machineSpecificFileName);
|
||||
|
||||
if (!File.Exists(machineSpecificPath))
|
||||
|
||||
@ -233,4 +233,4 @@ namespace ShareX
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,4 +59,4 @@ namespace ShareX
|
||||
public bool AutoStartAnalyze { get; set; } = true;
|
||||
public bool AutoCopyResult { get; set; } = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,65 +143,58 @@ namespace ShareX
|
||||
lblTestStatus.ForeColor = Color.Gold;
|
||||
lblTestStatus.Text = "Testing...";
|
||||
|
||||
var client = HttpClientFactory.Create();
|
||||
HttpClient client = HttpClientFactory.Create();
|
||||
HttpRequestMessage req = null;
|
||||
var provider = (AIProvider)cbProvider.SelectedIndex;
|
||||
AIProvider provider = (AIProvider)cbProvider.SelectedIndex;
|
||||
|
||||
switch (provider)
|
||||
{
|
||||
case AIProvider.OpenAI:
|
||||
case AIProvider.Custom:
|
||||
{
|
||||
var key = txtOpenAIAPIKey.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(key))
|
||||
string openAIKey = txtOpenAIAPIKey.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(openAIKey))
|
||||
{
|
||||
lblTestStatus.ForeColor = Color.IndianRed;
|
||||
lblTestStatus.Text = "Missing OpenAI API key.";
|
||||
return;
|
||||
}
|
||||
|
||||
var baseUrl = txtOpenAICustomURL.Text;
|
||||
if (string.IsNullOrWhiteSpace(baseUrl))
|
||||
baseUrl = "https://api.openai.com/v1";
|
||||
baseUrl = baseUrl.Trim().TrimEnd('/');
|
||||
string openAIBaseURL = txtOpenAICustomURL.Text;
|
||||
if (string.IsNullOrWhiteSpace(openAIBaseURL))
|
||||
{
|
||||
openAIBaseURL = "https://api.openai.com/v1";
|
||||
}
|
||||
openAIBaseURL = openAIBaseURL.Trim().TrimEnd('/');
|
||||
|
||||
var url = baseUrl + "/models";
|
||||
req = new HttpRequestMessage(HttpMethod.Get, url);
|
||||
req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", key);
|
||||
string openAIURL = openAIBaseURL + "/models";
|
||||
req = new HttpRequestMessage(HttpMethod.Get, openAIURL);
|
||||
req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", openAIKey);
|
||||
break;
|
||||
}
|
||||
|
||||
case AIProvider.Gemini:
|
||||
{
|
||||
var key = txtGeminiAPIKey.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(key))
|
||||
string geminiKey = txtGeminiAPIKey.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(geminiKey))
|
||||
{
|
||||
lblTestStatus.ForeColor = Color.IndianRed;
|
||||
lblTestStatus.Text = "Missing Gemini API key.";
|
||||
return;
|
||||
}
|
||||
|
||||
var url = "https://generativelanguage.googleapis.com/v1beta/models?key=" + Uri.EscapeDataString(key);
|
||||
req = new HttpRequestMessage(HttpMethod.Get, url);
|
||||
string geminiURL = "https://generativelanguage.googleapis.com/v1beta/models?key=" + Uri.EscapeDataString(geminiKey);
|
||||
req = new HttpRequestMessage(HttpMethod.Get, geminiURL);
|
||||
break;
|
||||
}
|
||||
|
||||
case AIProvider.OpenRouter:
|
||||
{
|
||||
var key = txtOpenRouterAPIKey.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(key))
|
||||
string openRouterKey = txtOpenRouterAPIKey.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(openRouterKey))
|
||||
{
|
||||
lblTestStatus.ForeColor = Color.IndianRed;
|
||||
lblTestStatus.Text = "Missing OpenRouter API key.";
|
||||
return;
|
||||
}
|
||||
|
||||
var url = "https://openrouter.ai/api/v1/models";
|
||||
req = new HttpRequestMessage(HttpMethod.Get, url);
|
||||
req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", key);
|
||||
string openRouterURL = "https://openrouter.ai/api/v1/models";
|
||||
req = new HttpRequestMessage(HttpMethod.Get, openRouterURL);
|
||||
req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", openRouterKey);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
lblTestStatus.ForeColor = Color.IndianRed;
|
||||
lblTestStatus.Text = "Select a provider first.";
|
||||
@ -209,15 +202,15 @@ namespace ShareX
|
||||
}
|
||||
|
||||
using (req)
|
||||
using (var resp = await client.SendAsync(req))
|
||||
using (HttpResponseMessage resp = await client.SendAsync(req))
|
||||
{
|
||||
var ok = (int)resp.StatusCode >= 200 && (int)resp.StatusCode < 300;
|
||||
var text = await resp.Content.ReadAsStringAsync();
|
||||
bool ok = (int)resp.StatusCode >= 200 && (int)resp.StatusCode < 300;
|
||||
string text = await resp.Content.ReadAsStringAsync();
|
||||
|
||||
if (ok)
|
||||
{
|
||||
lblTestStatus.ForeColor = Color.LimeGreen;
|
||||
lblTestStatus.Text = "Connection OK";
|
||||
lblTestStatus.Text = "Connection OK.";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -277,4 +270,4 @@ namespace ShareX
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
#region License Information (GPL v3)
|
||||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
@ -46,4 +46,4 @@ namespace ShareX
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
#region License Information (GPL v3)
|
||||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
@ -95,4 +95,4 @@ namespace ShareX
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
#region License Information (GPL v3)
|
||||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
@ -33,4 +33,4 @@ namespace ShareX
|
||||
Task<string> AnalyzeImage(Image image, string prompt, string reasoningEffort, string verbosity);
|
||||
Task<string> AnalyzeImage(string imagePath, string prompt, string reasoningEffort, string verbosity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
#region License Information (GPL v3)
|
||||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
@ -104,4 +104,4 @@ namespace ShareX
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
#region License Information (GPL v3)
|
||||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
@ -101,4 +101,4 @@ namespace ShareX
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user