Skip to content

Commit

Permalink
Increase max line length to 120
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Apr 29, 2020
1 parent 38b8709 commit 3f44639
Show file tree
Hide file tree
Showing 34 changed files with 208 additions and 272 deletions.
7 changes: 7 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# All files
[*]
guidelines = 80

# C# files
[*.cs]
guidelines = 80, 120
6 changes: 2 additions & 4 deletions src/AboutDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ namespace WinDynamicDesktop
public partial class AboutDialog : Form
{
private static readonly Func<string, string> _ = Localization.GetTranslation;
private static readonly string websiteLink =
"https://github.com/t1m0thyj/WinDynamicDesktop";
private static readonly string websiteLink = "https://github.com/t1m0thyj/WinDynamicDesktop";
private static readonly string donateLink = "https://paypal.me/t1m0thyj";

public AboutDialog()
Expand All @@ -41,8 +40,7 @@ public AboutDialog()
websiteLabel.Width = minWidth;
}

minWidth = minWidth + (descriptionLabel.Width - minWidth) / 2 +
descriptionLabel.Location.X * 2;
minWidth = minWidth + (descriptionLabel.Width - minWidth) / 2 + descriptionLabel.Location.X * 2;

if (this.Size.Width < minWidth)
{
Expand Down
12 changes: 5 additions & 7 deletions src/AppContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ private void HandleMultiInstance()
}
else
{
MessageDialog.ShowWarning(_("Another instance of WinDynamicDesktop is " +
"already running. You can access it by clicking on the icon in the " +
"system tray."), _("Error"));
MessageDialog.ShowWarning(_("Another instance of WinDynamicDesktop is already running. You can " +
"access it by clicking on the icon in the system tray."), _("Error"));
}

Environment.Exit(0);
Expand Down Expand Up @@ -96,15 +95,13 @@ public static void ShowPopup(string message, string title = null)
notifyIcon.ShowBalloonTip(10000);
}

private void OnNamedPipeClientMessage(NamedPipeConnection<string, string> conn,
string message)
private void OnNamedPipeClientMessage(NamedPipeConnection<string, string> conn, string message)
{
ThemeManager.importPaths.AddRange(message.Split('|'));

if (!ThemeManager.importMode)
{
notifyIcon.ContextMenuStrip.BeginInvoke(
new Action(() => ThemeManager.SelectTheme()));
notifyIcon.ContextMenuStrip.BeginInvoke(new Action(() => ThemeManager.SelectTheme()));
}
}

Expand Down Expand Up @@ -133,6 +130,7 @@ private void OnApplicationExit(object sender, EventArgs e)
}

_namedPipe?.Stop();
_mutex?.Dispose();
}
}
}
3 changes: 1 addition & 2 deletions src/DebugLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public static void WriteLogFile()

if (Directory.Exists("themes"))
{
foreach (string path in Directory.EnumerateFiles("themes", "*",
SearchOption.AllDirectories))
foreach (string path in Directory.EnumerateFiles("themes", "*", SearchOption.AllDirectories))
{
debugLog.WriteLine("./" + path.Replace('\\', '/'));

Expand Down
11 changes: 5 additions & 6 deletions src/DefaultThemes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class DefaultThemes
public static string[] GetDefaultThemes()
{
string yamlText = Encoding.UTF8.GetString(Properties.Resources.default_themes);
yamlLines = yamlText.Split(new[] { Environment.NewLine },
StringSplitOptions.RemoveEmptyEntries).Select((line) => line.Trim()).ToArray();
yamlLines = yamlText.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.Select((line) => line.Trim()).ToArray();

return yamlLines.Where((line) => !line.StartsWith("-")).Select(
(line) => line.Substring(0, line.Length - 1)).ToArray();
return yamlLines.Where((line) => !line.StartsWith("-"))
.Select((line) => line.Substring(0, line.Length - 1)).ToArray();
}

public static Uri[] GetThemeUriList(string themeId)
Expand All @@ -31,8 +31,7 @@ public static Uri[] GetThemeUriList(string themeId)

while ((startIndex < yamlLines.Length) && yamlLines[startIndex].StartsWith("-"))
{
uriList.Add(new Uri(yamlLines[startIndex].Substring(
yamlLines[startIndex].LastIndexOf(" ") + 1)));
uriList.Add(new Uri(yamlLines[startIndex].Substring(yamlLines[startIndex].LastIndexOf(" ") + 1)));
startIndex++;
}

Expand Down
3 changes: 1 addition & 2 deletions src/DesktopHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ namespace WinDynamicDesktop
{
class DesktopHelper : PlatformHelper
{
private const string registryStartupLocation =
@"Software\Microsoft\Windows\CurrentVersion\Run";
private const string registryStartupLocation = @"Software\Microsoft\Windows\CurrentVersion\Run";
private const string updateLink = "https://github.com/t1m0thyj/WinDynamicDesktop/releases";

private bool startOnBoot;
Expand Down
9 changes: 3 additions & 6 deletions src/DownloadDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public void InitDownload(ThemeConfig theme)
{
ThemeManager.downloadMode = true;
this.Invoke(new Action(() =>
label1.Text = string.Format(_("Downloading images for '{0}'..."),
ThemeManager.GetThemeName(theme))));
label1.Text = string.Format(_("Downloading images for '{0}'..."), ThemeManager.GetThemeName(theme))));

imagesZipDest = theme.themeId + "_images.zip";
themeUris = DefaultThemes.GetThemeUriList(theme.themeId).ToList();
Expand All @@ -70,8 +69,7 @@ private void UpdatePercentage(int percentage)
private bool EnsureZipNotHtml()
{
// Handle case where HTML page gets downloaded instead of ZIP
return (File.Exists(imagesZipDest) &&
((new FileInfo(imagesZipDest)).Length > 1024 * 1024));
return (File.Exists(imagesZipDest) && ((new FileInfo(imagesZipDest)).Length > 1024 * 1024));
}

private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
Expand Down Expand Up @@ -104,8 +102,7 @@ public async void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs
if ((e.Error == null) && EnsureZipNotHtml())
{
cancelButton.Enabled = false;
ThemeResult result = await Task.Run(
() => ThemeLoader.ExtractTheme(imagesZipDest, theme.themeId));
ThemeResult result = await Task.Run(() => ThemeLoader.ExtractTheme(imagesZipDest, theme.themeId));
result.Match(ThemeLoader.HandleError, newTheme =>
{
int themeIndex = ThemeManager.themeSettings.FindIndex(t => t.themeId == newTheme.themeId);
Expand Down
16 changes: 8 additions & 8 deletions src/DpiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ private enum ProcessDpiAwareness

private enum DpiAwarenessContext
{
DpiAwarenessContextUnaware = -1,
DpiAwarenessContextSystemAware = -2,
DpiAwarenessContextPerMonitorAware = -3,
DpiAwarenessContextPerMonitorAwareV2 = -4
DpiAwarenessUnaware = -1,
DpiAwarenessSystemAware = -2,
DpiAwarenessPerMonitorAware = -3,
DpiAwarenessPerMonitorAwareV2 = -4
}

[DllImport("user32.dll", SetLastError = true)]
Expand All @@ -38,10 +38,10 @@ private enum DpiAwarenessContext
[DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();

[DllImport("kernel32.dll", SetLastError = true)]
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern IntPtr LoadLibrary(string fileName);

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);

public static void SetDpiAwareness()
Expand All @@ -51,8 +51,8 @@ public static void SetDpiAwareness()

if (method != IntPtr.Zero)
{
if (SetProcessDpiAwarenessContext((IntPtr)DpiAwarenessContext.DpiAwarenessContextPerMonitorAwareV2) ||
SetProcessDpiAwarenessContext((IntPtr)DpiAwarenessContext.DpiAwarenessContextPerMonitorAware))
if (SetProcessDpiAwarenessContext((IntPtr)DpiAwarenessContext.DpiAwarenessPerMonitorAwareV2) ||
SetProcessDpiAwarenessContext((IntPtr)DpiAwarenessContext.DpiAwarenessPerMonitorAware))
{
return;
}
Expand Down
16 changes: 9 additions & 7 deletions src/FullScreenApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ private struct RECT
private static extern bool UnhookWinEvent(IntPtr hWinEventHook);

[DllImport("user32.dll")]
private static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);
private static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc,
WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);

private const uint WINEVENT_OUTOFCONTEXT = 0;
private const uint EVENT_SYSTEM_FOREGROUND = 3;

private delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
private delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject,
int idChild, uint dwEventThread, uint dwmsEventTime);

public FullScreenApi(WallpaperChangeScheduler wcs)
{
timerEventHandler = new Action(() => { wcs.HandleTimerEvent(true); });
timerEventHandler = new Action(() => wcs.HandleTimerEvent(true));

if (JsonConfig.settings.fullScreenPause)
{
Expand All @@ -76,8 +78,8 @@ private void SetFullScreenPause(bool fullScreenPause)
if (fullScreenPause)
{
winEventProc = new WinEventDelegate(WinEventProc);
winEventHook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND,
IntPtr.Zero, winEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
winEventHook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, IntPtr.Zero,
winEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
}
else
{
Expand Down Expand Up @@ -109,8 +111,8 @@ private bool IsRunningFullScreen()
return false;
}

private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject,
int idChild, uint dwEventThread, uint dwmsEventTime)
private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild,
uint dwEventThread, uint dwmsEventTime)
{
runningFullScreen = IsRunningFullScreen();

Expand Down
3 changes: 1 addition & 2 deletions src/ImportDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ private void ImportNext()
{
string themePath = importQueue.Peek();
this.Invoke(new Action(() =>
label1.Text = string.Format(_("Importing theme from {0}..."),
Path.GetFileName(themePath))));
label1.Text = string.Format(_("Importing theme from {0}..."), Path.GetFileName(themePath))));

ThemeResult result = ThemeManager.ImportTheme(themePath);
result.Match(e => this.Invoke(new Action(() => ThemeLoader.HandleError(e))),
Expand Down
4 changes: 2 additions & 2 deletions src/JsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public static void LoadConfig()
}
catch (JsonReaderException)
{
MessageDialog.ShowWarning("Your WinDynamicDesktop configuration file was " +
"corrupt and has been reset to the default settings.", "Warning");
MessageDialog.ShowWarning("Your WinDynamicDesktop configuration file was corrupt and has been " +
"reset to the default settings.", "Warning");
firstRun = true;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/LanguageDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ private void okButton_Click(object sender, EventArgs e)

if (AppContext.notifyIcon != null)
{
DialogResult result = MessageDialog.ShowQuestion(_("WinDynamicDesktop needs " +
"to restart for the language to change. Do you want to restart the app " +
"now?"), _("Question"));
DialogResult result = MessageDialog.ShowQuestion(_("WinDynamicDesktop needs to restart for the " +
"language to change. Do you want to restart the app now?"), _("Question"));

if (result == DialogResult.Yes)
{
Expand Down
14 changes: 6 additions & 8 deletions src/LaunchSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ public static bool IsLocationReady()
{
if (!JsonConfig.settings.dontUseLocation)
{
return (JsonConfig.settings.latitude != null &&
JsonConfig.settings.longitude != null);
return (JsonConfig.settings.latitude != null && JsonConfig.settings.longitude != null);
}
else
{
return (JsonConfig.settings.sunriseTime != null &&
JsonConfig.settings.sunsetTime != null);
return (JsonConfig.settings.sunriseTime != null && JsonConfig.settings.sunsetTime != null);
}
}

Expand All @@ -42,8 +40,8 @@ public static void NextStep(bool themeReadyOverride = false)

if (JsonConfig.firstRun)
{
AppContext.ShowPopup(_("Welcome! Please enter your location so the app can " +
"determine sunrise and sunset times."));
AppContext.ShowPopup(_("Welcome! Please enter your location so the app can determine sunrise and " +
"sunset times."));
}
}
else if (!IsThemeReady() && !themeReadyOverride) // Override if theme=None chosen
Expand All @@ -52,8 +50,8 @@ public static void NextStep(bool themeReadyOverride = false)
}
else if (JsonConfig.firstRun)
{
AppContext.ShowPopup(_("The app is still running in the background. You can " +
"access it at any time by clicking on the icon in the system tray."));
AppContext.ShowPopup(_("The app is still running in the background. You can access it at any time by " +
"clicking on the icon in the system tray."));

JsonConfig.firstRun = false; // Don't show this message again
}
Expand Down
12 changes: 5 additions & 7 deletions src/LocationIQ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ private static void HandleLocationSuccess(LocationIQData data, ScheduleDialog di
JsonConfig.settings.longitude = data.lon;
SolarData solarData = SunriseSunsetService.GetSolarData(DateTime.Today);

DialogResult result = MessageDialog.ShowQuestion(string.Format(_("Is this location " +
"correct?\n\n{0}\n{1}"), data.display_name,
SunriseSunsetService.GetSunriseSunsetString(solarData)), _("Question"), true);
DialogResult result = MessageDialog.ShowQuestion(string.Format(_("Is this location correct?\n\n{0}\n{1}"),
data.display_name, SunriseSunsetService.GetSunriseSunsetString(solarData)), _("Question"), true);

if (result == DialogResult.Yes)
{
Expand Down Expand Up @@ -54,10 +53,9 @@ public static void GetLocationData(string locationStr, ScheduleDialog dialog)
}
else
{
MessageDialog.ShowWarning(_("The location you entered was invalid, or you " +
"are not connected to the Internet. Check your Internet connection and " +
"try a different location. You can use a complete address or just the " +
"name of your city/region."), _("Error"));
MessageDialog.ShowWarning(_("The location you entered was invalid, or you are not connected to " +
"the Internet. Check your Internet connection and try a different location. You can use a " +
"complete address or just the name of your city/region."), _("Error"));
}
});
}
Expand Down
15 changes: 5 additions & 10 deletions src/MessageDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,24 @@ class MessageDialog
{
public static DialogResult ShowError(string message, string title = null)
{
return MessageBox.Show(message, title ?? "WinDynamicDesktop", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return MessageBox.Show(message, title ?? "WinDynamicDesktop", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

public static DialogResult ShowInfo(string message, string title = null,
bool cancelButton = false)
public static DialogResult ShowInfo(string message, string title = null, bool cancelButton = false)
{
return MessageBox.Show(message, title ?? "WinDynamicDesktop",
cancelButton ? MessageBoxButtons.OKCancel : MessageBoxButtons.OK,
MessageBoxIcon.Information);
cancelButton ? MessageBoxButtons.OKCancel : MessageBoxButtons.OK, MessageBoxIcon.Information);
}

public static DialogResult ShowQuestion(string message, string title = null,
bool useWarningIcon = false)
public static DialogResult ShowQuestion(string message, string title = null, bool useWarningIcon = false)
{
return MessageBox.Show(message, title ?? "WinDynamicDesktop", MessageBoxButtons.YesNo,
useWarningIcon ? MessageBoxIcon.Warning : MessageBoxIcon.Question);
}

public static DialogResult ShowWarning(string message, string title = null)
{
return MessageBox.Show(message, title ?? "WinDynamicDesktop", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return MessageBox.Show(message, title ?? "WinDynamicDesktop", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
Loading

0 comments on commit 3f44639

Please sign in to comment.