initial commit

This commit is contained in:
i2p
2026-08-27 11:22:54 -06:00
commit 3d81b11e14
2281 changed files with 54227 additions and 0 deletions
@@ -0,0 +1,37 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Crysome.Server.Converters;
public class BooleanToVisibilityConverter : IValueConverter
{
public bool Invert { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool flag = default(bool);
int num;
if (value is bool)
{
flag = (bool)value;
num = 1;
}
else
{
num = 0;
}
bool flag2 = (byte)((uint)num & (flag ? 1u : 0u)) != 0;
if (Invert)
{
flag2 = !flag2;
}
return (!flag2) ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
@@ -0,0 +1,39 @@
using System;
using System.Globalization;
using System.IO;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace Crysome.Server.Converters;
[ValueConversion(typeof(byte[]), typeof(BitmapImage))]
public class ByteArrayToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is byte[] array) || array.Length == 0)
{
return null;
}
try
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(array);
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
((Freezable)bitmapImage).Freeze();
return bitmapImage;
}
catch
{
return null;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
@@ -0,0 +1,42 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Crysome.Common.Model;
namespace Crysome.Server.Converters;
public class FileSizeConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
long num = (long)values[0];
if ((int)(FileType)values[1] == 0)
{
return "-";
}
string text = "bytes";
long num2 = num;
if (num >= 1000)
{
text = "KB";
num2 = num / 1024;
}
if (num >= 1000000)
{
text = "MB";
num2 = num / 1048576;
}
if (num >= 1000000000)
{
text = "GB";
num2 = num / 1073741824;
}
return num2 + " " + text;
}
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
@@ -0,0 +1,27 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Crysome.Common.Model;
using Crysome.Server.Resources;
namespace Crysome.Server.Converters;
[ValueConversion(typeof(FileType), typeof(string))]
public class FileTypeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
if ((int)(FileType)value != 1)
{
return Strings.FileType_Folder;
}
return Strings.FileType_File;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (object)(FileType)(((string)value == Strings.FileType_File) ? 1 : 0);
}
}
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace Crysome.Server.Converters;
public class FlagConverter : IValueConverter
{
private static readonly Dictionary<string, BitmapImage> Cache = new Dictionary<string, BitmapImage>(StringComparer.OrdinalIgnoreCase);
private static bool _loaded;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
string text = value.ToString().Trim().ToUpperInvariant();
if (string.IsNullOrEmpty(text))
{
return null;
}
if (!_loaded)
{
LoadAll();
}
if (Cache.TryGetValue(text, out var value2))
{
return value2;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
private static void LoadAll()
{
_loaded = true;
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string[] array = new string[2]
{
Path.Combine(baseDirectory, "flags"),
baseDirectory
};
foreach (string path in array)
{
if (!Directory.Exists(path))
{
continue;
}
string[] files = Directory.GetFiles(path, "*.png");
foreach (string text in files)
{
try
{
string text2 = Path.GetFileNameWithoutExtension(text).ToUpperInvariant();
if (!text2.Contains("@") && text2.Length == 2 && !Cache.ContainsKey(text2))
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(text);
bitmapImage.DecodePixelHeight = 16;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
((Freezable)bitmapImage).Freeze();
Cache[text2] = bitmapImage;
}
}
catch
{
}
}
}
}
}
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using Crysome.Server.Model;
namespace Crysome.Server.Converters;
public class InventoryDotsCollapseConverter : IMultiValueConverter
{
private const int CollapsedCount = 4;
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null || values.Length < 2)
{
if (values == null)
{
return null;
}
return values[0];
}
IEnumerable<InventoryDot> enumerable = values[0] as IEnumerable<InventoryDot>;
object obj = values[1];
bool flag = default(bool);
int num;
if (obj is bool)
{
flag = (bool)obj;
num = 1;
}
else
{
num = 0;
}
bool flag2 = (byte)((uint)num & (flag ? 1u : 0u)) != 0;
if (enumerable == null)
{
return new List<InventoryDot>();
}
if (!flag2)
{
return enumerable.Take(4).ToList();
}
return enumerable;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
@@ -0,0 +1,35 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
namespace Crysome.Server.Converters;
[ValueConversion(typeof(bool), typeof(Color))]
public class InventoryPresentToColorConverter : IValueConverter
{
private static readonly Color Found = Color.FromRgb(111, 207, 151);
private static readonly Color Missing = Color.FromRgb(85, 85, 85);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool flag = default(bool);
int num;
if (value is bool)
{
flag = (bool)value;
num = 1;
}
else
{
num = 0;
}
return (((uint)num & (flag ? 1u : 0u)) != 0) ? Found : Missing;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
@@ -0,0 +1,29 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace Crysome.Server.Converters;
public class InventoryPresentToOpacityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool flag = default(bool);
int num;
if (value is bool)
{
flag = (bool)value;
num = 1;
}
else
{
num = 0;
}
return (((uint)num & (flag ? 1u : 0u)) != 0) ? 1.0 : 0.3;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace Crysome.Server.Converters;
public class OSIconConverter : IValueConverter
{
private static readonly Dictionary<string, BitmapImage> Cache = new Dictionary<string, BitmapImage>(StringComparer.OrdinalIgnoreCase);
private static bool _loaded;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
string text = value.ToString().Trim().ToLower();
if (string.IsNullOrEmpty(text))
{
return null;
}
if (!_loaded)
{
LoadAll();
}
if (text.Contains("windows 11") || text.Contains("server 2022"))
{
return GetCached("windows11");
}
if (text.Contains("windows 10") || text.Contains("server 2019") || text.Contains("server 2016"))
{
return GetCached("windows10");
}
if (text.Contains("8.1") || text.Contains("server 2012"))
{
return GetCached("windows81");
}
if (text.Contains("windows 8"))
{
return GetCached("windows81");
}
if (text.Contains("windows 7") || text.Contains("vista") || text.Contains("server 2008"))
{
return GetCached("windows7");
}
if (text.Contains("xp") || text.Contains("server 2003"))
{
return GetCached("windowsxp");
}
if (text.Contains("linux"))
{
return GetCached("linux");
}
if (text.Contains("windows"))
{
return GetCached("windows10");
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
private static BitmapImage GetCached(string key)
{
if (Cache.TryGetValue(key, out var value))
{
return value;
}
return null;
}
private static void LoadAll()
{
_loaded = true;
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string[] array = new string[2]
{
baseDirectory,
Path.Combine(baseDirectory, "icons")
};
string[] array2 = new string[6] { "windows7", "windows81", "windows10", "windows11", "windowsxp", "linux" };
string[] array3 = array;
foreach (string text in array3)
{
if (!Directory.Exists(text))
{
continue;
}
string[] array4 = array2;
foreach (string text2 in array4)
{
if (Cache.ContainsKey(text2))
{
continue;
}
string text3 = Path.Combine(text, text2 + ".png");
if (File.Exists(text3))
{
try
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(text3);
bitmapImage.DecodePixelHeight = 16;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
((Freezable)bitmapImage).Freeze();
Cache[text2] = bitmapImage;
}
catch
{
}
}
}
}
}
}
@@ -0,0 +1,19 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Crysome.Server.Converters;
public class StringToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return string.IsNullOrEmpty(value as string) ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}