1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-09-14 01:32:10 +02:00

Compare commits

..

1 Commits

Author SHA1 Message Date
9238410756 WIP? 2019-05-09 11:54:38 +02:00
140 changed files with 1354 additions and 1550 deletions

4
.github/FUNDING.yml vendored
View File

@@ -1,4 +0,0 @@
# These are supported funding model platforms
patreon: chylex
ko_fi: chylex

View File

@@ -1,5 +1,5 @@
using System;
using TweetLib.Core.Collections;
using TweetDuck.Data;
namespace TweetDuck.Configuration{
static class Arguments{
@@ -22,8 +22,8 @@ namespace TweetDuck.Configuration{
return Current.HasFlag(flag);
}
public static string GetValue(string key){
return Current.GetValue(key);
public static string GetValue(string key, string defaultValue){
return Current.GetValue(key, defaultValue);
}
public static CommandLineArgs GetCurrentClean(){

View File

@@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using TweetDuck.Configuration.Instance;
using TweetDuck.Core.Utils;
using TweetDuck.Data;
using TweetLib.Core.Features.Configuration;
using TweetLib.Core.Features.Plugins.Config;
using TweetLib.Core.Serialization.Converters;
using TweetLib.Core.Utils;
using TweetDuck.Data.Serialization;
namespace TweetDuck.Configuration{
sealed class ConfigManager : IConfigManager{
sealed class ConfigManager{
public UserConfig User { get; }
public SystemConfig System { get; }
public PluginConfig Plugins { get; }
@@ -16,7 +16,7 @@ namespace TweetDuck.Configuration{
private readonly FileConfigInstance<UserConfig> infoUser;
private readonly FileConfigInstance<SystemConfig> infoSystem;
private readonly PluginConfigInstance<PluginConfig> infoPlugins;
private readonly PluginConfigInstance infoPlugins;
private readonly IConfigInstance<BaseConfig>[] infoList;
@@ -28,7 +28,7 @@ namespace TweetDuck.Configuration{
infoList = new IConfigInstance<BaseConfig>[]{
infoUser = new FileConfigInstance<UserConfig>(Program.UserConfigFilePath, User, "program options"),
infoSystem = new FileConfigInstance<SystemConfig>(Program.SystemConfigFilePath, System, "system options"),
infoPlugins = new PluginConfigInstance<PluginConfig>(Program.PluginConfigFilePath, Plugins)
infoPlugins = new PluginConfigInstance(Program.PluginConfigFilePath, Plugins)
};
// TODO refactor further
@@ -70,13 +70,59 @@ namespace TweetDuck.Configuration{
infoPlugins.Reload();
}
void IConfigManager.TriggerProgramRestartRequested(){
private void TriggerProgramRestartRequested(){
ProgramRestartRequested?.Invoke(this, EventArgs.Empty);
}
IConfigInstance<BaseConfig> IConfigManager.GetInstanceInfo(BaseConfig instance){
private IConfigInstance<BaseConfig> GetInstanceInfo(BaseConfig instance){
Type instanceType = instance.GetType();
return Array.Find(infoList, info => info.Instance.GetType() == instanceType); // TODO handle null
}
public abstract class BaseConfig{
private readonly ConfigManager configManager;
protected BaseConfig(ConfigManager configManager){
this.configManager = configManager;
}
// Management
public void Save(){
configManager.GetInstanceInfo(this).Save();
}
public void Reload(){
configManager.GetInstanceInfo(this).Reload();
}
public void Reset(){
configManager.GetInstanceInfo(this).Reset();
}
// Construction methods
public T ConstructWithDefaults<T>() where T : BaseConfig{
return ConstructWithDefaults(configManager) as T;
}
protected abstract BaseConfig ConstructWithDefaults(ConfigManager configManager);
// Utility methods
protected void UpdatePropertyWithEvent<T>(ref T field, T value, EventHandler eventHandler){
if (!EqualityComparer<T>.Default.Equals(field, value)){
field = value;
eventHandler?.Invoke(this, EventArgs.Empty);
}
}
protected void UpdatePropertyWithRestartRequest<T>(ref T field, T value){
if (!EqualityComparer<T>.Default.Equals(field, value)){
field = value;
configManager.TriggerProgramRestartRequested();
}
}
}
}
}

View File

@@ -1,20 +1,22 @@
using System;
using System.IO;
using TweetLib.Core.Serialization;
using TweetDuck.Data.Serialization;
namespace TweetDuck.Configuration.Instance{
sealed class FileConfigInstance<T> : IConfigInstance<T> where T : ConfigManager.BaseConfig{
private const string ErrorTitle = "Configuration Error";
namespace TweetLib.Core.Features.Configuration{
public sealed class FileConfigInstance<T> : IConfigInstance<T> where T : BaseConfig{
public T Instance { get; }
public FileSerializer<T> Serializer { get; }
private readonly string filenameMain;
private readonly string filenameBackup;
private readonly string identifier;
private readonly string errorIdentifier;
public FileConfigInstance(string filename, T instance, string identifier){
public FileConfigInstance(string filename, T instance, string errorIdentifier){
this.filenameMain = filename;
this.filenameBackup = filename + ".bak";
this.identifier = identifier;
this.filenameBackup = filename+".bak";
this.errorIdentifier = errorIdentifier;
this.Instance = instance;
this.Serializer = new FileSerializer<T>();
@@ -25,14 +27,14 @@ namespace TweetLib.Core.Features.Configuration{
}
public void Load(){
Exception? firstException = null;
Exception firstException = null;
for(int attempt = 0; attempt < 2; attempt++){
try{
LoadInternal(attempt > 0);
if (firstException != null){ // silently log exception that caused a backup restore
App.ErrorHandler.Log(firstException.ToString());
Program.Reporter.LogImportant(firstException.ToString());
}
return;
@@ -47,13 +49,13 @@ namespace TweetLib.Core.Features.Configuration{
}
if (firstException is FormatException){
OnException($"The configuration file for {identifier} is outdated or corrupted. If you continue, your {identifier} will be reset.", firstException);
Program.Reporter.HandleException(ErrorTitle, "The configuration file for "+errorIdentifier+" is outdated or corrupted. If you continue, your "+errorIdentifier+" will be reset.", true, firstException);
}
else if (firstException is SerializationSoftException sse){
OnException($"{sse.Errors.Count} error{(sse.Errors.Count == 1 ? " was" : "s were")} encountered while loading the configuration file for {identifier}. If you continue, some of your {identifier} will be reset.", firstException);
Program.Reporter.HandleException(ErrorTitle, $"{sse.Errors.Count} error{(sse.Errors.Count == 1 ? " was" : "s were")} encountered while loading the configuration file for "+errorIdentifier+". If you continue, some of your "+errorIdentifier+" will be reset.", true, firstException);
}
else if (firstException != null){
OnException($"Could not open the configuration file for {identifier}. If you continue, your {identifier} will be reset.", firstException);
Program.Reporter.HandleException(ErrorTitle, "Could not open the configuration file for "+errorIdentifier+". If you continue, your "+errorIdentifier+" will be reset.", true, firstException);
}
}
@@ -66,9 +68,9 @@ namespace TweetLib.Core.Features.Configuration{
Serializer.Write(filenameMain, Instance);
}catch(SerializationSoftException e){
OnException($"{e.Errors.Count} error{(e.Errors.Count == 1 ? " was" : "s were")} encountered while saving the configuration file for {identifier}.", e);
Program.Reporter.HandleException(ErrorTitle, $"{e.Errors.Count} error{(e.Errors.Count == 1 ? " was" : "s were")} encountered while saving the configuration file for "+errorIdentifier+".", true, e);
}catch(Exception e){
OnException($"Could not save the configuration file for {identifier}.", e);
Program.Reporter.HandleException(ErrorTitle, "Could not save the configuration file for "+errorIdentifier+".", true, e);
}
}
@@ -80,10 +82,10 @@ namespace TweetLib.Core.Features.Configuration{
Serializer.Write(filenameMain, Instance.ConstructWithDefaults<T>());
LoadInternal(false);
}catch(Exception e){
OnException($"Could not regenerate the configuration file for {identifier}.", e);
Program.Reporter.HandleException(ErrorTitle, "Could not regenerate the configuration file for "+errorIdentifier+".", true, e);
}
}catch(Exception e){
OnException($"Could not reload the configuration file for {identifier}.", e);
Program.Reporter.HandleException(ErrorTitle, "Could not reload the configuration file for "+errorIdentifier+".", true, e);
}
}
@@ -92,15 +94,11 @@ namespace TweetLib.Core.Features.Configuration{
File.Delete(filenameMain);
File.Delete(filenameBackup);
}catch(Exception e){
OnException($"Could not delete configuration files to reset {identifier}.", e);
Program.Reporter.HandleException(ErrorTitle, "Could not delete configuration files to reset "+errorIdentifier+".", true, e);
return;
}
Reload();
}
private static void OnException(string message, Exception e){
App.ErrorHandler.HandleException("Configuration Error", message, true, e);
}
}
}

View File

@@ -1,5 +1,5 @@
namespace TweetLib.Core.Features.Configuration{
public interface IConfigInstance<out T>{
namespace TweetDuck.Configuration.Instance{
interface IConfigInstance<out T>{
T Instance { get; }
void Save();

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace TweetDuck.Configuration.Instance{
class PluginConfigInstance : IConfigInstance<PluginConfig>{
public PluginConfig Instance { get; }
private readonly string filename;
public PluginConfigInstance(string filename, PluginConfig instance){
this.filename = filename;
this.Instance = instance;
}
public void Load(){
try{
using(StreamReader reader = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read), Encoding.UTF8)){
string line = reader.ReadLine();
if (line == "#Disabled"){
HashSet<string> newDisabled = new HashSet<string>();
while((line = reader.ReadLine()) != null){
newDisabled.Add(line);
}
Instance.ReloadSilently(newDisabled);
}
}
}catch(FileNotFoundException){
}catch(DirectoryNotFoundException){
}catch(Exception e){
Program.Reporter.HandleException("Plugin Configuration Error", "Could not read the plugin configuration file. If you continue, the list of disabled plugins will be reset to default.", true, e);
}
}
public void Save(){
try{
using(StreamWriter writer = new StreamWriter(new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None), Encoding.UTF8)){
writer.WriteLine("#Disabled");
foreach(string identifier in Instance.DisabledPlugins){
writer.WriteLine(identifier);
}
}
}catch(Exception e){
Program.Reporter.HandleException("Plugin Configuration Error", "Could not save the plugin configuration file.", true, e);
}
}
public void Reload(){
Load();
}
public void Reset(){
try{
File.Delete(filename);
Instance.ReloadSilently(Instance.ConstructWithDefaults<PluginConfig>().DisabledPlugins);
}catch(Exception e){
Program.Reporter.HandleException("Plugin Configuration Error", "Could not delete the plugin configuration file.", true, e);
return;
}
Reload();
}
}
}

View File

@@ -1,41 +1,20 @@
using System;
using System.Collections.Generic;
using TweetLib.Core.Features.Configuration;
using TweetLib.Core.Features.Plugins;
using TweetLib.Core.Features.Plugins.Config;
using TweetLib.Core.Features.Plugins.Events;
using TweetDuck.Plugins;
using TweetDuck.Plugins.Events;
namespace TweetDuck.Configuration{
sealed class PluginConfig : BaseConfig, IPluginConfig{
sealed class PluginConfig : ConfigManager.BaseConfig, IPluginConfig{
private static readonly string[] DefaultDisabled = {
"official/clear-columns",
"official/reply-account"
};
// CONFIGURATION DATA
// CONFIGURATION
private readonly HashSet<string> disabled = new HashSet<string>(DefaultDisabled);
// EVENTS
public IEnumerable<string> DisabledPlugins => disabled;
public event EventHandler<PluginChangedStateEventArgs> PluginChangedState;
// END OF CONFIG
public PluginConfig(IConfigManager configManager) : base(configManager){}
protected override BaseConfig ConstructWithDefaults(IConfigManager configManager){
return new PluginConfig(configManager);
}
// INTERFACE IMPLEMENTATION
IEnumerable<string> IPluginConfig.DisabledPlugins => disabled;
void IPluginConfig.Reset(IEnumerable<string> newDisabledPlugins){
disabled.Clear();
disabled.UnionWith(newDisabledPlugins);
}
public void SetEnabled(Plugin plugin, bool enabled){
if ((enabled && disabled.Remove(plugin.Identifier)) || (!enabled && disabled.Add(plugin.Identifier))){
@@ -47,5 +26,20 @@ namespace TweetDuck.Configuration{
public bool IsEnabled(Plugin plugin){
return !disabled.Contains(plugin.Identifier);
}
public void ReloadSilently(IEnumerable<string> newDisabled){
disabled.Clear();
disabled.UnionWith(newDisabled);
}
private readonly HashSet<string> disabled = new HashSet<string>(DefaultDisabled);
// END OF CONFIG
public PluginConfig(ConfigManager configManager) : base(configManager){}
protected override ConfigManager.BaseConfig ConstructWithDefaults(ConfigManager configManager){
return new PluginConfig(configManager);
}
}
}

View File

@@ -1,7 +1,5 @@
using TweetLib.Core.Features.Configuration;
namespace TweetDuck.Configuration{
sealed class SystemConfig : BaseConfig{
namespace TweetDuck.Configuration{
sealed class SystemConfig : ConfigManager.BaseConfig{
// CONFIGURATION DATA
@@ -19,9 +17,9 @@ namespace TweetDuck.Configuration{
// END OF CONFIG
public SystemConfig(IConfigManager configManager) : base(configManager){}
public SystemConfig(ConfigManager configManager) : base(configManager){}
protected override BaseConfig ConstructWithDefaults(IConfigManager configManager){
protected override ConfigManager.BaseConfig ConstructWithDefaults(ConfigManager configManager){
return new SystemConfig(configManager);
}
}

View File

@@ -3,12 +3,11 @@ using System.Drawing;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Notification;
using TweetDuck.Core.Other;
using TweetDuck.Core.Utils;
using TweetDuck.Data;
using TweetLib.Core.Features.Configuration;
using TweetLib.Core.Features.Twitter;
namespace TweetDuck.Configuration{
sealed class UserConfig : BaseConfig{
sealed class UserConfig : ConfigManager.BaseConfig{
// CONFIGURATION DATA
@@ -80,7 +79,7 @@ namespace TweetDuck.Configuration{
public bool IsCustomNotificationSizeSet => CustomNotificationSize != Size.Empty;
public bool IsCustomSoundNotificationSet => NotificationSoundPath != string.Empty;
public ImageQuality TwitterImageQuality => BestImageQuality ? ImageQuality.Best : ImageQuality.Default;
public TwitterUtils.ImageQuality TwitterImageQuality => BestImageQuality ? TwitterUtils.ImageQuality.Orig : TwitterUtils.ImageQuality.Default;
public string NotificationSoundPath{
get => _notificationSoundPath ?? string.Empty;
@@ -136,9 +135,9 @@ namespace TweetDuck.Configuration{
// END OF CONFIG
public UserConfig(IConfigManager configManager) : base(configManager){}
public UserConfig(ConfigManager configManager) : base(configManager){}
protected override BaseConfig ConstructWithDefaults(IConfigManager configManager){
protected override ConfigManager.BaseConfig ConstructWithDefaults(ConfigManager configManager){
return new UserConfig(configManager);
}
}

View File

@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Management;
using TweetDuck.Core.Notification;
@@ -7,7 +6,6 @@ using TweetDuck.Core.Other;
using TweetDuck.Core.Utils;
namespace TweetDuck.Core.Bridge{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
class TweetDeckBridge{
public static string FontSize { get; private set; }
public static string NotificationHeadLayout { get; private set; }
@@ -65,7 +63,7 @@ namespace TweetDuck.Core.Bridge{
}
// Notification only
public sealed class Notification : TweetDeckBridge{
public Notification(FormBrowser form, FormNotificationMain notification) : base(form, notification){}
@@ -119,12 +117,14 @@ namespace TweetDuck.Core.Bridge{
}
public void Alert(string type, string contents){
MessageBoxIcon icon = type switch{
"error" => MessageBoxIcon.Error,
"warning" => MessageBoxIcon.Warning,
"info" => MessageBoxIcon.Information,
_ => MessageBoxIcon.None
};
MessageBoxIcon icon;
switch(type){
case "error": icon = MessageBoxIcon.Error; break;
case "warning": icon = MessageBoxIcon.Warning; break;
case "info": icon = MessageBoxIcon.Information; break;
default: icon = MessageBoxIcon.None; break;
}
FormMessage.Show("TweetDuck Browser Message", contents, icon, FormMessage.OK);
}

View File

@@ -1,11 +1,9 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
using TweetLib.Core.Features.Updates;
using TweetDuck.Updates;
namespace TweetDuck.Core.Bridge{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
class UpdateBridge{
private readonly UpdateHandler updates;
private readonly Control sync;

View File

@@ -1,7 +1,7 @@
using System;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.WindowsAPICodePack.Taskbar;
using TweetDuck.Configuration;
using TweetDuck.Core.Bridge;
using TweetDuck.Core.Controls;
@@ -15,10 +15,9 @@ using TweetDuck.Core.Other.Analytics;
using TweetDuck.Core.Other.Settings.Dialogs;
using TweetDuck.Core.Utils;
using TweetDuck.Plugins;
using TweetDuck.Plugins.Events;
using TweetDuck.Resources;
using TweetDuck.Updates;
using TweetLib.Core.Features.Plugins.Events;
using TweetLib.Core.Features.Updates;
namespace TweetDuck.Core{
sealed partial class FormBrowser : Form, AnalyticsFile.IProvider{
@@ -52,6 +51,7 @@ namespace TweetDuck.Core{
private readonly FormNotificationTweet notification;
private readonly ContextMenu contextMenu;
private readonly UpdateBridge updateBridge;
private readonly TaskbarIcon taskbarIcon;
private bool isLoaded;
private FormWindowState prevState;
@@ -65,7 +65,7 @@ namespace TweetDuck.Core{
Text = Program.BrandName;
this.plugins = new PluginManager(this, Program.Config.Plugins, Program.PluginPath, Program.PluginDataPath);
this.plugins = new PluginManager(Program.Config.Plugins, Program.PluginPath);
this.plugins.Reloaded += plugins_Reloaded;
this.plugins.Executed += plugins_Executed;
this.plugins.Reload();
@@ -73,7 +73,7 @@ namespace TweetDuck.Core{
this.notification = new FormNotificationTweet(this, plugins);
this.notification.Show();
this.updates = new UpdateHandler(new UpdateCheckClient(Program.InstallerPath), TaskScheduler.FromCurrentSynchronizationContext());
this.updates = new UpdateHandler(Program.InstallerPath);
this.updates.CheckFinished += updates_CheckFinished;
this.updateBridge = new UpdateBridge(updates, this);
@@ -86,6 +86,9 @@ namespace TweetDuck.Core{
Controls.Add(new MenuStrip{ Visible = false }); // fixes Alt freezing the program in Win 10 Anniversary Update
this.taskbarIcon = new TaskbarIcon();
Shown += (sender, args) => taskbarIcon.UpdateIcon();
Disposed += (sender, args) => {
Config.MuteToggled -= Config_MuteToggled;
Config.TrayBehaviorChanged -= Config_TrayBehaviorChanged;
@@ -93,6 +96,7 @@ namespace TweetDuck.Core{
browser.Dispose();
updates.Dispose();
contextMenu.Dispose();
taskbarIcon.Dispose();
notificationScreenshotManager?.Dispose();
videoPlayer?.Dispose();
@@ -107,10 +111,6 @@ namespace TweetDuck.Core{
UpdateTray();
if (Config.MuteNotifications){
UpdateFormIcon();
}
if (Config.AllowDataCollection){
analytics = new AnalyticsManager(this, plugins, Program.AnalyticsFilePath);
}
@@ -136,10 +136,6 @@ namespace TweetDuck.Core{
isLoaded = true;
}
private void UpdateFormIcon(){ // TODO fix to show icon in taskbar too
Icon = Config.MuteNotifications ? Properties.Resources.icon_muted : Properties.Resources.icon;
}
private void UpdateTray(){
trayIcon.Visible = Config.TrayBehavior.ShouldDisplayIcon();
}
@@ -154,6 +150,7 @@ namespace TweetDuck.Core{
if (!isLoaded)return;
trayIcon.HasNotifications = false;
taskbarIcon.HasNotifications = false;
if (!browser.Enabled){ // when taking a screenshot, the window is unfocused and
browser.Enabled = true; // the browser is disabled; if the user clicks back into
@@ -215,7 +212,6 @@ namespace TweetDuck.Core{
}
private void Config_MuteToggled(object sender, EventArgs e){
UpdateFormIcon();
AnalyticsFile.NotificationMutes.Trigger();
}
@@ -505,8 +501,12 @@ namespace TweetDuck.Core{
}
public void OnTweetNotification(){ // may be called multiple times, once for each type of notification
if (Config.EnableTrayHighlight && !ContainsFocus){
trayIcon.HasNotifications = true;
if (!ContainsFocus){
if (Config.EnableTrayHighlight){
trayIcon.HasNotifications = true;
}
taskbarIcon.HasNotifications = false;
}
}

View File

@@ -17,6 +17,8 @@ namespace TweetDuck.Core{
else return false;
}
public static bool HasAnyDialogs => Application.OpenForms.OfType<IAppDialog>().Any();
public static void CloseAllDialogs(){
foreach(IAppDialog dialog in Application.OpenForms.OfType<IAppDialog>().Reverse()){
((Form)dialog).Close();

View File

@@ -12,14 +12,12 @@ using TweetDuck.Core.Notification;
using TweetDuck.Core.Other;
using TweetDuck.Core.Other.Analytics;
using TweetDuck.Resources;
using TweetLib.Core.Features.Twitter;
using TweetLib.Core.Utils;
namespace TweetDuck.Core.Handling{
abstract class ContextMenuBase : IContextMenuHandler{
protected static UserConfig Config => Program.Config.User;
private static ImageQuality ImageQuality => Config.TwitterImageQuality;
private static TwitterUtils.ImageQuality ImageQuality => Config.TwitterImageQuality;
private const CefMenuCommand MenuOpenLinkUrl = (CefMenuCommand)26500;
private const CefMenuCommand MenuCopyLinkUrl = (CefMenuCommand)26501;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
@@ -8,7 +9,7 @@ namespace TweetDuck.Core.Handling.General{
sealed class FileDialogHandler : IDialogHandler{
public bool OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, CefFileDialogFlags flags, string title, string defaultFilePath, List<string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback){
if (mode == CefFileDialogMode.Open || mode == CefFileDialogMode.OpenMultiple){
string allFilters = string.Join(";", acceptFilters.SelectMany(ParseFileType).Where(filter => !string.IsNullOrEmpty(filter)).Select(filter => "*" + filter));
string allFilters = string.Join(";", acceptFilters.Select(filter => "*"+filter));
using(OpenFileDialog dialog = new OpenFileDialog{
AutoUpgradeEnabled = true,
@@ -18,8 +19,8 @@ namespace TweetDuck.Core.Handling.General{
Filter = $"All Supported Formats ({allFilters})|{allFilters}|All Files (*.*)|*.*"
}){
if (dialog.ShowDialog() == DialogResult.OK){
string ext = Path.GetExtension(dialog.FileName)?.ToLower();
callback.Continue(acceptFilters.FindIndex(filter => ParseFileType(filter).Contains(ext)), dialog.FileNames.ToList());
string ext = Path.GetExtension(dialog.FileName);
callback.Continue(acceptFilters.FindIndex(filter => filter.Equals(ext, StringComparison.OrdinalIgnoreCase)), dialog.FileNames.ToList());
}
else{
callback.Cancel();
@@ -35,27 +36,5 @@ namespace TweetDuck.Core.Handling.General{
return false;
}
}
private static IEnumerable<string> ParseFileType(string type){
if (string.IsNullOrEmpty(type)){
return new string[0];
}
if (type[0] == '.'){
return new string[]{ type };
}
switch(type){
case "image/jpeg": return new string[]{ ".jpg", ".jpeg" };
case "image/png": return new string[]{ ".png" };
case "image/gif": return new string[]{ ".gif" };
case "image/webp": return new string[]{ ".webp" };
case "video/mp4": return new string[]{ ".mp4" };
case "video/quicktime": return new string[]{ ".mov", ".qt" };
}
System.Diagnostics.Debugger.Break();
return new string[0];
}
}
}

View File

@@ -12,17 +12,15 @@ namespace TweetDuck.Core.Handling.General{
int pipe = text.IndexOf('|');
if (pipe != -1){
icon = text.Substring(0, pipe) switch{
"error" => MessageBoxIcon.Error,
"warning" => MessageBoxIcon.Warning,
"info" => MessageBoxIcon.Information,
"question" => MessageBoxIcon.Question,
_ => MessageBoxIcon.None
};
if (icon != MessageBoxIcon.None){
text = text.Substring(pipe + 1);
switch(text.Substring(0, pipe)){
case "error": icon = MessageBoxIcon.Error; break;
case "warning": icon = MessageBoxIcon.Warning; break;
case "info": icon = MessageBoxIcon.Information; break;
case "question": icon = MessageBoxIcon.Question; break;
default: return new FormMessage(caption, text, icon);
}
text = text.Substring(pipe+1);
}
return new FormMessage(caption, text, icon);

View File

@@ -4,15 +4,11 @@ using TweetDuck.Core.Utils;
namespace TweetDuck.Core.Handling.General{
sealed class LifeSpanHandler : ILifeSpanHandler{
private static bool IsPopupAllowed(string url){
return url.StartsWith("https://twitter.com/teams/authorize?");
}
public static bool HandleLinkClick(IWebBrowser browserControl, WindowOpenDisposition targetDisposition, string targetUrl){
switch(targetDisposition){
case WindowOpenDisposition.NewBackgroundTab:
case WindowOpenDisposition.NewForegroundTab:
case WindowOpenDisposition.NewPopup when !IsPopupAllowed(targetUrl):
case WindowOpenDisposition.NewPopup:
case WindowOpenDisposition.NewWindow:
browserControl.AsControl().InvokeAsyncSafe(() => BrowserUtils.OpenExternalBrowser(targetUrl));
return true;

View File

@@ -7,7 +7,6 @@ using CefSharp;
using CefSharp.Handler;
using TweetDuck.Core.Handling.General;
using TweetDuck.Core.Utils;
using TweetLib.Core.Utils;
namespace TweetDuck.Core.Handling{
class RequestHandlerBase : DefaultRequestHandler{
@@ -22,13 +21,21 @@ namespace TweetDuck.Core.Handling{
TweetDeckHashes.Clear();
foreach(string rule in rules.Replace(" ", "").ToLower().Split(',')){
var (key, hash) = StringUtils.SplitInTwo(rule, '=') ?? throw new ArgumentException("A rule must have one '=' character: " + rule);
string[] split = rule.Split('=');
if (hash.All(chr => char.IsDigit(chr) || (chr >= 'a' && chr <= 'f'))){
TweetDeckHashes.Add(key, hash);
if (split.Length == 2){
string key = split[0];
string hash = split[1];
if (hash.All(chr => char.IsDigit(chr) || (chr >= 'a' && chr <= 'f'))){
TweetDeckHashes.Add(key, hash);
}
else{
throw new ArgumentException("Invalid hash characters: "+rule);
}
}
else{
throw new ArgumentException("Invalid hash characters: " + rule);
throw new ArgumentException("A rule must have exactly one '=' character: "+rule);
}
}
}

View File

@@ -1,6 +1,6 @@
using System;
using CefSharp;
using TweetLib.Core.Utils;
using TweetDuck.Core.Utils;
namespace TweetDuck.Core.Management{
sealed class ContextInfo{
@@ -107,7 +107,7 @@ namespace TweetDuck.Core.Management{
private string unsafeLinkUrl = string.Empty;
private string mediaUrl = string.Empty;
private ChirpInfo chirp = default;
private ChirpInfo chirp = default(ChirpInfo);
public void AddContext(IContextMenuParams parameters){
ContextMenuType flags = parameters.TypeFlags;

View File

@@ -3,10 +3,9 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using TweetDuck.Core.Other;
using TweetDuck.Data;
using TweetDuck.Plugins;
using TweetLib.Core.Data;
using TweetLib.Core.Features.Plugins;
using TweetLib.Core.Features.Plugins.Enums;
using TweetDuck.Plugins.Enums;
namespace TweetDuck.Core.Management{
sealed class ProfileManager{

View File

@@ -14,13 +14,15 @@ namespace TweetDuck.Core.Notification{
protected static UserConfig Config => Program.Config.User;
protected static int FontSizeLevel{
get => TweetDeckBridge.FontSize switch{
"largest" => 4,
"large" => 3,
"small" => 1,
"smallest" => 0,
_ => 2
};
get{
switch(TweetDeckBridge.FontSize){
case "largest": return 4;
case "large": return 3;
case "small": return 1;
case "smallest": return 0;
default: return 2;
}
}
}
protected virtual Point PrimaryLocation{

View File

@@ -6,10 +6,10 @@ using TweetDuck.Core.Bridge;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Handling;
using TweetDuck.Core.Utils;
using TweetDuck.Data;
using TweetDuck.Plugins;
using TweetDuck.Plugins.Enums;
using TweetDuck.Resources;
using TweetLib.Core.Data;
using TweetLib.Core.Features.Plugins.Enums;
namespace TweetDuck.Core.Notification{
abstract partial class FormNotificationMain : FormNotificationBase{
@@ -44,17 +44,27 @@ namespace TweetDuck.Core.Notification{
}
private int BaseClientWidth{
get => Config.NotificationSize switch{
TweetNotification.Size.Custom => Config.CustomNotificationSize.Width,
_ => BrowserUtils.Scale(284, SizeScale * (1.0 + 0.05 * FontSizeLevel))
};
get{
switch(Config.NotificationSize){
default:
return BrowserUtils.Scale(284, SizeScale*(1.0+0.05*FontSizeLevel));
case TweetNotification.Size.Custom:
return Config.CustomNotificationSize.Width;
}
}
}
private int BaseClientHeight{
get => Config.NotificationSize switch{
TweetNotification.Size.Custom => Config.CustomNotificationSize.Height,
_ => BrowserUtils.Scale(122, SizeScale * (1.0 + 0.08 * FontSizeLevel))
};
get{
switch(Config.NotificationSize){
default:
return BrowserUtils.Scale(122, SizeScale*(1.0+0.08*FontSizeLevel));
case TweetNotification.Size.Custom:
return Config.CustomNotificationSize.Height;
}
}
}
protected virtual string BodyClasses => IsCursorOverBrowser ? "td-notification td-hover" : "td-notification";
@@ -73,7 +83,7 @@ namespace TweetDuck.Core.Notification{
browser.LoadingStateChanged += Browser_LoadingStateChanged;
browser.FrameLoadEnd += Browser_FrameLoadEnd;
plugins.Register(browser, PluginEnvironment.Notification);
plugins.Register(browser, PluginEnvironment.Notification, this);
mouseHookDelegate = MouseHookProc;
Disposed += (sender, args) => StopMouseHook(true);

View File

@@ -6,9 +6,9 @@ using CefSharp;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Other;
using TweetDuck.Core.Utils;
using TweetDuck.Data;
using TweetDuck.Plugins;
using TweetDuck.Resources;
using TweetLib.Core.Data;
namespace TweetDuck.Core.Notification.Screenshot{
sealed class FormNotificationScreenshotable : FormNotificationBase{

View File

@@ -1,10 +1,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
namespace TweetDuck.Core.Notification.Screenshot{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
sealed class ScreenshotBridge{
private readonly Control owner;

View File

@@ -11,16 +11,18 @@ namespace TweetDuck.Core.Notification{
public const string SupportedFormats = "*.wav;*.ogg;*.mp3;*.flac;*.opus;*.weba;*.webm";
public static IResourceHandler CreateFileHandler(string path){
string mimeType = Path.GetExtension(path) switch{
".weba" => "audio/webm",
".webm" => "audio/webm",
".wav" => "audio/wav",
".ogg" => "audio/ogg",
".mp3" => "audio/mp3",
".flac" => "audio/flac",
".opus" => "audio/ogg; codecs=opus",
_ => null
};
string mimeType;
switch(Path.GetExtension(path)){
case ".weba":
case ".webm": mimeType = "audio/webm"; break;
case ".wav": mimeType = "audio/wav"; break;
case ".ogg": mimeType = "audio/ogg"; break;
case ".mp3": mimeType = "audio/mp3"; break;
case ".flac": mimeType = "audio/flac"; break;
case ".opus": mimeType = "audio/ogg; codecs=opus"; break;
default: mimeType = null; break;
}
try{
return ResourceHandler.FromFilePath(path, mimeType);

View File

@@ -2,8 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using TweetLib.Core.Serialization;
using TweetLib.Core.Serialization.Converters;
using TweetDuck.Data.Serialization;
namespace TweetDuck.Core.Other.Analytics{
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Local")]

View File

@@ -9,8 +9,6 @@ using System.Timers;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils;
using TweetDuck.Plugins;
using TweetLib.Core;
using TweetLib.Core.Utils;
namespace TweetDuck.Core.Other.Analytics{
sealed class AnalyticsManager : IDisposable{
@@ -22,7 +20,7 @@ namespace TweetDuck.Core.Other.Analytics{
#else
"https://tweetduck.chylex.com/breadcrumb/report"
#endif
);
);
public AnalyticsFile File { get; }
@@ -82,7 +80,7 @@ namespace TweetDuck.Core.Other.Analytics{
private void SetLastDataCollectionTime(DateTime dt, string message = null){
File.LastDataCollection = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0, dt.Kind);
File.LastCollectionVersion = Program.VersionTag;
File.LastCollectionMessage = message ?? dt.ToString("g", Lib.Culture);
File.LastCollectionMessage = message ?? dt.ToString("g", Program.Culture);
File.Save();
RestartTimer();
@@ -119,7 +117,7 @@ namespace TweetDuck.Core.Other.Analytics{
System.Diagnostics.Debugger.Break();
#endif
WebUtils.NewClient(BrowserUtils.UserAgentVanilla).UploadValues(CollectionUrl, "POST", report.ToNameValueCollection());
BrowserUtils.CreateWebClient().UploadValues(CollectionUrl, "POST", report.ToNameValueCollection());
}).ContinueWith(task => browser.InvokeAsyncSafe(() => {
if (task.Status == TaskStatus.RanToCompletion){
SetLastDataCollectionTime(DateTime.Now);

View File

@@ -11,10 +11,7 @@ using System.Text.RegularExpressions;
using TweetDuck.Core.Notification;
using TweetDuck.Core.Utils;
using TweetDuck.Plugins;
using TweetLib.Core;
using TweetLib.Core.Features.Plugins;
using TweetLib.Core.Features.Plugins.Enums;
using TweetLib.Core.Utils;
using TweetDuck.Plugins.Enums;
namespace TweetDuck.Core.Other.Analytics{
static class AnalyticsReportGenerator{
@@ -30,7 +27,7 @@ namespace TweetDuck.Core.Other.Analytics{
{ "System Edition" , SystemEdition },
{ "System Environment" , Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit" },
{ "System Build" , SystemBuild },
{ "System Locale" , Lib.Culture.Name.ToLower() },
{ "System Locale" , Program.Culture.Name.ToLower() },
0,
{ "RAM" , Exact(RamSize) },
{ "GPU" , GpuVendor },
@@ -82,7 +79,7 @@ namespace TweetDuck.Core.Other.Analytics{
{ "Custom Notification CSS" , RoundUp((UserConfig.CustomNotificationCSS ?? string.Empty).Length, 50) },
0,
{ "Plugins All" , List(plugins.Plugins.Select(Plugin)) },
{ "Plugins Enabled" , List(plugins.Plugins.Where(plugins.Config.IsEnabled).Select(Plugin)) },
{ "Plugins Enabled" , List(plugins.Plugins.Where(plugin => plugins.Config.IsEnabled(plugin)).Select(Plugin)) },
0,
{ "Theme" , Dict(editLayoutDesign, "_theme", "light/def") },
{ "Column Width" , Dict(editLayoutDesign, "columnWidth", "310px/def") },
@@ -207,30 +204,36 @@ namespace TweetDuck.Core.Other.Analytics{
}
private static string TrayMode{
get => UserConfig.TrayBehavior switch{
TrayIcon.Behavior.DisplayOnly => "icon",
TrayIcon.Behavior.MinimizeToTray => "minimize",
TrayIcon.Behavior.CloseToTray => "close",
TrayIcon.Behavior.Combined => "combined",
_ => "off"
};
get{
switch(UserConfig.TrayBehavior){
case TrayIcon.Behavior.DisplayOnly: return "icon";
case TrayIcon.Behavior.MinimizeToTray: return "minimize";
case TrayIcon.Behavior.CloseToTray: return "close";
case TrayIcon.Behavior.Combined: return "combined";
default: return "off";
}
}
}
private static string NotificationPosition{
get => UserConfig.NotificationPosition switch{
TweetNotification.Position.TopLeft => "top left",
TweetNotification.Position.TopRight => "top right",
TweetNotification.Position.BottomLeft => "bottom left",
TweetNotification.Position.BottomRight => "bottom right",
_ => "custom"
};
get{
switch(UserConfig.NotificationPosition){
case TweetNotification.Position.TopLeft: return "top left";
case TweetNotification.Position.TopRight: return "top right";
case TweetNotification.Position.BottomLeft: return "bottom left";
case TweetNotification.Position.BottomRight: return "bottom right";
default: return "custom";
}
}
}
private static string NotificationSize{
get => UserConfig.NotificationSize switch{
TweetNotification.Size.Auto => "auto",
_ => RoundUp(UserConfig.CustomNotificationSize.Width, 20) + "x" + RoundUp(UserConfig.CustomNotificationSize.Height, 20)
};
get{
switch(UserConfig.NotificationSize){
case TweetNotification.Size.Auto: return "auto";
default: return RoundUp(UserConfig.CustomNotificationSize.Width, 20)+"x"+RoundUp(UserConfig.CustomNotificationSize.Height, 20);
}
}
}
private static string NotificationTimer{

View File

@@ -1,6 +1,4 @@
using TweetDuck.Plugins;
namespace TweetDuck.Core.Other {
namespace TweetDuck.Core.Other {
partial class FormPlugins {
/// <summary>
/// Required designer variable.
@@ -29,7 +27,7 @@ namespace TweetDuck.Core.Other {
this.btnClose = new System.Windows.Forms.Button();
this.btnReload = new System.Windows.Forms.Button();
this.btnOpenFolder = new System.Windows.Forms.Button();
this.flowLayoutPlugins = new PluginListFlowLayout();
this.flowLayoutPlugins = new TweetDuck.Plugins.Controls.PluginListFlowLayout();
this.timerLayout = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
@@ -119,7 +117,7 @@ namespace TweetDuck.Core.Other {
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnReload;
private System.Windows.Forms.Button btnOpenFolder;
private PluginListFlowLayout flowLayoutPlugins;
private Plugins.Controls.PluginListFlowLayout flowLayoutPlugins;
private System.Windows.Forms.Timer timerLayout;
}
}

View File

@@ -5,7 +5,7 @@ using System.Linq;
using System.Windows.Forms;
using TweetDuck.Configuration;
using TweetDuck.Plugins;
using TweetLib.Core.Features.Plugins;
using TweetDuck.Plugins.Controls;
namespace TweetDuck.Core.Other{
sealed partial class FormPlugins : Form, FormManager.IAppDialog{

View File

@@ -10,7 +10,7 @@ using TweetDuck.Core.Other.Settings;
using TweetDuck.Core.Other.Settings.Dialogs;
using TweetDuck.Core.Utils;
using TweetDuck.Plugins;
using TweetLib.Core.Features.Updates;
using TweetDuck.Updates;
namespace TweetDuck.Core.Other{
sealed partial class FormSettings : Form, FormManager.IAppDialog{
@@ -195,7 +195,7 @@ namespace TweetDuck.Core.Other{
private sealed class SettingsTab{
public Button Button { get; }
public BaseTabSettings Control => control ??= constructor();
public BaseTabSettings Control => control ?? (control = constructor());
public bool IsInitialized => control != null;
private readonly Func<BaseTabSettings> constructor;

View File

@@ -5,6 +5,8 @@ using TweetDuck.Core.Other.Analytics;
namespace TweetDuck.Core.Other.Settings.Dialogs{
sealed partial class DialogSettingsAnalytics : Form{
public string CefArgs => textBoxReport.Text;
public DialogSettingsAnalytics(AnalyticsReport report){
InitializeComponent();

View File

@@ -2,7 +2,7 @@
using System.Windows.Forms;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils;
using TweetLib.Core.Collections;
using TweetDuck.Data;
namespace TweetDuck.Core.Other.Settings.Dialogs{
sealed partial class DialogSettingsCefArgs : Form{

View File

@@ -4,8 +4,8 @@ using System.IO;
using System.Windows.Forms;
using TweetDuck.Configuration;
using TweetDuck.Core.Management;
using TweetDuck.Core.Utils;
using TweetDuck.Plugins;
using TweetLib.Core.Utils;
namespace TweetDuck.Core.Other.Settings.Dialogs{
sealed partial class DialogSettingsManage : Form{

View File

@@ -1,7 +1,7 @@
using System;
using System.Windows.Forms;
using TweetDuck.Configuration;
using TweetLib.Core.Collections;
using TweetDuck.Data;
namespace TweetDuck.Core.Other.Settings.Dialogs{
sealed partial class DialogSettingsRestart : Form{
@@ -18,7 +18,7 @@ namespace TweetDuck.Core.Other.Settings.Dialogs{
tbDataFolder.Enabled = false;
}
else{
tbDataFolder.Text = currentArgs.GetValue(Arguments.ArgDataFolder) ?? string.Empty;
tbDataFolder.Text = currentArgs.GetValue(Arguments.ArgDataFolder, string.Empty);
tbDataFolder.TextChanged += control_Change;
}

View File

@@ -6,8 +6,7 @@ using TweetDuck.Core.Controls;
using TweetDuck.Core.Handling.General;
using TweetDuck.Core.Other.Settings.Dialogs;
using TweetDuck.Core.Utils;
using TweetLib.Core.Features.Updates;
using TweetLib.Core.Utils;
using TweetDuck.Updates;
namespace TweetDuck.Core.Other.Settings{
sealed partial class TabSettingsGeneral : BaseTabSettings{

49
Core/Other/TaskbarIcon.cs Normal file
View File

@@ -0,0 +1,49 @@
using System;
using Microsoft.WindowsAPICodePack.Taskbar;
using TweetDuck.Configuration;
using Res = TweetDuck.Properties.Resources;
namespace TweetDuck.Core.Other{
sealed class TaskbarIcon : IDisposable{
private static UserConfig Config => Program.Config.User;
public bool HasNotifications{
get{
return hasNotifications;
}
set{
if (hasNotifications != value){
hasNotifications = value;
UpdateIcon();
}
}
}
private bool hasNotifications;
public TaskbarIcon(){
Config.MuteToggled += Config_MuteToggled;
}
public void Dispose(){
Config.MuteToggled -= Config_MuteToggled;
}
private void Config_MuteToggled(object sender, EventArgs e){
UpdateIcon();
}
public void UpdateIcon(){
if (hasNotifications){
TaskbarManager.Instance.SetOverlayIcon(Res.overlay_notification, "Unread Notifications");
}
else if (Config.MuteNotifications){
TaskbarManager.Instance.SetOverlayIcon(Res.overlay_muted, "Notifications Muted");
}
else{
TaskbarManager.Instance.SetOverlayIcon(null, string.Empty);
}
}
}
}

View File

@@ -51,7 +51,7 @@ namespace TweetDuck.Core.Other{
this.contextMenu.MenuItems.Add("Mute notifications", menuItemMuteNotifications_Click);
this.contextMenu.MenuItems.Add("Close", menuItemClose_Click);
this.contextMenu.Popup += contextMenu_Popup;
this.notifyIcon.ContextMenu = contextMenu;
this.notifyIcon.Text = Program.BrandName;

View File

@@ -12,8 +12,8 @@ using TweetDuck.Core.Handling.General;
using TweetDuck.Core.Notification;
using TweetDuck.Core.Utils;
using TweetDuck.Plugins;
using TweetDuck.Plugins.Enums;
using TweetDuck.Resources;
using TweetLib.Core.Features.Plugins.Enums;
namespace TweetDuck.Core{
sealed class TweetDeckBrowser : IDisposable{
@@ -77,7 +77,7 @@ namespace TweetDuck.Core{
this.browser.SetupZoomEvents();
owner.Controls.Add(browser);
plugins.Register(browser, PluginEnvironment.Browser, true);
plugins.Register(browser, PluginEnvironment.Browser, owner, true);
Config.MuteToggled += Config_MuteToggled;
Config.SoundNotificationChanged += Config_SoundNotificationInfoChanged;

View File

@@ -3,16 +3,16 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Windows.Forms;
using CefSharp.WinForms;
using TweetDuck.Configuration;
using TweetDuck.Core.Other;
using TweetLib.Core.Utils;
namespace TweetDuck.Core.Utils{
static class BrowserUtils{
public static string UserAgentVanilla => Program.BrandName + " " + Application.ProductVersion;
public static string UserAgentChrome => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/" + Cef.ChromiumVersion + " Safari/537.36";
public static string UserAgentVanilla => Program.BrandName+" "+Application.ProductVersion;
public static string UserAgentChrome => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/"+Cef.ChromiumVersion+" Safari/537.36";
public static readonly bool HasDevTools = File.Exists(Path.Combine(Program.ProgramPath, "devtools_resources.pak"));
@@ -74,11 +74,29 @@ namespace TweetDuck.Core.Utils{
};
}
private const string TwitterTrackingUrl = "t.co";
public enum UrlCheckResult{
Invalid, Tracking, Fine
}
public static UrlCheckResult CheckUrl(string url){
if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri)){
string scheme = uri.Scheme;
if (scheme == Uri.UriSchemeHttps || scheme == Uri.UriSchemeHttp || scheme == Uri.UriSchemeFtp || scheme == Uri.UriSchemeMailto){
return uri.Host == TwitterTrackingUrl ? UrlCheckResult.Tracking : UrlCheckResult.Fine;
}
}
return UrlCheckResult.Invalid;
}
public static void OpenExternalBrowser(string url){
if (string.IsNullOrWhiteSpace(url))return;
switch(UrlUtils.Check(url)){
case UrlUtils.CheckResult.Fine:
switch(CheckUrl(url)){
case UrlCheckResult.Fine:
if (FormGuide.CheckGuideUrl(url, out string hash)){
FormGuide.Show(hash);
}
@@ -99,9 +117,9 @@ namespace TweetDuck.Core.Utils{
break;
case UrlUtils.CheckResult.Tracking:
case UrlCheckResult.Tracking:
if (Config.IgnoreTrackingUrlWarning){
goto case UrlUtils.CheckResult.Fine;
goto case UrlCheckResult.Fine;
}
using(FormMessage form = new FormMessage("Blocked URL", "TweetDuck has blocked a tracking url due to privacy concerns. Do you want to visit it anyway?\n"+url, MessageBoxIcon.Warning)){
@@ -117,13 +135,13 @@ namespace TweetDuck.Core.Utils{
}
if (result == DialogResult.Ignore || result == DialogResult.Yes){
goto case UrlUtils.CheckResult.Fine;
goto case UrlCheckResult.Fine;
}
}
break;
case UrlUtils.CheckResult.Invalid:
case UrlCheckResult.Invalid:
FormMessage.Warning("Blocked URL", "A potentially malicious URL was blocked from opening:\n"+url, FormMessage.OK);
break;
}
@@ -156,10 +174,50 @@ namespace TweetDuck.Core.Utils{
}
}
public static string GetFileNameFromUrl(string url){
string file = Path.GetFileName(new Uri(url).AbsolutePath);
return string.IsNullOrEmpty(file) ? null : file;
}
public static string GetErrorName(CefErrorCode code){
return StringUtils.ConvertPascalCaseToScreamingSnakeCase(Enum.GetName(typeof(CefErrorCode), code) ?? string.Empty);
}
public static WebClient CreateWebClient(){
WindowsUtils.EnsureTLS12();
WebClient client = new WebClient{ Proxy = null };
client.Headers[HttpRequestHeader.UserAgent] = UserAgentVanilla;
return client;
}
public static WebClient DownloadFileAsync(string url, string target, string cookie, Action onSuccess, Action<Exception> onFailure){
WebClient client = CreateWebClient();
if (cookie != null){
client.Headers[HttpRequestHeader.Cookie] = cookie;
}
client.DownloadFileCompleted += (sender, args) => {
if (args.Cancelled){
try{
File.Delete(target);
}catch{
// didn't want it deleted anyways
}
}
else if (args.Error != null){
onFailure?.Invoke(args.Error);
}
else{
onSuccess?.Invoke();
}
};
client.DownloadFileAsync(new Uri(url), target);
return client;
}
public static int Scale(int baseValue, double scaleFactor){
return (int)Math.Round(baseValue*scaleFactor);
}

View File

@@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace TweetLib.Core.Utils{
public static class LocaleUtils{
namespace TweetDuck.Core.Utils{
static class LocaleUtils{
// https://cs.chromium.org/chromium/src/third_party/hunspell_dictionaries/
public static IEnumerable<Item> SpellCheckLanguages { get; } = new List<string>{
"af-ZA", "bg-BG", "ca-ES", "cs-CZ", "da-DK", "de-DE",
@@ -33,9 +33,9 @@ namespace TweetLib.Core.Utils{
private string Name => info?.NativeName ?? Code;
private readonly CultureInfo? info;
private readonly CultureInfo info;
public Item(string code, string? alt = null){
public Item(string code, string alt = null){
this.Code = code;
try{

View File

@@ -2,20 +2,10 @@
using System.Linq;
using System.Text.RegularExpressions;
namespace TweetLib.Core.Utils{
public static class StringUtils{
namespace TweetDuck.Core.Utils{
static class StringUtils{
public static readonly string[] EmptyArray = new string[0];
public static (string before, string after)? SplitInTwo(string str, char search, int startIndex = 0){
int index = str.IndexOf(search, startIndex);
if (index == -1){
return null;
}
return (str.Substring(0, index), str.Substring(index + 1));
}
public static string ExtractBefore(string str, char search, int startIndex = 0){
int index = str.IndexOf(search, startIndex);
return index == -1 ? str : str.Substring(0, index);
@@ -33,7 +23,7 @@ namespace TweetLib.Core.Utils{
return Regex.Replace(str, @"[a-zA-Z]", match => {
int code = match.Value[0];
int start = code <= 90 ? 65 : 97;
return ((char)(start + (code - start + 13) % 26)).ToString();
return ((char)(start+(code-start+13)%26)).ToString();
});
}

View File

@@ -8,10 +8,7 @@ using TweetDuck.Core.Management;
using TweetDuck.Core.Other;
using TweetDuck.Data;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using TweetLib.Core.Features.Twitter;
using TweetLib.Core.Utils;
using Cookie = CefSharp.Cookie;
namespace TweetDuck.Core.Utils{
@@ -30,6 +27,14 @@ namespace TweetDuck.Core.Utils{
"tweetdeck", "TweetDeck", "tweetduck", "TweetDuck", "TD"
};
public static readonly string[] ValidImageExtensions = {
".jpg", ".jpeg", ".png", ".gif"
};
public enum ImageQuality{
Default, Orig
}
public static bool IsTweetDeckWebsite(IFrame frame){
return frame.Url.Contains("//tweetdeck.twitter.com/");
}
@@ -42,19 +47,38 @@ namespace TweetDuck.Core.Utils{
return frame.Url.Contains("//twitter.com/account/login_verification");
}
private static string ExtractMediaBaseLink(string url){
int slash = url.LastIndexOf('/');
return slash == -1 ? url : StringUtils.ExtractBefore(url, ':', slash);
}
public static string GetMediaLink(string url, ImageQuality quality){
return ImageUrl.TryParse(url, out var obj) ? obj.WithQuality(quality) : url;
if (quality == ImageQuality.Orig){
string result = ExtractMediaBaseLink(url);
if (url.Contains("//ton.twitter.com/") && url.Contains("/ton/data/dm/")){
result += ":large";
}
else if (result != url || url.Contains("//pbs.twimg.com/media/")){
result += ":orig";
}
return result;
}
else{
return url;
}
}
public static string GetImageFileName(string url){
return UrlUtils.GetFileNameFromUrl(ImageUrl.TryParse(url, out var obj) ? obj.WithNoQuality : url);
return BrowserUtils.GetFileNameFromUrl(ExtractMediaBaseLink(url));
}
public static void ViewImage(string url, ImageQuality quality){
void ViewImageInternal(string path){
string ext = Path.GetExtension(path);
if (ImageUrl.ValidExtensions.Contains(ext)){
if (ValidImageExtensions.Contains(ext)){
WindowsUtils.OpenAssociatedProgram(path);
}
else{
@@ -64,7 +88,7 @@ namespace TweetDuck.Core.Utils{
string file = Path.Combine(BrowserCache.CacheFolder, GetImageFileName(url) ?? Path.GetRandomFileName());
if (FileUtils.FileExistsAndNotEmpty(file)){
if (WindowsUtils.FileExistsAndNotEmpty(file)){
ViewImageInternal(file);
}
else{
@@ -119,7 +143,7 @@ namespace TweetDuck.Core.Utils{
}
public static void DownloadVideo(string url, string username){
string filename = UrlUtils.GetFileNameFromUrl(url);
string filename = BrowserUtils.GetFileNameFromUrl(url);
string ext = Path.GetExtension(filename);
using(SaveFileDialog dialog = new SaveFileDialog{
@@ -154,10 +178,7 @@ namespace TweetDuck.Core.Utils{
}
}
WebClient client = WebUtils.NewClient(BrowserUtils.UserAgentChrome);
client.Headers[HttpRequestHeader.Cookie] = cookieStr;
client.DownloadFileCompleted += WebUtils.FileDownloadCallback(target, onSuccess, onFailure);
client.DownloadFileAsync(new Uri(url), target);
BrowserUtils.DownloadFileAsync(url, target, cookieStr, onSuccess, onFailure);
}, scheduler);
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
@@ -15,6 +16,7 @@ namespace TweetDuck.Core.Utils{
private static readonly Lazy<Regex> RegexOffsetClipboardHtml = new Lazy<Regex>(() => new Regex(@"(?<=EndHTML:|EndFragment:)(\d+)"), false);
private static readonly bool IsWindows8OrNewer;
private static bool HasMicrosoftBeenBroughtTo2008Yet;
public static int CurrentProcessID { get; }
public static bool ShouldAvoidToolWindow { get; }
@@ -30,6 +32,47 @@ namespace TweetDuck.Core.Utils{
ShouldAvoidToolWindow = IsWindows8OrNewer;
}
public static void EnsureTLS12(){
if (!HasMicrosoftBeenBroughtTo2008Yet){
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol &= ~(SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11);
HasMicrosoftBeenBroughtTo2008Yet = true;
}
}
public static void CreateDirectoryForFile(string file){
string dir = Path.GetDirectoryName(file);
if (dir == null){
throw new ArgumentException("Invalid file path: "+file);
}
else if (dir.Length > 0){
Directory.CreateDirectory(dir);
}
}
public static bool CheckFolderWritePermission(string path){
string testFile = Path.Combine(path, ".test");
try{
Directory.CreateDirectory(path);
using(File.Create(testFile)){}
File.Delete(testFile);
return true;
}catch{
return false;
}
}
public static bool FileExistsAndNotEmpty(string path){
try{
return new FileInfo(path).Length > 0;
}catch{
return false;
}
}
public static bool OpenAssociatedProgram(string file, string arguments = "", bool runElevated = false){
try{

View File

@@ -1,11 +1,11 @@
using System;
using System.IO;
using System.Text;
using TweetLib.Core.Utils;
using TweetDuck.Core.Utils;
namespace TweetLib.Core.Data{
public sealed class CombinedFileStream : IDisposable{
private const char KeySeparator = '|';
namespace TweetDuck.Data{
sealed class CombinedFileStream : IDisposable{
public const char KeySeparator = '|';
private readonly Stream stream;
@@ -45,7 +45,7 @@ namespace TweetLib.Core.Data{
stream.Write(contents, 0, contents.Length);
}
public Entry? ReadFile(){
public Entry ReadFile(){
int nameLength = stream.ReadByte();
if (nameLength == -1){
@@ -64,7 +64,7 @@ namespace TweetLib.Core.Data{
return new Entry(Encoding.UTF8.GetString(name), contents);
}
public string? SkipFile(){
public string SkipFile(){
int nameLength = stream.ReadByte();
if (nameLength == -1){
@@ -120,7 +120,7 @@ namespace TweetLib.Core.Data{
public void WriteToFile(string path, bool createDirectory){
if (createDirectory){
FileUtils.CreateDirectoryForFile(path);
WindowsUtils.CreateDirectoryForFile(path);
}
File.WriteAllBytes(path, contents);

View File

@@ -2,8 +2,8 @@
using System.Text;
using System.Text.RegularExpressions;
namespace TweetLib.Core.Collections{
public sealed class CommandLineArgs{
namespace TweetDuck.Data{
sealed class CommandLineArgs{
public static CommandLineArgs FromStringArray(char entryChar, string[] array){
CommandLineArgs args = new CommandLineArgs();
ReadStringArray(entryChar, array, args);
@@ -15,7 +15,7 @@ namespace TweetLib.Core.Collections{
string entry = array[index];
if (entry.Length > 0 && entry[0] == entryChar){
if (index < array.Length - 1){
if (index < array.Length-1){
string potentialValue = array[index+1];
if (potentialValue.Length > 0 && potentialValue[0] == entryChar){
@@ -52,7 +52,7 @@ namespace TweetLib.Core.Collections{
}
else{
key = matchValue.Substring(0, indexEquals).TrimStart('-');
value = matchValue.Substring(indexEquals + 1).Trim('"');
value = matchValue.Substring(indexEquals+1).Trim('"');
}
if (key.Length != 0){
@@ -66,7 +66,7 @@ namespace TweetLib.Core.Collections{
private readonly HashSet<string> flags = new HashSet<string>();
private readonly Dictionary<string, string> values = new Dictionary<string, string>();
public int Count => flags.Count + values.Count;
public int Count => flags.Count+values.Count;
public void AddFlag(string flag){
flags.Add(flag.ToLower());
@@ -84,8 +84,12 @@ namespace TweetLib.Core.Collections{
values[key.ToLower()] = value;
}
public string? GetValue(string key){
return values.TryGetValue(key.ToLower(), out string val) ? val : null;
public bool HasValue(string key){
return values.ContainsKey(key.ToLower());
}
public string GetValue(string key, string defaultValue){
return values.TryGetValue(key.ToLower(), out string val) ? val : defaultValue;
}
public void RemoveValue(string key){
@@ -99,7 +103,7 @@ namespace TweetLib.Core.Collections{
copy.AddFlag(flag);
}
foreach(var kvp in values){
foreach(KeyValuePair<string, string> kvp in values){
copy.SetValue(kvp.Key, kvp.Value);
}
@@ -111,7 +115,7 @@ namespace TweetLib.Core.Collections{
target[flag] = "1";
}
foreach(var kvp in values){
foreach(KeyValuePair<string, string> kvp in values){
target[kvp.Key] = kvp.Value;
}
}
@@ -123,11 +127,11 @@ namespace TweetLib.Core.Collections{
build.Append(flag).Append(' ');
}
foreach(var kvp in values){
foreach(KeyValuePair<string, string> kvp in values){
build.Append(kvp.Key).Append(" \"").Append(kvp.Value).Append("\" ");
}
return build.Length == 0 ? string.Empty : build.Remove(build.Length - 1, 1).ToString();
return build.Length == 0 ? string.Empty : build.Remove(build.Length-1, 1).ToString();
}
}
}

View File

@@ -1,7 +1,7 @@
using System;
namespace TweetLib.Core.Data{
public sealed class InjectedHTML{
namespace TweetDuck.Data{
sealed class InjectedHTML{
public enum Position{
Before, After
}
@@ -27,7 +27,7 @@ namespace TweetLib.Core.Data{
switch(position){
case Position.Before: cutIndex = index; break;
case Position.After: cutIndex = index + search.Length; break;
case Position.After: cutIndex = index+search.Length; break;
default: return targetHTML;
}

View File

@@ -1,14 +1,14 @@
using System;
namespace TweetLib.Core.Data{
public sealed class Result<T>{
namespace TweetDuck.Data{
sealed class Result<T>{
public bool HasValue => exception == null;
public T Value => HasValue ? value : throw new InvalidOperationException("Requested value from a failed result.");
public Exception Exception => exception ?? throw new InvalidOperationException("Requested exception from a successful result.");
private readonly T value;
private readonly Exception? exception;
private readonly Exception exception;
public Result(T value){
this.value = value;
@@ -16,7 +16,7 @@ namespace TweetLib.Core.Data{
}
public Result(Exception exception){
this.value = default!;
this.value = default(T);
this.exception = exception ?? throw new ArgumentNullException(nameof(exception));
}
@@ -25,12 +25,12 @@ namespace TweetLib.Core.Data{
onSuccess(value);
}
else{
onException(exception!);
onException(exception);
}
}
public Result<R> Select<R>(Func<T, R> map){
return HasValue ? new Result<R>(map(value)) : new Result<R>(exception!);
return HasValue ? new Result<R>(map(value)) : new Result<R>(exception);
}
}
}

View File

@@ -4,11 +4,10 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using TweetLib.Core.Serialization.Converters;
using TweetLib.Core.Utils;
using TweetDuck.Core.Utils;
namespace TweetLib.Core.Serialization{
public sealed class FileSerializer<T>{
namespace TweetDuck.Data.Serialization{
sealed class FileSerializer<T>{
private const string NewLineReal = "\r\n";
private const string NewLineCustom = "\r~\n";
@@ -50,6 +49,8 @@ namespace TweetLib.Core.Serialization{
return build.Append(data.Substring(index)).ToString();
}
private static readonly ITypeConverter BasicSerializerObj = new BasicTypeConverter();
private readonly Dictionary<string, PropertyInfo> props;
private readonly Dictionary<Type, ITypeConverter> converters;
@@ -65,7 +66,7 @@ namespace TweetLib.Core.Serialization{
public void Write(string file, T obj){
LinkedList<string> errors = new LinkedList<string>();
FileUtils.CreateDirectoryForFile(file);
WindowsUtils.CreateDirectoryForFile(file);
using(StreamWriter writer = new StreamWriter(new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None))){
foreach(KeyValuePair<string, PropertyInfo> prop in props){
@@ -73,10 +74,10 @@ namespace TweetLib.Core.Serialization{
object value = prop.Value.GetValue(obj);
if (!converters.TryGetValue(type, out ITypeConverter serializer)){
serializer = ClrTypeConverter.Instance;
serializer = BasicSerializerObj;
}
if (serializer.TryWriteType(type, value, out string? converted)){
if (serializer.TryWriteType(type, value, out string converted)){
if (converted != null){
writer.Write(prop.Key);
writer.Write(' ');
@@ -141,10 +142,10 @@ namespace TweetLib.Core.Serialization{
if (props.TryGetValue(property, out PropertyInfo info)){
if (!converters.TryGetValue(info.PropertyType, out ITypeConverter serializer)){
serializer = ClrTypeConverter.Instance;
serializer = BasicSerializerObj;
}
if (serializer.TryReadType(info.PropertyType, value, out object? converted)){
if (serializer.TryReadType(info.PropertyType, value, out object converted)){
info.SetValue(obj, converted);
}
else{
@@ -164,5 +165,53 @@ namespace TweetLib.Core.Serialization{
}catch(FileNotFoundException){
}catch(DirectoryNotFoundException){}
}
private sealed class BasicTypeConverter : ITypeConverter{
bool ITypeConverter.TryWriteType(Type type, object value, out string converted){
switch(Type.GetTypeCode(type)){
case TypeCode.Boolean:
converted = value.ToString();
return true;
case TypeCode.Int32:
converted = ((int)value).ToString(); // cast required for enums
return true;
case TypeCode.String:
converted = value?.ToString();
return true;
default:
converted = null;
return false;
}
}
bool ITypeConverter.TryReadType(Type type, string value, out object converted){
switch(Type.GetTypeCode(type)){
case TypeCode.Boolean:
if (bool.TryParse(value, out bool b)){
converted = b;
return true;
}
else goto default;
case TypeCode.Int32:
if (int.TryParse(value, out int i)){
converted = i;
return true;
}
else goto default;
case TypeCode.String:
converted = value;
return true;
default:
converted = null;
return false;
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
using System;
namespace TweetDuck.Data.Serialization{
interface ITypeConverter{
bool TryWriteType(Type type, object value, out string converted);
bool TryReadType(Type type, string value, out object converted);
}
}

View File

@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
namespace TweetLib.Core.Serialization{
public sealed class SerializationSoftException : Exception{
namespace TweetDuck.Data.Serialization{
sealed class SerializationSoftException : Exception{
public IList<string> Errors { get; }
public SerializationSoftException(IList<string> errors) : base(string.Join(Environment.NewLine, errors)){

View File

@@ -1,11 +1,11 @@
using System;
namespace TweetLib.Core.Serialization.Converters{
public sealed class SingleTypeConverter<T> : ITypeConverter{
namespace TweetDuck.Data.Serialization{
sealed class SingleTypeConverter<T> : ITypeConverter{
public Func<T, string> ConvertToString { get; set; }
public Func<string, T> ConvertToObject { get; set; }
bool ITypeConverter.TryWriteType(Type type, object value, out string? converted){
bool ITypeConverter.TryWriteType(Type type, object value, out string converted){
try{
converted = ConvertToString((T)value);
return true;
@@ -15,7 +15,7 @@ namespace TweetLib.Core.Serialization.Converters{
}
}
bool ITypeConverter.TryReadType(Type type, string value, out object? converted){
bool ITypeConverter.TryReadType(Type type, string value, out object converted){
try{
converted = ConvertToObject(value);
return true;

View File

@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
namespace TweetLib.Core.Collections{
public sealed class TwoKeyDictionary<K1, K2, V>{
namespace TweetDuck.Data{
sealed class TwoKeyDictionary<K1, K2, V>{
private readonly Dictionary<K1, Dictionary<K2, V>> dict;
private readonly int innerCapacity;
@@ -85,8 +85,7 @@ namespace TweetLib.Core.Collections{
return true;
}
return false;
else return false;
}
public bool TryGetValue(K1 outerKey, K2 innerKey, out V value){
@@ -94,7 +93,7 @@ namespace TweetLib.Core.Collections{
return innerDict.TryGetValue(innerKey, out value);
}
else{
value = default!;
value = default(V);
return false;
}
}

View File

@@ -1,8 +1,8 @@
using System.Drawing;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
using TweetLib.Core.Serialization.Converters;
using TweetLib.Core.Utils;
using TweetDuck.Core.Utils;
using TweetDuck.Data.Serialization;
namespace TweetDuck.Data{
sealed class WindowState{

View File

@@ -1,4 +1,4 @@
namespace TweetDuck.Plugins {
namespace TweetDuck.Plugins.Controls {
partial class PluginControl {
/// <summary>
/// Required designer variable.

View File

@@ -3,10 +3,9 @@ using System.Drawing;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils;
using TweetLib.Core.Features.Plugins;
using TweetLib.Core.Features.Plugins.Enums;
using TweetDuck.Plugins.Enums;
namespace TweetDuck.Plugins{
namespace TweetDuck.Plugins.Controls{
sealed partial class PluginControl : UserControl{
private readonly PluginManager pluginManager;
private readonly Plugin plugin;
@@ -56,19 +55,19 @@ namespace TweetDuck.Plugins{
private void panelDescription_Resize(object sender, EventArgs e){
SuspendLayout();
int maxWidth = panelDescription.Width - (panelDescription.VerticalScroll.Visible ? SystemInformation.VerticalScrollBarWidth : 0);
int maxWidth = panelDescription.Width-(panelDescription.VerticalScroll.Visible ? SystemInformation.VerticalScrollBarWidth : 0);
labelDescription.MaximumSize = new Size(maxWidth, int.MaxValue);
Font font = labelDescription.Font;
int descriptionLines = TextRenderer.MeasureText(labelDescription.Text, font, new Size(maxWidth, int.MaxValue), TextFormatFlags.WordBreak).Height / (font.Height - 1);
int descriptionLines = TextRenderer.MeasureText(labelDescription.Text, font, new Size(maxWidth, int.MaxValue), TextFormatFlags.WordBreak).Height/(font.Height-1);
int requiredLines = Math.Max(descriptionLines, 1 + (string.IsNullOrEmpty(labelVersion.Text) ? 0 : 1) + (isConfigurable ? 1 : 0));
int requiredLines = Math.Max(descriptionLines, 1+(string.IsNullOrEmpty(labelVersion.Text) ? 0 : 1)+(isConfigurable ? 1 : 0));
nextHeight = requiredLines switch{
1 => MaximumSize.Height - 2 * (font.Height - 1),
2 => MaximumSize.Height - 1 * (font.Height - 1),
_ => MaximumSize.Height
};
switch(requiredLines){
case 1: nextHeight = MaximumSize.Height-2*(font.Height-1); break;
case 2: nextHeight = MaximumSize.Height-(font.Height-1); break;
default: nextHeight = MaximumSize.Height; break;
}
if (nextHeight != Height){
timerLayout.Start();

View File

@@ -1,7 +1,7 @@
using System.Windows.Forms;
using TweetDuck.Core.Utils;
namespace TweetDuck.Plugins{
namespace TweetDuck.Plugins.Controls{
sealed class PluginListFlowLayout : FlowLayoutPanel{
public PluginListFlowLayout(){
FlowDirection = FlowDirection.TopDown;

View File

@@ -0,0 +1,88 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
namespace TweetDuck.Plugins.Enums{
[Flags]
enum PluginEnvironment{
None = 0,
Browser = 1,
Notification = 2
}
static class PluginEnvironmentExtensions{
public static IEnumerable<PluginEnvironment> Values{
get{
yield return PluginEnvironment.Browser;
yield return PluginEnvironment.Notification;
}
}
public static bool IncludesDisabledPlugins(this PluginEnvironment environment){
return environment == PluginEnvironment.Browser;
}
public static string GetPluginScriptFile(this PluginEnvironment environment){
switch(environment){
case PluginEnvironment.Browser: return "browser.js";
case PluginEnvironment.Notification: return "notification.js";
default: return null;
}
}
public static string GetPluginScriptVariables(this PluginEnvironment environment){
switch(environment){
case PluginEnvironment.Browser: return "$,$TD,$TDP,TD";
case PluginEnvironment.Notification: return "$TD,$TDP";
default: return string.Empty;
}
}
public static IReadOnlyDictionary<PluginEnvironment, T> Map<T>(T forNone, T forBrowser, T forNotification){
return new PluginEnvironmentDictionary<T>(forNone, forBrowser, forNotification);
}
[SuppressMessage("ReSharper", "MemberHidesStaticFromOuterClass")]
private sealed class PluginEnvironmentDictionary<T> : IReadOnlyDictionary<PluginEnvironment, T>{
private const int TotalKeys = 3;
public IEnumerable<PluginEnvironment> Keys => Enum.GetValues(typeof(PluginEnvironment)).Cast<PluginEnvironment>();
public IEnumerable<T> Values => data;
public int Count => TotalKeys;
public T this[PluginEnvironment key] => data[(int)key];
private readonly T[] data;
public PluginEnvironmentDictionary(T forNone, T forBrowser, T forNotification){
this.data = new T[TotalKeys];
this.data[(int)PluginEnvironment.None] = forNone;
this.data[(int)PluginEnvironment.Browser] = forBrowser;
this.data[(int)PluginEnvironment.Notification] = forNotification;
}
public bool ContainsKey(PluginEnvironment key){
return key >= 0 && (int)key < TotalKeys;
}
public bool TryGetValue(PluginEnvironment key, out T value){
if (ContainsKey(key)){
value = this[key];
return true;
}
else{
value = default(T);
return false;
}
}
public IEnumerator<KeyValuePair<PluginEnvironment, T>> GetEnumerator(){
return Keys.Select(key => new KeyValuePair<PluginEnvironment, T>(key, this[key])).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
}

View File

@@ -0,0 +1,5 @@
namespace TweetDuck.Plugins.Enums{
enum PluginFolder{
Root, Data
}
}

View File

@@ -0,0 +1,23 @@
namespace TweetDuck.Plugins.Enums{
enum PluginGroup{
Official, Custom
}
static class PluginGroupExtensions{
public static string GetIdentifierPrefix(this PluginGroup group){
switch(group){
case PluginGroup.Official: return "official/";
case PluginGroup.Custom: return "custom/";
default: return "unknown/";
}
}
public static string GetIdentifierPrefixShort(this PluginGroup group){
switch(group){
case PluginGroup.Official: return "o/";
case PluginGroup.Custom: return "c/";
default: return "?/";
}
}
}
}

View File

@@ -1,7 +1,7 @@
using System;
namespace TweetLib.Core.Features.Plugins.Events{
public sealed class PluginChangedStateEventArgs : EventArgs{
namespace TweetDuck.Plugins.Events{
sealed class PluginChangedStateEventArgs : EventArgs{
public Plugin Plugin { get; }
public bool IsEnabled { get; }

View File

@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
namespace TweetLib.Core.Features.Plugins.Events{
public sealed class PluginErrorEventArgs : EventArgs{
namespace TweetDuck.Plugins.Events{
sealed class PluginErrorEventArgs : EventArgs{
public bool HasErrors => Errors.Count > 0;
public IList<string> Errors { get; }

View File

@@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using TweetLib.Core.Features.Plugins.Events;
namespace TweetLib.Core.Features.Plugins.Config{
public interface IPluginConfig{
event EventHandler<PluginChangedStateEventArgs> PluginChangedState;
using TweetDuck.Plugins.Events;
namespace TweetDuck.Plugins{
interface IPluginConfig{
IEnumerable<string> DisabledPlugins { get; }
void Reset(IEnumerable<string> newDisabledPlugins);
event EventHandler<PluginChangedStateEventArgs> PluginChangedState;
void SetEnabled(Plugin plugin, bool enabled);
bool IsEnabled(Plugin plugin);

View File

@@ -1,10 +1,10 @@
using System;
using System.IO;
using TweetLib.Core.Features.Plugins.Enums;
using TweetDuck.Plugins.Enums;
namespace TweetLib.Core.Features.Plugins{
public sealed class Plugin{
private static readonly Version AppVersion = new Version(Lib.VersionTag);
namespace TweetDuck.Plugins{
sealed class Plugin{
private static readonly Version AppVersion = new Version(Program.VersionTag);
public string Identifier { get; }
public PluginGroup Group { get; }
@@ -62,7 +62,7 @@ namespace TweetLib.Core.Features.Plugins{
public string GetScriptPath(PluginEnvironment environment){
if (Environments.HasFlag(environment)){
string? file = environment.GetPluginScriptFile();
string file = environment.GetPluginScriptFile();
return file != null ? Path.Combine(pathRoot, file) : string.Empty;
}
else{
@@ -71,11 +71,11 @@ namespace TweetLib.Core.Features.Plugins{
}
public string GetPluginFolder(PluginFolder folder){
return folder switch{
PluginFolder.Root => pathRoot,
PluginFolder.Data => pathData,
_ => string.Empty
};
switch(folder){
case PluginFolder.Root: return pathRoot;
case PluginFolder.Data: return pathData;
default: return string.Empty;
}
}
public string GetFullPathIfSafe(PluginFolder folder, string relativePath){
@@ -124,7 +124,7 @@ namespace TweetLib.Core.Features.Plugins{
public sealed class Builder{
private static readonly Version DefaultRequiredVersion = new Version(0, 0, 0, 0);
public string Name { get; set; } = string.Empty;
public string Name { get; set; }
public string Description { get; set; } = string.Empty;
public string Author { get; set; } = "(anonymous)";
public string Version { get; set; } = string.Empty;
@@ -144,7 +144,7 @@ namespace TweetLib.Core.Features.Plugins{
this.group = group;
this.pathRoot = pathRoot;
this.pathData = pathData;
this.identifier = group.GetIdentifierPrefix() + name;
this.identifier = group.GetIdentifierPrefix()+name;
}
public void AddEnvironment(PluginEnvironment environment){

View File

@@ -1,25 +1,26 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using TweetLib.Core.Collections;
using TweetLib.Core.Data;
using TweetLib.Core.Features.Plugins.Enums;
using TweetLib.Core.Features.Plugins.Events;
using TweetLib.Core.Utils;
using TweetDuck.Core.Utils;
using TweetDuck.Data;
using TweetDuck.Plugins.Enums;
using TweetDuck.Plugins.Events;
namespace TweetLib.Core.Features.Plugins{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public sealed class PluginBridge{
private readonly IPluginManager manager;
private readonly FileCache fileCache = new FileCache();
namespace TweetDuck.Plugins{
sealed class PluginBridge{
private static string SanitizeCacheKey(string key){
return key.Replace('\\', '/').Trim();
}
private readonly PluginManager manager;
private readonly TwoKeyDictionary<int, string, string> fileCache = new TwoKeyDictionary<int, string, string>(4, 2);
private readonly TwoKeyDictionary<int, string, InjectedHTML> notificationInjections = new TwoKeyDictionary<int, string, InjectedHTML>(4, 1);
public IEnumerable<InjectedHTML> NotificationInjections => notificationInjections.InnerValues;
public ISet<Plugin> WithConfigureFunction { get; } = new HashSet<Plugin>();
public HashSet<Plugin> WithConfigureFunction { get; } = new HashSet<Plugin>();
public PluginBridge(IPluginManager manager){
public PluginBridge(PluginManager manager){
this.manager = manager;
this.manager.Reloaded += manager_Reloaded;
this.manager.Config.PluginChangedState += Config_PluginChangedState;
@@ -50,7 +51,7 @@ namespace TweetLib.Core.Features.Plugins{
switch(folder){
case PluginFolder.Data: throw new ArgumentException("File path has to be relative to the plugin data folder.");
case PluginFolder.Root: throw new ArgumentException("File path has to be relative to the plugin root folder.");
default: throw new ArgumentException($"Invalid folder type {folder}, this is a TweetDuck error.");
default: throw new ArgumentException("Invalid folder type "+folder+", this is a TweetDuck error.");
}
}
else{
@@ -58,15 +59,15 @@ namespace TweetLib.Core.Features.Plugins{
}
}
private string ReadFileUnsafe(int token, PluginFolder folder, string path, bool readCached){
string fullPath = GetFullPathOrThrow(token, folder, path);
if (readCached && fileCache.TryGetValue(token, folder, path, out string cachedContents)){
private string ReadFileUnsafe(int token, string cacheKey, string fullPath, bool readCached){
cacheKey = SanitizeCacheKey(cacheKey);
if (readCached && fileCache.TryGetValue(token, cacheKey, out string cachedContents)){
return cachedContents;
}
try{
return fileCache[token, folder, path] = File.ReadAllText(fullPath, Encoding.UTF8);
return fileCache[token, cacheKey] = File.ReadAllText(fullPath, Encoding.UTF8);
}catch(FileNotFoundException){
throw new FileNotFoundException("File not found.");
}catch(DirectoryNotFoundException){
@@ -79,19 +80,19 @@ namespace TweetLib.Core.Features.Plugins{
public void WriteFile(int token, string path, string contents){
string fullPath = GetFullPathOrThrow(token, PluginFolder.Data, path);
FileUtils.CreateDirectoryForFile(fullPath);
WindowsUtils.CreateDirectoryForFile(fullPath);
File.WriteAllText(fullPath, contents, Encoding.UTF8);
fileCache[token, PluginFolder.Data, path] = contents;
fileCache[token, SanitizeCacheKey(path)] = contents;
}
public string ReadFile(int token, string path, bool cache){
return ReadFileUnsafe(token, PluginFolder.Data, path, cache);
return ReadFileUnsafe(token, path, GetFullPathOrThrow(token, PluginFolder.Data, path), cache);
}
public void DeleteFile(int token, string path){
string fullPath = GetFullPathOrThrow(token, PluginFolder.Data, path);
fileCache.Remove(token, PluginFolder.Data, path);
fileCache.Remove(token, SanitizeCacheKey(path));
File.Delete(fullPath);
}
@@ -100,7 +101,7 @@ namespace TweetLib.Core.Features.Plugins{
}
public string ReadFileRoot(int token, string path){
return ReadFileUnsafe(token, PluginFolder.Root, path, true);
return ReadFileUnsafe(token, "root*"+path, GetFullPathOrThrow(token, PluginFolder.Root, path), true);
}
public bool CheckFileExistsRoot(int token, string path){
@@ -122,39 +123,5 @@ namespace TweetLib.Core.Features.Plugins{
WithConfigureFunction.Add(plugin);
}
}
private sealed class FileCache{
private readonly TwoKeyDictionary<int, string, string> cache = new TwoKeyDictionary<int, string, string>(4, 2);
public string this[int token, PluginFolder folder, string path]{
set => cache[token, Key(folder, path)] = value;
}
public void Clear(){
cache.Clear();
}
public bool TryGetValue(int token, PluginFolder folder, string path, out string contents){
return cache.TryGetValue(token, Key(folder, path), out contents);
}
public void Remove(int token){
cache.Remove(token);
}
public void Remove(int token, PluginFolder folder, string path){
cache.Remove(token, Key(folder, path));
}
private static string Key(PluginFolder folder, string path){
string prefix = folder switch{
PluginFolder.Root => "root/",
PluginFolder.Data => "data/",
_ => throw new InvalidOperationException($"Invalid folder type {folder}, this is a TweetDuck error.")
};
return prefix + path.Replace('\\', '/').Trim();
}
}
}
}

70
Plugins/PluginLoader.cs Normal file
View File

@@ -0,0 +1,70 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using TweetDuck.Plugins.Enums;
namespace TweetDuck.Plugins{
static class PluginLoader{
private static readonly string[] EndTag = { "[END]" };
public static Plugin FromFolder(string path, PluginGroup group){
string name = Path.GetFileName(path);
if (string.IsNullOrEmpty(name)){
throw new ArgumentException("Could not extract directory name from path: "+path);
}
Plugin.Builder builder = new Plugin.Builder(group, name, path, Path.Combine(Program.PluginDataPath, group.GetIdentifierPrefix(), name));
foreach(string file in Directory.EnumerateFiles(path, "*.js", SearchOption.TopDirectoryOnly).Select(Path.GetFileName)){
builder.AddEnvironment(PluginEnvironmentExtensions.Values.FirstOrDefault(env => file.Equals(env.GetPluginScriptFile(), StringComparison.Ordinal)));
}
string metaFile = Path.Combine(path, ".meta");
if (!File.Exists(metaFile)){
throw new ArgumentException("Plugin is missing a .meta file");
}
string currentTag = null, currentContents = string.Empty;
foreach(string line in File.ReadAllLines(metaFile, Encoding.UTF8).Concat(EndTag).Select(line => line.TrimEnd()).Where(line => line.Length > 0)){
if (line[0] == '[' && line[line.Length-1] == ']'){
if (currentTag != null){
SetProperty(builder, currentTag, currentContents);
}
currentTag = line.Substring(1, line.Length-2).ToUpper();
currentContents = string.Empty;
if (line.Equals(EndTag[0])){
break;
}
}
else if (currentTag != null){
currentContents = currentContents.Length == 0 ? line : currentContents+Environment.NewLine+line;
}
else{
throw new FormatException("Missing metadata tag before value: "+line);
}
}
return builder.BuildAndSetup();
}
private static void SetProperty(Plugin.Builder builder, string tag, string value){
switch(tag){
case "NAME": builder.Name = value; break;
case "DESCRIPTION": builder.Description = value; break;
case "AUTHOR": builder.Author = value; break;
case "VERSION": builder.Version = value; break;
case "WEBSITE": builder.Website = value; break;
case "CONFIGFILE": builder.ConfigFile = value; break;
case "CONFIGDEFAULT": builder.ConfigDefault = value; break;
case "REQUIRES": builder.RequiredVersion = Version.TryParse(value, out Version version) ? version : throw new FormatException("Invalid required minimum version: "+value); break;
default: throw new FormatException("Invalid metadata tag: "+tag);
}
}
}
}

View File

@@ -5,33 +5,28 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils;
using TweetDuck.Data;
using TweetDuck.Plugins.Enums;
using TweetDuck.Plugins.Events;
using TweetDuck.Resources;
using TweetLib.Core.Data;
using TweetLib.Core.Features.Plugins;
using TweetLib.Core.Features.Plugins.Config;
using TweetLib.Core.Features.Plugins.Enums;
using TweetLib.Core.Features.Plugins.Events;
namespace TweetDuck.Plugins{
sealed class PluginManager : IPluginManager{
private const string SetupScriptPrefix = "plugins.";
sealed class PluginManager{
private static readonly IReadOnlyDictionary<PluginEnvironment, string> PluginSetupScriptNames = PluginEnvironmentExtensions.Map(null, "plugins.browser.js", "plugins.notification.js");
public string PathCustomPlugins => Path.Combine(pluginFolder, PluginGroup.Custom.GetSubFolder());
public string PathOfficialPlugins => Path.Combine(rootPath, "official");
public string PathCustomPlugins => Path.Combine(rootPath, "user");
public IEnumerable<Plugin> Plugins => plugins;
public IEnumerable<InjectedHTML> NotificationInjections => bridge.NotificationInjections;
public IPluginConfig Config { get; }
public event EventHandler<PluginErrorEventArgs> Reloaded;
public event EventHandler<PluginErrorEventArgs> Executed;
private readonly string pluginFolder;
private readonly string pluginDataFolder;
private readonly Control sync;
private readonly string rootPath;
private readonly PluginBridge bridge;
private readonly HashSet<Plugin> plugins = new HashSet<Plugin>();
@@ -40,23 +35,20 @@ namespace TweetDuck.Plugins{
private IWebBrowser mainBrowser;
public PluginManager(Control sync, IPluginConfig config, string pluginFolder, string pluginDataFolder){
public PluginManager(IPluginConfig config, string rootPath){
this.Config = config;
this.Config.PluginChangedState += Config_PluginChangedState;
this.pluginFolder = pluginFolder;
this.pluginDataFolder = pluginDataFolder;
this.sync = sync;
this.rootPath = rootPath;
this.bridge = new PluginBridge(this);
}
public void Register(IWebBrowser browser, PluginEnvironment environment, bool asMainBrowser = false){
public void Register(IWebBrowser browser, PluginEnvironment environment, Control sync, bool asMainBrowser = false){
browser.FrameLoadEnd += (sender, args) => {
IFrame frame = args.Frame;
if (frame.IsMain && TwitterUtils.IsTweetDeckWebsite(frame)){
ExecutePlugins(frame, environment);
ExecutePlugins(frame, environment, sync);
}
};
@@ -89,10 +81,10 @@ namespace TweetDuck.Plugins{
}
else if (plugin.HasConfig){
if (File.Exists(plugin.ConfigPath)){
using(Process.Start("explorer.exe", "/select,\"" + plugin.ConfigPath.Replace('/', '\\') + "\"")){}
using(Process.Start("explorer.exe", "/select,\""+plugin.ConfigPath.Replace('/', '\\')+"\"")){}
}
else{
using(Process.Start("explorer.exe", '"' + plugin.GetPluginFolder(PluginFolder.Data).Replace('/', '\\') + '"')){}
using(Process.Start("explorer.exe", '"'+plugin.GetPluginFolder(PluginFolder.Data).Replace('/', '\\')+'"')){}
}
}
}
@@ -111,7 +103,7 @@ namespace TweetDuck.Plugins{
}while(tokens.ContainsKey(token) && --attempts >= 0);
if (attempts < 0){
token = -tokens.Count - 1;
token = -tokens.Count-1;
}
tokens[token] = plugin;
@@ -126,22 +118,35 @@ namespace TweetDuck.Plugins{
plugins.Clear();
tokens.Clear();
List<string> loadErrors = new List<string>(1);
List<string> loadErrors = new List<string>(2);
foreach(var result in PluginGroupExtensions.Values.SelectMany(group => PluginLoader.AllInFolder(pluginFolder, pluginDataFolder, group))){
if (result.HasValue){
plugins.Add(result.Value);
IEnumerable<Plugin> LoadPluginsFrom(string path, PluginGroup group){
if (!Directory.Exists(path)){
yield break;
}
else{
loadErrors.Add(result.Exception.Message);
foreach(string fullDir in Directory.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly)){
Plugin plugin;
try{
plugin = PluginLoader.FromFolder(fullDir, group);
}catch(Exception e){
loadErrors.Add(group.GetIdentifierPrefix()+Path.GetFileName(fullDir)+": "+e.Message);
continue;
}
yield return plugin;
}
}
plugins.UnionWith(LoadPluginsFrom(PathOfficialPlugins, PluginGroup.Official));
plugins.UnionWith(LoadPluginsFrom(PathCustomPlugins, PluginGroup.Custom));
Reloaded?.Invoke(this, new PluginErrorEventArgs(loadErrors));
}
private void ExecutePlugins(IFrame frame, PluginEnvironment environment){
if (!HasAnyPlugin(environment) || !ScriptLoader.ExecuteFile(frame, SetupScriptPrefix + environment.GetPluginScriptFile(), sync)){
private void ExecutePlugins(IFrame frame, PluginEnvironment environment, Control sync){
if (!HasAnyPlugin(environment) || !ScriptLoader.ExecuteFile(frame, PluginSetupScriptNames[environment], sync)){
return;
}
@@ -165,16 +170,14 @@ namespace TweetDuck.Plugins{
try{
script = File.ReadAllText(path);
}catch(Exception e){
failedPlugins.Add($"{plugin.Identifier} ({Path.GetFileName(path)}): {e.Message}");
failedPlugins.Add(plugin.Identifier+" ("+Path.GetFileName(path)+"): "+e.Message);
continue;
}
ScriptLoader.ExecuteScript(frame, PluginScriptGenerator.GeneratePlugin(plugin.Identifier, script, GetTokenFromPlugin(plugin), environment), $"plugin:{plugin}");
ScriptLoader.ExecuteScript(frame, PluginScriptGenerator.GeneratePlugin(plugin.Identifier, script, GetTokenFromPlugin(plugin), environment), "plugin:"+plugin);
}
sync.InvokeAsyncSafe(() => {
Executed?.Invoke(this, new PluginErrorEventArgs(failedPlugins));
});
Executed?.Invoke(this, new PluginErrorEventArgs(failedPlugins));
}
}
}

View File

@@ -1,11 +1,10 @@
using System.Linq;
using TweetLib.Core.Features.Plugins.Config;
using TweetLib.Core.Features.Plugins.Enums;
using TweetDuck.Plugins.Enums;
namespace TweetLib.Core.Features.Plugins{
public static class PluginScriptGenerator{
namespace TweetDuck.Plugins{
static class PluginScriptGenerator{
public static string GenerateConfig(IPluginConfig config){
return "window.TD_PLUGINS.disabled = [" + string.Join(",", config.DisabledPlugins.Select(id => '"' + id + '"')) + "]";
return "window.TD_PLUGINS.disabled = ["+string.Join(",", config.DisabledPlugins.Select(id => $"\"{id}\""))+"]";
}
public static string GeneratePlugin(string pluginIdentifier, string pluginContents, int pluginToken, PluginEnvironment environment){

View File

@@ -2,8 +2,10 @@ using CefSharp;
using CefSharp.WinForms;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using TweetDuck.Configuration;
using TweetDuck.Core;
@@ -12,17 +14,15 @@ using TweetDuck.Core.Handling.General;
using TweetDuck.Core.Other;
using TweetDuck.Core.Management;
using TweetDuck.Core.Utils;
using TweetLib.Core;
using TweetLib.Core.Collections;
using TweetLib.Core.Utils;
using TweetDuck.Data;
namespace TweetDuck{
static class Program{
public const string BrandName = Lib.BrandName;
public const string VersionTag = Lib.VersionTag;
public const string BrandName = "TweetDuck";
public const string Website = "https://tweetduck.chylex.com";
public const string VersionTag = "1.17.4";
public static readonly string ProgramPath = AppDomain.CurrentDomain.BaseDirectory;
public static readonly bool IsPortable = File.Exists(Path.Combine(ProgramPath, "makeportable"));
@@ -48,18 +48,23 @@ namespace TweetDuck{
private static readonly LockManager LockManager = new LockManager(Path.Combine(StoragePath, ".lock"));
private static bool HasCleanedUp;
public static CultureInfo Culture { get; }
public static Reporter Reporter { get; }
public static ConfigManager Config { get; }
static Program(){
Culture = CultureInfo.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
#if DEBUG
CultureInfo.DefaultThreadCurrentUICulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); // force english exceptions
#endif
Reporter = new Reporter(ErrorLogFilePath);
Reporter.SetupUnhandledExceptionHandler("TweetDuck Has Failed :(");
Config = new ConfigManager();
Lib.Initialize(new App.Builder{
ErrorHandler = Reporter
});
}
[STAThread]
@@ -70,7 +75,7 @@ namespace TweetDuck{
WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore");
if (!FileUtils.CheckFolderWritePermission(StoragePath)){
if (!WindowsUtils.CheckFolderWritePermission(StoragePath)){
FormMessage.Warning("Permission Error", "TweetDuck does not have write permissions to the storage folder: "+StoragePath, FormMessage.OK);
return;
}
@@ -126,7 +131,7 @@ namespace TweetDuck{
}
try{
RequestHandlerBase.LoadResourceRewriteRules(Arguments.GetValue(Arguments.ArgFreeze));
RequestHandlerBase.LoadResourceRewriteRules(Arguments.GetValue(Arguments.ArgFreeze, null));
}catch(Exception e){
FormMessage.Error("Resource Freeze", "Error parsing resource rewrite rules: "+e.Message, FormMessage.OK);
return;
@@ -163,7 +168,7 @@ namespace TweetDuck{
// ProgramPath has a trailing backslash
string updaterArgs = "/SP- /SILENT /FORCECLOSEAPPLICATIONS /UPDATEPATH=\""+ProgramPath+"\" /RUNARGS=\""+Arguments.GetCurrentForInstallerCmd()+"\""+(IsPortable ? " /PORTABLE=1" : "");
bool runElevated = !IsPortable || !FileUtils.CheckFolderWritePermission(ProgramPath);
bool runElevated = !IsPortable || !WindowsUtils.CheckFolderWritePermission(ProgramPath);
if (WindowsUtils.OpenAssociatedProgram(mainForm.UpdateInstallerPath, updaterArgs, runElevated)){
Application.Exit();
@@ -175,7 +180,7 @@ namespace TweetDuck{
}
private static string GetDataStoragePath(){
string custom = Arguments.GetValue(Arguments.ArgDataFolder);
string custom = Arguments.GetValue(Arguments.ArgDataFolder, null);
if (custom != null && (custom.Contains(Path.DirectorySeparatorChar) || custom.Contains(Path.AltDirectorySeparatorChar))){
if (Path.GetInvalidPathChars().Any(custom.Contains)){

View File

@@ -120,6 +120,26 @@ namespace TweetDuck.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon overlay_muted {
get {
object obj = ResourceManager.GetObject("overlay_muted", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon overlay_notification {
get {
object obj = ResourceManager.GetObject("overlay_notification", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>

View File

@@ -136,6 +136,12 @@
<data name="icon_tray_new" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Images\icon-tray-new.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="overlay_muted" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Images\overlay-muted.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="overlay_notification" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Images\overlay-notification.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="spinner" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Images\spinner.apng;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>

View File

@@ -1,28 +1,30 @@
# Support
[Follow TweetDuck on Twitter](https://twitter.com/TryMyAwesomeApp) &nbsp;|&nbsp; [Support via Ko-fi](https://ko-fi.com/chylex) &nbsp;|&nbsp; [Support via Patreon](https://www.patreon.com/chylex)
[Follow TweetDuck on Twitter](https://twitter.com/TryMyAwesomeApp) &nbsp;|&nbsp; [Support via PayPal](https://paypal.me/chylex) &nbsp;|&nbsp; [Support via Patreon](https://www.patreon.com/chylex)
# Build Instructions
### Setup
The program can be built using Visual Studio 2019. Before opening the solution, please make sure you have the following workloads and components installed (optional components that are not listed can be deselected to save space):
The program can be built using Visual Studio 2017 or newer. Before opening the solution, please make sure you have the following workloads and components installed (optional components that are not listed can be deselected to save space):
* **.NET desktop development**
* .NET Framework 4.7.2 SDK
* .NET Framework 4 4.6 development tools
* F# desktop language support
* **Desktop development with C++**
* MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.20)
* *(VS 2017)* VC++ 2017 version 15.9 v14.16 latest v141 tools
* *(VS 2019)* MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.20)
After opening the solution, right-click the solution and select **Restore NuGet Packages**, or manually run this command in the **Package Manager Console**:
```
PM> Install-Package CefSharp.WinForms -Version 67.0.0
PM> Install-Package WindowsAPICodePack-Shell -Version 1.1.1
```
### Debug
The `Debug` configuration uses a separate data folder by default (`%LOCALAPPDATA%\TweetDuckDebug`) to avoid affecting an existing installation of TweetDuck. You can modify this by opening **TweetDuck Properties** in Visual Studio, clicking the **Debug** tab, and changing the **Command line arguments** field.
While debugging, opening the main menu and clicking **Reload browser** automatically rebuilds all resources in `Resources/Scripts` and `Resources/Plugins`. This allows editing HTML/CSS/JS files without restarting the program, but it will cause a short delay between browser reloads.
While debugging, opening the main menu and clicking **Reload browser** automatically rebuilds all resources in `Resources/Scripts` and `Resources/Plugins`. This allows editing HTML/CSS/JS files without restarting the program, but it will cause a short delay between browser reloads. An F# compiler must be present when building the project to enable this feature: `C:\Program Files (x86)\Microsoft SDKs\F#\10.1\Framework\v4.0\fsc.exe`
### Release
@@ -42,13 +44,18 @@ If you decide to publicly release a custom version, please make it clear that it
- Some files are checked for invalid characters:
- `Resources/Plugins/emoji-keyboard/emoji-ordering.txt` line endings must be LF (line feed); any CR (carriage return) in the file will cause a failed build, and you will need to ensure correct line endings in your text editor
#### Error: The "EmbedAllSources" parameter is not supported by the "Csc" task
1. Open `C:\Program Files (x86)\Visual Studio\2017\<edition>\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets` in a text editor
2. Remove line that says `EmbedAllSources="$(EmbedAllSources)"`
3. Hope the next Visual Studio update fixes it...
### Installers
TweetDuck uses **Inno Setup** for installers and updates. First, download and install [InnoSetup 5.6.1](http://files.jrsoftware.org/is/5/innosetup-5.6.1.exe) (with Preprocessor support) and the [Inno Download Plugin 1.5.0](https://drive.google.com/folderview?id=0Bzw1xBVt0mokSXZrUEFIanV4azA&usp=sharing#list).
TweetDuck uses **Inno Setup** for installers and updates. First, download and install [InnoSetup QuickStart Pack](http://www.jrsoftware.org/isdl.php) (non-unicode; editor and encryption support not required) and the [Inno Download Plugin](https://code.google.com/archive/p/inno-download-plugin).
Next, add the Inno Setup installation folder (usually `C:\Program Files (x86)\Inno Setup 5`) into your **PATH** environment variable. You may need to restart File Explorer and Visual Studio for the change to take place.
Next, add the Inno Setup installation folder (usually `C:\Program Files (x86)\Inno Setup 5`) into your **PATH** environment variable. You may need to restart File Explorer for the change to take place.
Now you can generate installers by running `bld/GEN INSTALLERS.bat`. Note that this will only package the files, you still need to run the [release build](#release) in Visual Studio first!
Now you can generate installers by running `bld/GEN INSTALLERS.bat`. Note that this will only package the files, you still need to run the [release build](#release) in Visual Studio!
After the window closes, three installers will be generated inside the `bld/Output` folder:
* **TweetDuck.exe**

View File

@@ -6,11 +6,9 @@ using System.Text;
using System.Windows.Forms;
using TweetDuck.Configuration;
using TweetDuck.Core.Other;
using TweetLib.Core;
using TweetLib.Core.Application;
namespace TweetDuck{
sealed class Reporter : IAppErrorHandler{
sealed class Reporter{
private readonly string logFile;
public Reporter(string logFile){
@@ -30,12 +28,8 @@ namespace TweetDuck{
}
public bool LogImportant(string data){
return ((IAppErrorHandler)this).Log(data);
}
bool IAppErrorHandler.Log(string text){
#if DEBUG
Debug.WriteLine(text);
Debug.WriteLine(data);
#endif
StringBuilder build = new StringBuilder();
@@ -44,8 +38,8 @@ namespace TweetDuck{
build.Append("Please, report all issues to: https://github.com/chylex/TweetDuck/issues\r\n\r\n");
}
build.Append("[").Append(DateTime.Now.ToString("G", Lib.Culture)).Append("]\r\n");
build.Append(text).Append("\r\n\r\n");
build.Append("[").Append(DateTime.Now.ToString("G", Program.Culture)).Append("]\r\n");
build.Append(data).Append("\r\n\r\n");
try{
File.AppendAllText(logFile, build.ToString(), Encoding.UTF8);

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@@ -8,7 +8,6 @@ enabled(){
_theme: "light",
themeOverride: false,
columnWidth: "310px",
composerWidth: "default",
fontSize: "12px",
hideTweetActions: true,
moveTweetActionsToRight: true,
@@ -381,15 +380,8 @@ enabled(){
this.css.insert("#general_settings .cf { display: none !important }");
this.css.insert("#settings-modal .js-setting-list li:nth-child(3) { border-bottom: 1px solid #ccd6dd }");
this.css.insert(`html[data-td-font] { font-size: ${this.config.fontSize} !important }`);
this.css.insert(`.avatar { border-radius: ${this.config.avatarRadius}% !important }`);
if (this.config.composerWidth !== "default"){
const width = this.config.composerWidth;
this.css.insert(`.js-app-content.is-open { margin-right: ${width} !important; transform: translateX(${width}) !important }`);
this.css.insert(`#tduck .js-app-content.tduck-is-opening { margin-right: 0 !important }`);
this.css.insert(`.js-drawer { width: ${width} !important; left: -${width} !important }`);
}
this.css.insert("html[data-td-font] { font-size: "+this.config.fontSize+" !important }");
this.css.insert(".avatar { border-radius: "+this.config.avatarRadius+"% !important }");
let currentTheme = TD.settings.getTheme();
@@ -578,7 +570,7 @@ ${iconData.map(entry => `#tduck .icon-${entry[0]}:before{content:\"\\f0${entry[1
let cols = this.config.columnWidth.slice(1);
this.css.insert(".column { width: calc((100vw - 205px) / "+cols+" - 6px) !important; min-width: 160px }");
this.css.insert(".is-condensed .column { width: calc((100vw - 65px) / "+cols+" - 6px) !important }");
this.css.insert(".is-condensed .column { width: calc((100vw - 55px) / "+cols+" - 6px) !important }");
}
else{
this.css.insert(".column { width: "+this.config.columnWidth+" !important }");
@@ -646,13 +638,6 @@ ${notificationScrollbarColor ? `
$(".js-dropdown.pos-r").toggleClass("pos-r pos-l");
}
};
this.uiDrawerActiveEvent = (e, data) => {
return if data.activeDrawer === null || this.config.composerWidth === "default";
const ele = $(".js-app-content").addClass("tduck-is-opening");
setTimeout(() => ele.removeClass("tduck-is-opening"), 250);
};
}
ready(){
@@ -662,7 +647,6 @@ ready(){
// layout events
$(document).on("uiShowActionsMenu", this.uiShowActionsMenuEvent);
$(document).on("uiDrawerActive", this.uiDrawerActiveEvent);
// modal
$("[data-action='settings-menu']").on("click", this.onSettingsMenuClickedEvent);
@@ -725,12 +709,10 @@ disabled(){
window.clearTimeout(this.optimizationTimer);
}
$(document).off("uiShowActionsMenu", this.uiShowActionsMenuEvent);
$(window).off("focus", this.onWindowFocusEvent);
$(window).off("blur", this.onWindowBlurEvent);
$(document).off("uiShowActionsMenu", this.uiShowActionsMenuEvent);
$(document).off("uiDrawerActive", this.uiDrawerActiveEvent);
TD.components.GlobalSettings.prototype.getInfo = this.prevFuncSettingsGetInfo;
TD.components.GlobalSettings.prototype.switchTab = this.prevFuncSettingsSwitchTab;

View File

@@ -55,20 +55,6 @@
<option disabled></option>
</select>
<!-- COMPOSER SIZE -->
<label class="txt-uppercase touch-larger-label">
<b>New Tweet panel</b>
</label>
<select data-td-key="composerWidth">
<option value="default">Default</option>
<option value="270px">Narrow (270px)</option>
<option value="310px">Medium (310px)</option>
<option value="350px">Wide (350px)</option>
<option value="custom-px">Custom</option>
<option value="change-custom-px">Change custom value...</option>
</select>
<!-- FONT SIZE -->
<label class="txt-uppercase touch-larger-label">
@@ -83,6 +69,10 @@
<option value="custom-px">Custom</option>
<option value="change-custom-px">Change custom value...</option>
</select>
<label class="checkbox">
<input data-td-key="forceArialFont" class="js-theme-checkbox touch-larger-label" type="checkbox">
Use Arial as default font
</label>
<label class="checkbox">
<input data-td-key="increaseQuoteTextSize" class="js-theme-checkbox touch-larger-label" type="checkbox">
Increase quoted tweet font size
@@ -126,10 +116,6 @@
<input data-td-key="themeColorTweaks" class="js-theme-checkbox touch-larger-label" type="checkbox">
Theme color tweaks
</label>
<label class="checkbox">
<input data-td-key="forceArialFont" class="js-theme-checkbox touch-larger-label" type="checkbox">
Use Arial as default font
</label>
<!-- ADVANCED -->
@@ -186,7 +172,7 @@
#edit-design-panel {
width: 693px;
height: 424px;
height: 380px;
background-color: #FFF;
box-shadow: 0 0 10px rgba(17, 17, 17, 0.5);
}
@@ -231,7 +217,7 @@
#edit-design-panel-content label.radio {
display: inline-block;
margin: 0 16px 0 4px;
margin: 0 16px 5px 4px;
cursor: pointer;
}

View File

@@ -506,6 +506,18 @@ html.dark .lst-group .selected a:hover{background:#55acee}
html.dark .lst-group .selected .fullname,html.dark .lst-group .selected .inner strong,html.dark .lst-group .selected .list-link,html.dark .lst-group .selected .list-twitter-list,html.dark .lst-group .selected .list-subtitle,html.dark .lst-group .selected .list-account,html.dark .lst-group .selected .list-listmember,html.dark .lst-group .selected .txt-ellipsis{color:#F5F8FA}
html.dark .lst-group .selected .username,html.dark .lst-group .selected .bytext,html.dark .lst-group .selected .subtitle,html.dark .lst-group .selected .icon-protected{color:#eef3f7}
html.dark .itm-remove{border-top:1px solid #ddd}
html.dark .caret-outer{border-bottom:7px solid rgba(17,17,17,0.1)}
html.dark .caret-inner{border-bottom:6px solid #fff}
html.dark .drp-h-divider{border-bottom:1px solid #ddd}
html.dark .dropdown-menu .typeahead-item,html.dark .dropdown-menu [data-action]{color:#292F33}
html.dark .dropdown-menu .is-selected{background:#55acee;color:#fff}
html.dark .dropdown-menu .is-selected [data-action]{color:#fff}
html.dark .dropdown-menu .is-selected a:not(:hover):not(:focus){color:#fff}
html.dark .dropdown-menu a:not(:hover):not(:focus){color:#292F33}
html.dark .dropdown-menu-old li:hover{background:#55acee}
html.dark .dropdown-menu-old li:hover a{color:#fff}
html.dark .dropdown-menu-old li:hover .attribution{color:#fff}
html.dark .non-selectable-item{color:#292F33}
html.dark .update-available-item:before{background-color:#FFAD1F}
html.dark .is-selected .update-available-item:before{background-color:rgba(41,47,51,0.2)}
html.dark .popover{background-color:#fff;box-shadow:0 0 10px rgba(17,17,17,0.7)}

View File

@@ -380,9 +380,13 @@ enabled(){
hideKeyboard();
};
this.composerActiveEvent = function(e){
$(".emoji-keyboard-popup-btn", me.composeDrawer).on("click", me.emojiKeyboardButtonClickEvent);
$(".js-docked-compose .js-compose-scroller > .scroll-v", me.composeDrawer).on("scroll", me.composerScrollEvent);
this.drawerToggleEvent = function(e, data){
if (data.activeDrawer === "compose"){
setTimeout(function(){
$(".emoji-keyboard-popup-btn", me.composeDrawer).on("click", me.emojiKeyboardButtonClickEvent);
$(".js-docked-compose .js-compose-scroller > .scroll-v", me.composeDrawer).on("scroll", me.composerScrollEvent);
}, 0);
}
};
this.documentClickEvent = function(e){
@@ -410,7 +414,7 @@ enabled(){
if (maybeDockedComposePanel.length){
maybeDockedComposePanel.find(".cf.margin-t--12.margin-b--30").first().append(buttonHTML);
this.composerActiveEvent();
this.drawerToggleEvent({}, { activeDrawer: "compose" });
}
}
@@ -420,7 +424,7 @@ ready(){
$(document).on("click", this.documentClickEvent);
$(document).on("keydown", this.documentKeyEvent);
$(document).on("tduckOldComposerActive", this.composerActiveEvent);
$(document).on("uiDrawerActive", this.drawerToggleEvent);
$(document).on("uiComposeImageAdded", this.uploadFilesEvent);
this.composeDrawer.on("uiComposeTweetSending", this.composerSendingEvent);
@@ -546,7 +550,7 @@ disabled(){
$(document).off("click", this.documentClickEvent);
$(document).off("keydown", this.documentKeyEvent);
$(document).off("tduckOldComposerActive", this.composerActiveEvent);
$(document).off("uiDrawerActive", this.drawerToggleEvent);
$(document).off("uiComposeImageAdded", this.uploadFilesEvent);
this.composeDrawer.off("uiComposeTweetSending", this.composerSendingEvent);

View File

@@ -376,7 +376,7 @@ enabled(){
};
this.drawerToggleEvent = function(e, data){
if (typeof data === "undefined" || data.activeDrawer !== "compose"){
if (data.activeDrawer === null){
hideTemplateModal();
}
};
@@ -385,7 +385,6 @@ enabled(){
ready(){
$(".js-drawer[data-drawer='compose']").on("click", ".manage-templates-btn", this.manageTemplatesButtonClickEvent);
$(document).on("uiDrawerActive", this.drawerToggleEvent);
$(document).on("click", ".js-new-composer-opt-in", this.drawerToggleEvent);
}
disabled(){
@@ -394,7 +393,6 @@ disabled(){
$(".js-drawer[data-drawer='compose']").off("click", ".manage-templates-btn", this.manageTemplatesButtonClickEvent);
$(document).off("uiDrawerActive", this.drawerToggleEvent);
$(document).off("click", ".js-new-composer-opt-in", this.drawerToggleEvent);
TD.mustaches["compose/docked_compose.mustache"] = this.prevComposeMustache;
}

View File

@@ -145,7 +145,7 @@ namespace TweetDuck.Resources{
// ReSharper disable PossibleNullReferenceException
object instPluginManager = typeFormBrowser.GetField("plugins", flagsInstance).GetValue(FormManager.TryFind<FormBrowser>());
typePluginManager.GetField("pluginFolder", flagsInstance).SetValue(instPluginManager, newPluginRoot);
typePluginManager.GetField("rootPath", flagsInstance).SetValue(instPluginManager, newPluginRoot);
Debug.WriteLine("Reloading hot swapped plugins...");
((PluginManager)instPluginManager).Reload();

View File

@@ -477,19 +477,6 @@
});
});
//
// Block: Hook into composer event.
//
execSafe(function hookComposerEvents(){
$(document).on("uiDrawerActive uiRwebComposerOptOut", function(e, data){
return if e.type === "uiDrawerActive" && data.activeDrawer !== "compose";
setTimeout(function(){
$(document).trigger("tduckOldComposerActive");
}, 0);
});
});
//
// Block: Add TweetDuck buttons to the settings menu.
//
@@ -823,7 +810,7 @@
html.addClass($(document.documentElement).attr("class"));
html.addClass($(document.body).attr("class"));
html.css("background-color", getClassStyleProperty("stream-item", "background-color"));
html.css("background-color", getClassStyleProperty("column", "background-color"));
html.css("border", "none");
for(let selector of [ ".js-quote-detail", ".js-media-preview-container", ".js-media" ]){
@@ -1060,8 +1047,12 @@
setTimeout(refocusInput, 0);
};
$(document).on("tduckOldComposerActive", function(e){
$$(".js-account-list", ".js-docked-compose").delegate(".js-account-item", "click", accountItemClickEvent);
$(document).on("uiDrawerActive", function(e, data){
if (data.activeDrawer === "compose"){
setTimeout(function(){
$$(".js-account-list", ".js-docked-compose").delegate(".js-account-item", "click", accountItemClickEvent);
}, 0);
}
});
});
@@ -1298,31 +1289,6 @@
};
});
//
// Block: Fix DM image previews and GIF thumbnails not loading due to new URLs.
//
if (ensurePropertyExists(TD, "services", "TwitterMedia", "prototype", "getTwitterPreviewUrl")){
const prevFunc = TD.services.TwitterMedia.prototype.getTwitterPreviewUrl;
TD.services.TwitterMedia.prototype.getTwitterPreviewUrl = function(){
const url = prevFunc.apply(this, arguments);
if (url.startsWith("https://ton.twitter.com/1.1/ton/data/dm/") || url.startsWith("https://pbs.twimg.com/tweet_video_thumb/")){
const format = url.match(/\?.*format=(\w+)/);
if (format && format.length === 2){
const fix = `.${format[1]}?`;
if (!url.includes(fix)){
return url.replace("?", fix);
}
}
}
return url;
};
}
//
// Block: Fix youtu.be previews not showing up for https links.
//
@@ -1342,25 +1308,29 @@
//
// Block: Add a pin icon to make tweet compose drawer stay open.
//
execSafe(function setupStayOpenPin(){
$(document).on("tduckOldComposerActive", function(e){
let ele = $(`#import "markup/pin.html"`).appendTo(".js-docked-compose .js-compose-header");
ele.click(function(){
if (TD.settings.getComposeStayOpen()){
ele.css("transform", "rotate(0deg)");
TD.settings.setComposeStayOpen(false);
}
else{
ele.css("transform", "rotate(90deg)");
TD.settings.setComposeStayOpen(true);
}
});
onAppReady.push(function setupStayOpenPin(){
let ele = $(`
<svg id="td-compose-drawer-pin" viewBox="0 0 24 24" class="icon js-show-tip" data-original-title="Stay open" data-tooltip-position="left">
<path d="M9.884,16.959l3.272,0.001l-0.82,4.568l-1.635,0l-0.817,-4.569Z"/>
<rect x="8.694" y="7.208" width="5.652" height="7.445"/>
<path d="M16.877,17.448c0,-1.908 -1.549,-3.456 -3.456,-3.456l-3.802,0c-1.907,0 -3.456,1.548 -3.456,3.456l10.714,0Z"/>
<path d="M6.572,5.676l2.182,2.183l5.532,0l2.182,-2.183l0,-1.455l-9.896,0l0,1.455Z"/>
</svg>`).appendTo(".js-docked-compose .js-compose-header");
ele.click(function(){
if (TD.settings.getComposeStayOpen()){
ele.css("transform", "rotate(0deg)");
TD.settings.setComposeStayOpen(false);
}
else{
ele.css("transform", "rotate(90deg)");
TD.settings.setComposeStayOpen(true);
}
});
if (TD.settings.getComposeStayOpen()){
ele.css("transform", "rotate(90deg)");
}
});
//
@@ -1617,7 +1587,7 @@
}
//
// Block: Fix broken horizontal scrolling of column container when holding Shift.
// Block: Fix broken horizontal scrolling of column container when holding Shift. TODO Fix broken smooth scrolling.
//
if (ensurePropertyExists(TD, "ui", "columns", "setupColumnScrollListeners")){
TD.ui.columns.setupColumnScrollListeners = appendToFunction(TD.ui.columns.setupColumnScrollListeners, function(column){
@@ -1625,7 +1595,9 @@
return if !ele.length;
ele.off("onmousewheel").on("mousewheel", ".scroll-v", function(e){
e.stopImmediatePropagation();
if (e.shiftKey){
e.stopImmediatePropagation();
}
});
window.TDGF_prioritizeNewestEvent(ele[0], "mousewheel");

View File

@@ -1,6 +0,0 @@
<svg id="td-compose-drawer-pin" viewBox="0 0 24 24" class="icon js-show-tip" data-original-title="Stay open" data-tooltip-position="left">
<path d="M9.884,16.959l3.272,0.001l-0.82,4.568l-1.635,0l-0.817,-4.569Z"/>
<rect x="8.694" y="7.208" width="5.652" height="7.445"/>
<path d="M16.877,17.448c0,-1.908 -1.549,-3.456 -3.456,-3.456l-3.802,0c-1.907,0 -3.456,1.548 -3.456,3.456l10.714,0Z"/>
<path d="M6.572,5.676l2.182,2.183l5.532,0l2.182,-2.183l0,-1.455l-9.896,0l0,1.455Z"/>
</svg>

Before

Width:  |  Height:  |  Size: 488 B

View File

@@ -249,14 +249,10 @@ a[data-full-url] {
transition: transform 0.1s ease;
}
.js-docked-compose .compose-remember-state {
.js-docked-compose footer {
display: none !important;
}
.js-new-composer-opt-in {
border-bottom: none !important;
}
.compose-content {
bottom: 0 !important;
}

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="packages\Microsoft.Net.Compilers.2.9.0\build\Microsoft.Net.Compilers.props" Condition="Exists('packages\Microsoft.Net.Compilers.2.9.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="packages\CefSharp.WinForms.67.0.0\build\CefSharp.WinForms.props" Condition="Exists('packages\CefSharp.WinForms.67.0.0\build\CefSharp.WinForms.props')" />
<Import Project="packages\CefSharp.Common.67.0.0\build\CefSharp.Common.props" Condition="Exists('packages\CefSharp.Common.67.0.0\build\CefSharp.Common.props')" />
<Import Project="packages\cef.redist.x86.3.3396.1786\build\cef.redist.x86.props" Condition="Exists('packages\cef.redist.x86.3.3396.1786\build\cef.redist.x86.props')" />
@@ -14,8 +14,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TweetDuck</RootNamespace>
<AssemblyName>TweetDuck</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<LangVersion>8.0</LangVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ApplicationIcon>Resources\Images\icon.ico</ApplicationIcon>
@@ -34,6 +33,7 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>7</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\x86\Release\</OutputPath>
@@ -43,8 +43,15 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>7</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\WindowsAPICodePack-Core.1.1.1\lib\Microsoft.WindowsAPICodePack.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAPICodePack.Shell, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\WindowsAPICodePack-Shell.1.1.1\lib\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
@@ -54,7 +61,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration\Arguments.cs" />
<Compile Include="Configuration\Instance\FileConfigInstance.cs" />
<Compile Include="Configuration\ConfigManager.cs" />
<Compile Include="Configuration\Instance\IConfigInstance.cs" />
<Compile Include="Configuration\Instance\PluginConfigInstance.cs" />
<Compile Include="Configuration\LockManager.cs" />
<Compile Include="Configuration\SystemConfig.cs" />
<Compile Include="Configuration\UserConfig.cs" />
@@ -194,7 +204,10 @@
<DependentUpon>TabSettingsFeedback.cs</DependentUpon>
</Compile>
<Compile Include="Core\TweetDeckBrowser.cs" />
<Compile Include="Core\Utils\LocaleUtils.cs" />
<Compile Include="Core\Utils\StringUtils.cs" />
<Compile Include="Core\Utils\TwitterUtils.cs" />
<Compile Include="Data\CombinedFileStream.cs" />
<Compile Include="Core\Management\ProfileManager.cs" />
<Compile Include="Core\Other\Settings\TabSettingsAdvanced.cs">
<SubType>UserControl</SubType>
@@ -224,11 +237,19 @@
<DependentUpon>TabSettingsNotifications.cs</DependentUpon>
</Compile>
<Compile Include="Core\Notification\Screenshot\ScreenshotBridge.cs" />
<Compile Include="Data\CommandLineArgs.cs" />
<Compile Include="Core\Notification\Screenshot\FormNotificationScreenshotable.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Core\Notification\Screenshot\TweetScreenshotManager.cs" />
<Compile Include="Data\ResourceLink.cs" />
<Compile Include="Data\Result.cs" />
<Compile Include="Data\Serialization\FileSerializer.cs" />
<Compile Include="Data\InjectedHTML.cs" />
<Compile Include="Data\Serialization\ITypeConverter.cs" />
<Compile Include="Data\Serialization\SerializationSoftException.cs" />
<Compile Include="Data\Serialization\SingleTypeConverter.cs" />
<Compile Include="Data\TwoKeyDictionary.cs" />
<Compile Include="Data\WindowState.cs" />
<Compile Include="Core\Utils\WindowsUtils.cs" />
<Compile Include="Core\Bridge\TweetDeckBridge.cs" />
@@ -238,23 +259,34 @@
<Compile Include="Core\Other\FormSettings.Designer.cs">
<DependentUpon>FormSettings.cs</DependentUpon>
</Compile>
<Compile Include="Plugins\PluginControl.cs">
<Compile Include="Plugins\Controls\PluginControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Plugins\PluginControl.Designer.cs">
<Compile Include="Plugins\Controls\PluginControl.Designer.cs">
<DependentUpon>PluginControl.cs</DependentUpon>
</Compile>
<Compile Include="Plugins\PluginListFlowLayout.cs">
<Compile Include="Plugins\Controls\PluginListFlowLayout.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Plugins\Enums\PluginFolder.cs" />
<Compile Include="Plugins\IPluginConfig.cs" />
<Compile Include="Plugins\Plugin.cs" />
<Compile Include="Plugins\Events\PluginChangedStateEventArgs.cs" />
<Compile Include="Plugins\PluginBridge.cs" />
<Compile Include="Configuration\PluginConfig.cs" />
<Compile Include="Plugins\Enums\PluginEnvironment.cs" />
<Compile Include="Plugins\Enums\PluginGroup.cs" />
<Compile Include="Plugins\Events\PluginErrorEventArgs.cs" />
<Compile Include="Plugins\PluginLoader.cs" />
<Compile Include="Plugins\PluginManager.cs" />
<Compile Include="Plugins\PluginScriptGenerator.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Reporter.cs" />
<Compile Include="Updates\UpdateCheckEventArgs.cs" />
<Compile Include="Updates\FormUpdateDownload.cs">
<SubType>Form</SubType>
</Compile>
@@ -271,6 +303,9 @@
<Compile Include="Core\Utils\BrowserUtils.cs" />
<Compile Include="Core\Utils\NativeMethods.cs" />
<Compile Include="Updates\UpdateCheckClient.cs" />
<Compile Include="Updates\UpdateDownloadStatus.cs" />
<Compile Include="Updates\UpdateHandler.cs" />
<Compile Include="Updates\UpdateInfo.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\ScriptLoader.cs" />
@@ -351,10 +386,6 @@
<None Include="Resources\Scripts\update.js" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="lib\TweetLib.Core\TweetLib.Core.csproj">
<Project>{93ba3cb4-a812-4949-b07d-8d393fb38937}</Project>
<Name>TweetLib.Core</Name>
</ProjectReference>
<ProjectReference Include="subprocess\TweetDuck.Browser.csproj">
<Project>{b10b0017-819e-4f71-870f-8256b36a26aa}</Project>
<Name>TweetDuck.Browser</Name>
@@ -368,6 +399,15 @@
<Name>TweetLib.Communication</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Resources\Images\overlay-muted.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Images\overlay-muted.ico" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Images\overlay-notification.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>rmdir "$(ProjectDir)bin\Debug"
@@ -384,7 +424,7 @@ IF EXIST "$(ProjectDir)bld\post_build.exe" (
</PostBuildEvent>
</PropertyGroup>
<Target Name="BeforeBuild" Condition="(!$([System.IO.File]::Exists(&quot;$(ProjectDir)\bld\post_build.exe&quot;)) OR ($([System.IO.File]::GetLastWriteTime(&quot;$(ProjectDir)\Resources\PostBuild.fsx&quot;).Ticks) &gt; $([System.IO.File]::GetLastWriteTime(&quot;$(ProjectDir)\bld\post_build.exe&quot;).Ticks)))">
<Exec Command="&quot;$(ProjectDir)bld\POST BUILD.bat&quot; &quot;$(DevEnvDir)CommonExtensions\Microsoft\FSharp\fsc.exe&quot;" WorkingDirectory="$(ProjectDir)bld\" IgnoreExitCode="true" />
<Exec Command="&quot;$(ProjectDir)bld\POST BUILD.bat&quot;" WorkingDirectory="$(ProjectDir)bld\" IgnoreExitCode="true" />
</Target>
<Target Name="AfterBuild" Condition="$(ConfigurationName) == Release">
<Exec Command="del &quot;$(TargetDir)*.pdb&quot;" />
@@ -406,7 +446,7 @@ IF EXIST "$(ProjectDir)bld\post_build.exe" (
<Error Condition="!Exists('packages\CefSharp.Common.67.0.0\build\CefSharp.Common.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\CefSharp.Common.67.0.0\build\CefSharp.Common.targets'))" />
<Error Condition="!Exists('packages\CefSharp.WinForms.67.0.0\build\CefSharp.WinForms.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\CefSharp.WinForms.67.0.0\build\CefSharp.WinForms.props'))" />
<Error Condition="!Exists('packages\CefSharp.WinForms.67.0.0\build\CefSharp.WinForms.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\CefSharp.WinForms.67.0.0\build\CefSharp.WinForms.targets'))" />
<Error Condition="!Exists('packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('packages\Microsoft.Net.Compilers.2.9.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Net.Compilers.2.9.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
<Import Project="packages\CefSharp.Common.67.0.0\build\CefSharp.Common.targets" Condition="Exists('packages\CefSharp.Common.67.0.0\build\CefSharp.Common.targets')" />
<Import Project="packages\CefSharp.WinForms.67.0.0\build\CefSharp.WinForms.targets" Condition="Exists('packages\CefSharp.WinForms.67.0.0\build\CefSharp.WinForms.targets')" />

View File

@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetDuck", "TweetDuck.csproj", "{2389A7CD-E0D3-4706-8294-092929A33A2D}"
EndProject
@@ -14,8 +14,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetTest.System", "lib\Twe
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "TweetTest.Unit", "lib\TweetTest.Unit\TweetTest.Unit.fsproj", "{EEE1071A-28FA-48B1-82A1-9CBDC5C3F2C3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TweetDuck.Core", "lib\TweetLib.Core\TweetLib.Core.csproj", "{93BA3CB4-A812-4949-B07D-8D393FB38937}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@@ -44,10 +42,6 @@ Global
{EEE1071A-28FA-48B1-82A1-9CBDC5C3F2C3}.Debug|x86.ActiveCfg = Debug|x86
{EEE1071A-28FA-48B1-82A1-9CBDC5C3F2C3}.Debug|x86.Build.0 = Debug|x86
{EEE1071A-28FA-48B1-82A1-9CBDC5C3F2C3}.Release|x86.ActiveCfg = Debug|x86
{93BA3CB4-A812-4949-B07D-8D393FB38937}.Debug|x86.ActiveCfg = Debug|x86
{93BA3CB4-A812-4949-B07D-8D393FB38937}.Debug|x86.Build.0 = Debug|x86
{93BA3CB4-A812-4949-B07D-8D393FB38937}.Release|x86.ActiveCfg = Release|x86
{93BA3CB4-A812-4949-B07D-8D393FB38937}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -1,6 +1,5 @@
using System;
using System.Windows.Forms;
using TweetLib.Core.Features.Updates;
namespace TweetDuck.Updates{
sealed partial class FormUpdateDownload : Form{

View File

@@ -6,12 +6,10 @@ using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using TweetDuck.Core.Utils;
using TweetLib.Core.Features.Updates;
using TweetLib.Core.Utils;
using JsonObject = System.Collections.Generic.IDictionary<string, object>;
namespace TweetDuck.Updates{
sealed class UpdateCheckClient : IUpdateCheckClient{
sealed class UpdateCheckClient{
private const string ApiLatestRelease = "https://api.github.com/repos/chylex/TweetDuck/releases/latest";
private const string UpdaterAssetName = "TweetDuck.Update.exe";
@@ -21,12 +19,10 @@ namespace TweetDuck.Updates{
this.installerFolder = installerFolder;
}
bool IUpdateCheckClient.CanCheck => Program.Config.User.EnableUpdateCheck;
Task<UpdateInfo> IUpdateCheckClient.Check(){
public Task<UpdateInfo> Check(){
TaskCompletionSource<UpdateInfo> result = new TaskCompletionSource<UpdateInfo>();
WebClient client = WebUtils.NewClient(BrowserUtils.UserAgentVanilla);
WebClient client = BrowserUtils.CreateWebClient();
client.Headers[HttpRequestHeader.Accept] = "application/vnd.github.v3+json";
client.DownloadStringTaskAsync(ApiLatestRelease).ContinueWith(task => {
@@ -69,9 +65,10 @@ namespace TweetDuck.Updates{
private static Exception ExpandWebException(Exception e){
if (e is WebException we && we.Response is HttpWebResponse response){
try{
using var stream = response.GetResponseStream();
using var reader = new StreamReader(stream, Encoding.GetEncoding(response.CharacterSet ?? "utf-8"));
return new Reporter.ExpandedLogException(e, reader.ReadToEnd());
using(Stream stream = response.GetResponseStream())
using(StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(response.CharacterSet ?? "utf-8"))){
return new Reporter.ExpandedLogException(e, reader.ReadToEnd());
}
}catch{
// whatever
}

View File

@@ -1,8 +1,8 @@
using System;
using TweetLib.Core.Data;
using TweetDuck.Data;
namespace TweetLib.Core.Features.Updates{
public sealed class UpdateCheckEventArgs : EventArgs{
namespace TweetDuck.Updates{
sealed class UpdateCheckEventArgs : EventArgs{
public int EventId { get; }
public Result<UpdateInfo> Result { get; }

View File

@@ -1,4 +1,4 @@
namespace TweetLib.Core.Features.Updates{
namespace TweetDuck.Updates{
public enum UpdateDownloadStatus{
None = 0,
InProgress,

View File

@@ -1,38 +1,34 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using TweetLib.Core.Data;
using Timer = System.Timers.Timer;
using TweetDuck.Data;
using Timer = System.Windows.Forms.Timer;
namespace TweetLib.Core.Features.Updates{
public sealed class UpdateHandler : IDisposable{
namespace TweetDuck.Updates{
sealed class UpdateHandler : IDisposable{
public const int CheckCodeUpdatesDisabled = -1;
private readonly IUpdateCheckClient client;
private readonly UpdateCheckClient client;
private readonly TaskScheduler scheduler;
private readonly Timer timer;
public event EventHandler<UpdateCheckEventArgs> CheckFinished;
private ushort lastEventId;
public UpdateHandler(IUpdateCheckClient client, TaskScheduler scheduler){
this.client = client;
this.scheduler = scheduler;
public UpdateHandler(string installerFolder){
this.client = new UpdateCheckClient(installerFolder);
this.scheduler = TaskScheduler.FromCurrentSynchronizationContext();
this.timer = new Timer{
AutoReset = false,
Enabled = false
};
this.timer.Elapsed += timer_Elapsed;
this.timer = new Timer();
this.timer.Tick += timer_Tick;
}
public void Dispose(){
timer.Dispose();
}
private void timer_Elapsed(object sender, ElapsedEventArgs e){
private void timer_Tick(object sender, EventArgs e){
timer.Stop();
Check(false);
}
@@ -43,9 +39,9 @@ namespace TweetLib.Core.Features.Updates{
timer.Stop();
if (client.CanCheck){
if (Program.Config.User.EnableUpdateCheck){
DateTime now = DateTime.Now;
TimeSpan nextHour = now.AddSeconds(60 * (60 - now.Minute) - now.Second) - now;
TimeSpan nextHour = now.AddSeconds(60*(60-now.Minute)-now.Second)-now;
if (nextHour.TotalMinutes < 15){
nextHour = nextHour.Add(TimeSpan.FromHours(1));
@@ -57,7 +53,7 @@ namespace TweetLib.Core.Features.Updates{
}
public int Check(bool force){
if (client.CanCheck || force){
if (Program.Config.User.EnableUpdateCheck || force){
int nextEventId = unchecked(++lastEventId);
Task<UpdateInfo> checkTask = client.Check();

View File

@@ -1,20 +1,20 @@
using System;
using System.IO;
using System.Net;
using TweetLib.Core.Utils;
using TweetDuck.Core.Utils;
namespace TweetLib.Core.Features.Updates{
public sealed class UpdateInfo{
namespace TweetDuck.Updates{
sealed class UpdateInfo{
public string VersionTag { get; }
public string ReleaseNotes { get; }
public string InstallerPath { get; }
public UpdateDownloadStatus DownloadStatus { get; private set; }
public Exception? DownloadError { get; private set; }
public Exception DownloadError { get; private set; }
private readonly string downloadUrl;
private readonly string installerFolder;
private WebClient? currentDownload;
private WebClient currentDownload;
public UpdateInfo(string versionTag, string releaseNotes, string downloadUrl, string installerFolder){
this.downloadUrl = downloadUrl;
@@ -22,11 +22,11 @@ namespace TweetLib.Core.Features.Updates{
this.VersionTag = versionTag;
this.ReleaseNotes = releaseNotes;
this.InstallerPath = Path.Combine(installerFolder, $"{Lib.BrandName}.{versionTag}.exe");
this.InstallerPath = Path.Combine(installerFolder, $"TweetDuck.{versionTag}.exe");
}
public void BeginSilentDownload(){
if (FileUtils.FileExistsAndNotEmpty(InstallerPath)){
if (WindowsUtils.FileExistsAndNotEmpty(InstallerPath)){
DownloadStatus = UpdateDownloadStatus.Done;
return;
}
@@ -48,9 +48,7 @@ namespace TweetLib.Core.Features.Updates{
return;
}
WebClient client = WebUtils.NewClient($"{Lib.BrandName} {Lib.VersionTag}");
client.DownloadFileCompleted += WebUtils.FileDownloadCallback(InstallerPath, () => {
currentDownload = BrowserUtils.DownloadFileAsync(downloadUrl, InstallerPath, null, () => {
DownloadStatus = UpdateDownloadStatus.Done;
currentDownload = null;
}, e => {
@@ -58,8 +56,6 @@ namespace TweetLib.Core.Features.Updates{
DownloadStatus = UpdateDownloadStatus.Failed;
currentDownload = null;
});
client.DownloadFileAsync(new Uri(downloadUrl), InstallerPath);
}
}

View File

@@ -1,12 +1,16 @@
@ECHO OFF
IF EXIST "post_build.exe" (
DEL "post_build.exe"
DEL "post_build.exe"
SET fsc="%PROGRAMFILES(x86)%\Microsoft SDKs\F#\10.1\Framework\v4.0\fsc.exe"
IF NOT EXIST %fsc% (
SET fsc="%PROGRAMFILES%\Microsoft SDKs\F#\10.1\Framework\v4.0\fsc.exe"
)
IF NOT EXIST %1 (
IF NOT EXIST %fsc% (
ECHO fsc.exe not found
EXIT 1
)
%1 --standalone --deterministic --preferreduilang:en-US --platform:x86 --target:exe --out:post_build.exe "%~dp0..\Resources\PostBuild.fsx"
%fsc% --standalone --deterministic --preferreduilang:en-US --platform:x86 --target:exe --out:post_build.exe "%~dp0..\Resources\PostBuild.fsx"

View File

@@ -76,14 +76,14 @@ function TDGetNetFrameworkVersion: Cardinal; forward;
function TDIsVCMissing: Boolean; forward;
procedure TDInstallVCRedist; forward;
{ Check .NET Framework version on startup, ask user if they want to proceed if older than 4.7.2. }
{ Check .NET Framework version on startup, ask user if they want to proceed if older than 4.5.2. }
function InitializeSetup: Boolean;
begin
UpdatePath := ExpandConstant('{param:UPDATEPATH}')
ForceRedistPrompt := ExpandConstant('{param:PROMPTREDIST}')
VisitedTasksPage := False
if (TDGetNetFrameworkVersion() < 461808) and (MsgBox('{#MyAppName} requires .NET Framework 4.7.2 or newer,'+#13+#10+'please visit {#MyAppShortURL} for a download link.'+#13+#10+#13+#10'Do you want to proceed with the setup anyway?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDNO) then
if (TDGetNetFrameworkVersion() < 379893) and (MsgBox('{#MyAppName} requires .NET Framework 4.5.2 or newer,'+#13+#10+'please visit {#MyAppShortURL} for a download link.'+#13+#10+#13+#10'Do you want to proceed with the setup anyway?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDNO) then
begin
Result := False
Exit

View File

@@ -64,14 +64,14 @@ function TDGetNetFrameworkVersion: Cardinal; forward;
function TDIsVCMissing: Boolean; forward;
procedure TDInstallVCRedist; forward;
{ Check .NET Framework version on startup, ask user if they want to proceed if older than 4.7.2. }
{ Check .NET Framework version on startup, ask user if they want to proceed if older than 4.5.2. }
function InitializeSetup: Boolean;
begin
UpdatePath := ExpandConstant('{param:UPDATEPATH}')
ForceRedistPrompt := ExpandConstant('{param:PROMPTREDIST}')
VisitedTasksPage := False
if (TDGetNetFrameworkVersion() < 461808) and (MsgBox('{#MyAppName} requires .NET Framework 4.7.2 or newer,'+#13+#10+'please visit {#MyAppShortURL} for a download link.'+#13+#10+#13+#10'Do you want to proceed with the setup anyway?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDNO) then
if (TDGetNetFrameworkVersion() < 379893) and (MsgBox('{#MyAppName} requires .NET Framework 4.5.2 or newer,'+#13+#10+'please visit {#MyAppShortURL} for a download link.'+#13+#10+#13+#10'Do you want to proceed with the setup anyway?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDNO) then
begin
Result := False
Exit

View File

@@ -81,7 +81,7 @@ procedure TDExecuteFullDownload; forward;
var IsPortable: Boolean;
var UpdatePath: String;
{ Check .NET Framework version on startup, ask user if they want to proceed if older than 4.7.2. Prepare full download package if required. }
{ Check .NET Framework version on startup, ask user if they want to proceed if older than 4.5.2. Prepare full download package if required. }
function InitializeSetup: Boolean;
begin
IsPortable := ExpandConstant('{param:PORTABLE}') = '1'
@@ -99,7 +99,7 @@ begin
idpAddFile('https://github.com/{#MyAppPublisher}/{#MyAppName}/releases/download/'+TDGetAppVersionClean()+'/'+TDGetFullDownloadFileName(), ExpandConstant('{tmp}\{#MyAppName}.Full.exe'))
end;
if (TDGetNetFrameworkVersion() < 461808) and (MsgBox('{#MyAppName} requires .NET Framework 4.7.2 or newer,'+#13+#10+'please visit {#MyAppShortURL} for a download link.'+#13+#10+#13+#10'Do you want to proceed with the setup anyway?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDNO) then
if (TDGetNetFrameworkVersion() < 379893) and (MsgBox('{#MyAppName} requires .NET Framework 4.5.2 or newer,'+#13+#10+'please visit {#MyAppShortURL} for a download link.'+#13+#10+#13+#10'Do you want to proceed with the setup anyway?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDNO) then
begin
Result := False
Exit

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\..\packages\Microsoft.Net.Compilers.2.9.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\packages\Microsoft.Net.Compilers.2.9.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TweetLib.Communication</RootNamespace>
<AssemblyName>TweetLib.Communication</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
@@ -23,7 +23,7 @@
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>8.0</LangVersion>
<LangVersion>7</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
@@ -51,6 +51,6 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.2.9.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.2.9.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
</Project>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="3.0.0" targetFramework="net472" developmentDependency="true" />
<package id="Microsoft.Net.Compilers" version="2.9.0" targetFramework="net452" developmentDependency="true" />
</packages>

View File

@@ -1,28 +0,0 @@
using System;
using TweetLib.Core.Application;
namespace TweetLib.Core{
public sealed class App{
public static IAppErrorHandler ErrorHandler { get; private set; }
// Builder
public sealed class Builder{
public IAppErrorHandler? ErrorHandler { get; set; }
// Validation
internal void Initialize(){
App.ErrorHandler = Validate(ErrorHandler, nameof(ErrorHandler))!;
}
private T Validate<T>(T obj, string name){
if (obj == null){
throw new InvalidOperationException("Missing property " + name + " on the provided App.");
}
return obj;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More