Commit dfa72a81 authored by DigitalNikki's avatar DigitalNikki

...

Add all files to repository
parent 3a733c39
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
[Oo]bj/
# Added Types
*.pfx
*.ignore
# mstest test results
TestResults
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
## *.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.log
*.vspscc
*.vssscc
.builds
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Publish Web Output
*.Publish.xml
# NuGet Packages Directory
packages
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
[Bb]in
[Oo]bj
sql
TestResults
[Tt]est[Rr]esult*
*.Cache
ClientBin
[Ss]tyle[Cc]op.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
.vs/
Installers/*setup.exe
# How to contribute
Until it is decided how to have this done, contributions will not be accepted.
// File changed by aDigitalPhantom/Nicole M on Jan/21/2018
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using GamingBorderless.Logic.Models;
using GamingBorderless.Logic.System;
namespace GamingBorderless.Logic.Core
{
public class LanguageManager
{
public static string CurrentCulture { get; set; }
private static readonly HashSet<string> CultureNames = CreateCultureNames();
private static readonly string _archiveName = "Languages.zip";
private static Dictionary<string, Language> Languages { get; set; }
private static HashSet<string> CreateCultureNames()
{
var cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures)
.Where(x => !string.IsNullOrEmpty(x.Name))
.ToArray();
var allNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
allNames.UnionWith(cultureInfos.Select(x => x.TwoLetterISOLanguageName));
allNames.UnionWith(cultureInfos.Select(x => x.Name));
return allNames;
}
private static bool CultureExists(string name)
{
return CultureNames.Contains(name);
}
public static string Data(string key)
{
key = key.ToLower();
var culture = Thread.CurrentThread.CurrentCulture.Name;
var lang = Languages[culture];
var data = lang.Data(key);
if (string.IsNullOrWhiteSpace(data))
{
MessageBox.Show($"{lang.Culture} is missing a translation for {key}");
Environment.Exit(0);
}
return data;
}
public static void Load()
{
Languages = new Dictionary<string, Language>();
if (File.Exists(_archiveName))
{
try
{
Tools.ExtractZipFile(_archiveName, string.Empty, AppEnvironment.LanguagePath);
}
catch (Exception e)
{
MessageBox.Show("Failed to extract the language pack. Please report this: " + e.Message);
Environment.Exit(1);
}
}
if (!Directory.Exists(AppEnvironment.LanguagePath))
{
MessageBox.Show("UI Translations are missing from disk.");
Environment.Exit(1);
}
foreach (var langFile in Directory.GetFiles(AppEnvironment.LanguagePath, "*.lang"))
{
var culture = Path.GetFileNameWithoutExtension(langFile);
if (culture != null && CultureExists(culture) && !Languages.ContainsKey(culture))
{
var lang = new Language {Culture = culture};
lang.LoadData(langFile);
if (lang.LanguageData != null)
{
Languages.Add(culture, lang);
}
}
}
if (Languages.Count <= 0)
{
MessageBox.Show($"No Langauges have been loaded! Ensure {AppEnvironment.LanguagePath} exist with at least one .lang file.");
Environment.Exit(0);
}
var defaultLang = Languages.Values.FirstOrDefault(lang => lang.Culture.Equals(Config.Instance.AppSettings.DefaultCulture));
defaultLang?.Set();
}
public static void Setup(ToolStripMenuItem toolStripLanguages)
{
foreach (var lang in Languages.Values)
{
var item = toolStripLanguages.DropDownItems.Add(new ToolStripMenuItem
{
Text = lang.ToString(),
CheckOnClick = true,
Checked = IsDefault(lang.DisplayName)
});
toolStripLanguages.DropDownItems[item].Click += (s, ea) =>
{
var tt = (ToolStripMenuItem)s;
if (!tt.Checked)
{
if (IsDefault(tt.Text) && !LanguageSelected(toolStripLanguages.DropDownItems))
{
tt.Checked = true;
}
return;
}
foreach (ToolStripMenuItem dropItem in toolStripLanguages.DropDownItems)
{
if (dropItem != tt)
{
dropItem.Checked = false;
}
}
SetDefaultLanguage(tt.Text);
};
}
}
private static bool LanguageSelected(ToolStripItemCollection dropDownItems)
{
var anyChecked = false;
foreach (ToolStripMenuItem dropItem in dropDownItems)
{
anyChecked = dropItem.Checked;
}
return anyChecked;
}
private static bool IsDefault(string displayName)
{
var defaultCulture = Config.Instance.AppSettings.DefaultCulture;
var langauge = Languages.Values.FirstOrDefault(lang => lang.DisplayName.Equals(displayName));
return langauge != null && langauge.Culture.Equals(defaultCulture);
}
private static void SetDefaultLanguage(string tsiText)
{
var langauge = Languages.Values.FirstOrDefault(lang => lang.DisplayName.Equals(tsiText));
if (langauge != null)
{
Config.Instance.AppSettings.DefaultCulture = langauge.Culture;
Config.Save();
langauge.Set();
var dialogResult = MessageBox.Show(Data("settingConfirmationPrompt"), Data("settingConfirmationTitle"),
MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
string batchContent = "/c \"@ECHO OFF & timeout /t 6 > nul & start \"\" \"$[APPPATH]$\" & exit\"";
batchContent = batchContent.Replace("$[APPPATH]$", Application.ExecutablePath);
Process.Start("cmd", batchContent);
Application.Exit();
}
}
}
}
}
\ No newline at end of file
// File changed by aDigitalPhantom/Nicole M on Jan/21/2018
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using GamingBorderless.Logic.Extensions;
using GamingBorderless.Logic.Models;
using GamingBorderless.Logic.System.Utilities;
using GamingBorderless.Logic.Windows;
namespace GamingBorderless.Logic.Core
{
public class ProcessWatcher
{
private readonly Form _form;
private CancellationTokenSource _watcherToken;
private Action<ProcessDetails, bool> _callback;
//Holds a list of process details
public List<ProcessDetails> Processes { get; }
public bool AutoHandleFavorites { get; set; }
private readonly object _updateLock = new object();
public ProcessWatcher(Form form)
{
_form = form;
AutoHandleFavorites = true;
Processes = new List<ProcessDetails>();
}
public ProcessDetails FromHandle(IntPtr hCurrentActiveWindow)
{
return Processes.FirstOrDefault(pd => pd.WindowHandle == hCurrentActiveWindow);
}
public Task Refresh()
{
Processes.Clear();
return Task.Factory.StartNew(UpdateProcesses);
}
public void Start(Action<ProcessDetails, bool> callback)
{
_callback = callback;
_watcherToken = new CancellationTokenSource();
Task.Factory.StartNew(Watch, _watcherToken.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
private async void Watch()
{
while (!_watcherToken.IsCancellationRequested)
{
UpdateProcesses();
if (AutoHandleFavorites)
{
// check favorites against the cache
foreach (var pd in Processes)
{
try
{
foreach (var favProcess in Config.Instance.Favorites)
{
if (favProcess.Matches(pd))
{
favProcess.IsRunning = true;
favProcess.RunningId = pd.Proc.Id;
RemoveBorder(pd, favProcess);
}
}
}
catch
{
// ignored
}
}
}
await Task.Delay(TimeSpan.FromSeconds((Config.Instance.AppSettings.SlowWindowDetection ? 10 : 3)));
}
}
/// <summary>
/// remove the menu, resize the window, remove border, and maximize
/// </summary>
public void RemoveBorder(ProcessDetails pd, Favorite favDetails = null, bool overrideTimeout = false)
{
if (favDetails != null && favDetails.DelayBorderless && overrideTimeout == false)
{
//Wait 10 seconds before removing the border.
var task = new Task(() => RemoveBorder(pd, favDetails, true));
task.Wait(TimeSpan.FromSeconds(10));
}
// If a Favorite screen exists, use the Rect from that, instead
if (favDetails?.FavScreen != null)
{
RemoveBorder_ToSpecificRect(pd, PRectangle.ToRectangle(favDetails.FavScreen), favDetails,
overrideTimeout);
return;
}
Manipulation.MakeWindowBorderless(pd, _form, pd.WindowHandle, new Rectangle(), favDetails ?? Favorite.FromWindow(pd));
}
/// <summary>
/// remove the menu, resize the window, remove border, and maximize
/// </summary>
public void RemoveBorder_ToSpecificScreen(IntPtr hWnd, Screen screen, Favorite favDetails = null,
bool overrideTimeout = false)
{
if (favDetails != null && favDetails.DelayBorderless && overrideTimeout == false)
{
//Wait 10 seconds before removing the border.
var task = new Task(() => RemoveBorder_ToSpecificScreen(hWnd, screen, favDetails, true));
task.Wait(TimeSpan.FromSeconds(10));
}
var pd = FromHandle(hWnd);
Manipulation.MakeWindowBorderless(pd, _form, hWnd, screen.Bounds, favDetails ?? Favorite.FromWindow(pd));
}
/// <summary>
/// remove the menu, resize the window, remove border, and maximize
/// </summary>
public void RemoveBorder_ToSpecificRect(IntPtr hWnd, Rectangle targetFrame, Favorite favDetails = null,
bool overrideTimeout = false)
{
if (favDetails != null && favDetails.DelayBorderless && overrideTimeout == false)
{
//Wait 10 seconds before removing the border.
var task = new Task(() => RemoveBorder_ToSpecificRect(hWnd, targetFrame, favDetails, true));
task.Wait(TimeSpan.FromSeconds(10));
}
var pd = FromHandle(hWnd);
Manipulation.MakeWindowBorderless(pd, _form, hWnd, targetFrame, favDetails ?? Favorite.FromWindow(pd));
}
/// <summary>
/// Handle a removed process
/// </summary>
/// <param name="pd"></param>
private void HandlePrunedProcess(ProcessDetails pd)
{
// If we made this process borderless at some point, then check for a favorite that matches and undo
// some stuff to Windows.
foreach (var fav in Config.Instance.Favorites)
{
if (fav.Matches(pd))
{
fav.IsRunning = false;
if (fav.HideWindowsTaskbar)
{
Manipulation.ToggleWindowsTaskbarVisibility(Boolstate.True);
}
if (fav.HideMouseCursor)
{
Manipulation.ToggleMouseCursorVisibility(_form, Boolstate.True);
}
}
}
}
private void UpdateProcesses()
{
if (!AutoHandleFavorites)
{
if (_form != null)
{
if (_form.WindowState == FormWindowState.Minimized || !_form.Visible)
{
return;
}
}
}
foreach (var process in Processes.ToList())
{
var index = Processes.FindIndex(x => x.WindowHandle == process.WindowHandle);
var shouldBePruned = process.ProcessHasExited;
if (!shouldBePruned)
{
var currentTitle = "";
if (!process.NoAccess)
{
TaskUtilities.StartTaskAndWait(() => { currentTitle = Native.GetWindowTitle(process.WindowHandle); },
Config.Instance.AppSettings.SlowWindowDetection ? 10 : 2); shouldBePruned = process.WindowTitle != currentTitle;
}
}
if (shouldBePruned)
{
if (process.MadeBorderless)
{
HandlePrunedProcess(process);
}
Processes.RemoveAt(index);
_callback(process, true);
}
}
Native.QueryProcessesWithWindows(pd =>
{
try
{
if (!string.IsNullOrWhiteSpace(pd?.Proc?.ProcessName))
{
if (Config.Instance.IsHidden(pd?.Proc?.ProcessName))
{
return;
}
if (Processes.Select(p => p.Proc.Id).Contains(pd.Proc.Id) &&
Processes.Select(p => p.WindowTitle).Contains(pd.WindowTitle))
{
return;
}
Processes.Add(pd);
_callback(pd, false);
}
}
catch (Exception)
{
_callback(null, false);
}
}, Processes.Where(p => p.WindowHandle != IntPtr.Zero).Select(p => p.WindowHandle).ToList());
}
}
}
\ No newline at end of file
// File changed by aDigitalPhantom/Nicole M on Jan/21/2018
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GamingBorderless.Logic.Extensions
{
public static class CrossThreadExtensions
{
public static List<T> CloneList<T>(List<T> oldList)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, oldList);
stream.Position = 0;