public IEnumerable <System.Globalization.CultureInfo> GetAvailableCultures(Type type) { List <System.Globalization.CultureInfo> result = new List <System.Globalization.CultureInfo>(); var rm = new System.Resources.ResourceManager(type); System.Globalization.CultureInfo[] cultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures); foreach (System.Globalization.CultureInfo culture in cultures) { try { if (culture.Equals(System.Globalization.CultureInfo.InvariantCulture)) { continue; //do not use "==", won't work } var rs = rm.GetResourceSet(culture, true, false); if (rs != null) { result.Add(culture); } } catch (System.Globalization.CultureNotFoundException) { //NOP } rm.ReleaseAllResources(); } return(result); }
public override void OnPageShown() { if (EnvUtils.RunningOnWindows()) { System.Resources.ResourceManager rm = new System.Resources.ResourceManager("GitUI.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); // dummy request; for some strange reason the ResourceSets are not loaded untill after the first object request... bug? rm.GetObject("dummy"); System.Resources.ResourceSet resourceSet = rm.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true); contextMenuStrip_SplitButton.Items.Clear(); foreach (System.Collections.DictionaryEntry icon in resourceSet) { //add entry to toolstrip if (icon.Value.GetType() == typeof(Icon)) { //contextMenuStrip_SplitButton.Items.Add(icon.Key.ToString(), (Image)((Icon)icon.Value).ToBitmap(), SplitButtonMenuItem_Click); } else if (icon.Value.GetType() == typeof(Bitmap)) { contextMenuStrip_SplitButton.Items.Add(icon.Key.ToString(), (Image)icon.Value, SplitButtonMenuItem_Click); } //var aa = icon.Value.GetType(); } resourceSet.Close(); rm.ReleaseAllResources(); } }
public override void OnPageShown() { if (Settings.RunningOnWindows()) { System.Resources.ResourceManager rm = new System.Resources.ResourceManager("GitUI.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); // dummy request; for some strange reason the ResourceSets are not loaded untill after the first object request... bug? rm.GetObject("dummy"); System.Resources.ResourceSet resourceSet = rm.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true); contextMenuStrip_SplitButton.Items.Clear(); foreach (System.Collections.DictionaryEntry icon in resourceSet) { //add entry to toolstrip if (icon.Value.GetType() == typeof(Icon)) { //contextMenuStrip_SplitButton.Items.Add(icon.Key.ToString(), (Image)((Icon)icon.Value).ToBitmap(), SplitButtonMenuItem_Click); } else if (icon.Value.GetType() == typeof(Bitmap)) { contextMenuStrip_SplitButton.Items.Add(icon.Key.ToString(), (Image)icon.Value, SplitButtonMenuItem_Click); } //var aa = icon.Value.GetType(); } resourceSet.Close(); rm.ReleaseAllResources(); } }
public static bool Exists(string path) { if (string.IsNullOrEmpty(path) || path.Length <= _resourceFilePrefix.Length) return false; path = path.Substring(_resourceFilePrefix.Length).ToLower(); if(_resourcePath==null) { _resourcePath = new Dictionary<string, string>(); var culture = System.Threading.Thread.CurrentThread.CurrentCulture; var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var resourceName = assembly.GetName().Name + ".g"; var resourceManager = new System.Resources.ResourceManager(resourceName, assembly); try { var resourceSet = resourceManager.GetResourceSet(culture, true, true); foreach (System.Collections.DictionaryEntry resource in resourceSet) { _resourcePath.Add(resource.Key.ToString(), ""); } } finally { resourceManager.ReleaseAllResources(); } } return _resourcePath.ContainsKey(path); }
public override void OnPageShown() { if (!EnvUtils.RunningOnWindows()) { return; } var rm = new System.Resources.ResourceManager("GitUI.Properties.Images", Assembly.GetExecutingAssembly()); // dummy request; for some strange reason the ResourceSets are not loaded untill after the first object request... bug? rm.GetObject("dummy"); using System.Resources.ResourceSet resourceSet = rm.GetResourceSet(CultureInfo.CurrentUICulture, true, true); foreach (DictionaryEntry icon in resourceSet.Cast <DictionaryEntry>().OrderBy(icon => icon.Key)) { if (icon.Value is Bitmap bitmap) { EmbeddedIcons.Images.Add(icon.Key.ToString(), bitmap.AdaptLightness()); } } resourceSet.Close(); rm.ReleaseAllResources(); lvScripts.LargeImageList = lvScripts.SmallImageList = EmbeddedIcons; _imagsLoaded = true; if (_scripts is object) { BindScripts(_scripts, null); } }
public static bool Exists(string path) { if (string.IsNullOrEmpty(path) || path.Length <= _resourceFilePrefix.Length) { return(false); } path = path.Substring(_resourceFilePrefix.Length).ToLower(); if (_resourcePath == null) { _resourcePath = new Dictionary <string, string>(); var culture = System.Threading.Thread.CurrentThread.CurrentCulture; var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var resourceName = assembly.GetName().Name + ".g"; var resourceManager = new System.Resources.ResourceManager(resourceName, assembly); try { var resourceSet = resourceManager.GetResourceSet(culture, true, true); foreach (System.Collections.DictionaryEntry resource in resourceSet) { _resourcePath.Add(resource.Key.ToString(), ""); } } finally { resourceManager.ReleaseAllResources(); } } return(_resourcePath.ContainsKey(path)); }
/// <summary> /// リソースを解放する /// </summary> internal static void ReleaseResources() { lock (locker) { foreach (Type key in _MessageResSet.Keys) { System.Resources.ResourceManager manager = _MessageResSet[key]; if (manager != null) { manager.ReleaseAllResources(); } } _MessageResSet.Clear(); } }
/// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } //释放所有资源 _ownerResource.ReleaseAllResources(); //释放基类中的资源 base.Dispose(disposing); }
private string GetImage() { System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); System.Globalization.CultureInfo culture = Thread.CurrentThread.CurrentCulture; string resourceName = asm.GetName().Name + ".g"; System.Resources.ResourceManager rm = new System.Resources.ResourceManager(resourceName, asm); System.Resources.ResourceSet resourceSet = rm.GetResourceSet(culture, true, true); List<string> resources = new List<string>(); foreach (DictionaryEntry resource in resourceSet) { if(((string)resource.Key).StartsWith("images/splash%20screens/")) resources.Add((string)resource.Key); } rm.ReleaseAllResources(); Random r = new Random(); int i = r.Next(0, resources.Count()); return resources[i]; }
public static List <string> GetImageListFromDLL(string assemblyName) { Assembly asm = Assembly.LoadFrom(assemblyName + (assemblyName.Contains(".dll") ? "" : ".dll")); System.Globalization.CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentCulture; string resourceName = asm.GetName().Name + ".g"; System.Resources.ResourceManager rm = new System.Resources.ResourceManager(resourceName, asm); System.Resources.ResourceSet resourceSet = rm.GetResourceSet(culture, true, true); List <string> resources = new List <string>(); foreach (System.Collections.DictionaryEntry resource in resourceSet) { resources.Add((string)resource.Key); } rm.ReleaseAllResources(); return(resources); }
public static void LoadDLLResources() { try { Assembly myAssembly = Assembly.Load("UniGitResources"); var rc = new System.Resources.ResourceManager("UniGitResources.Properties.Resources", myAssembly); foreach (DictionaryEntry e in rc.GetResourceSet(CultureInfo.InvariantCulture, true, true)) { if (e.Value.GetType().Name == "Bitmap") { textures.Add((string)e.Key, LoadTextureFromBitmap((string)e.Key, e.Value)); } } rc.ReleaseAllResources(); } catch (Exception e) { Debug.LogException(e); } }
public static IEnumerable <object> GetResourcePaths(Assembly assembly) { var culture = System.Threading.Thread.CurrentThread.CurrentCulture; var resourceName = assembly.GetName().Name + ".g"; var resourceManager = new System.Resources.ResourceManager(resourceName, assembly); try { var resourceSet = resourceManager.GetResourceSet(culture, true, true); foreach (System.Collections.DictionaryEntry resource in resourceSet) { yield return(resource.Key); } } finally { resourceManager.ReleaseAllResources(); } }
private string GetImage() { System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); System.Globalization.CultureInfo culture = Thread.CurrentThread.CurrentCulture; string resourceName = asm.GetName().Name + ".g"; System.Resources.ResourceManager rm = new System.Resources.ResourceManager(resourceName, asm); System.Resources.ResourceSet resourceSet = rm.GetResourceSet(culture, true, true); List <string> resources = new List <string>(); foreach (DictionaryEntry resource in resourceSet) { if (((string)resource.Key).StartsWith("images/splash%20screens/")) { resources.Add((string)resource.Key); } } rm.ReleaseAllResources(); Random r = new Random(); int i = r.Next(0, resources.Count()); return(resources[i]); }
private void App_Startup(object sender, StartupEventArgs e) { try { //localization var culture = System.Globalization.CultureInfo.CurrentCulture; if (culture.TwoLetterISOLanguageName != @"en") { var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var resourceName = assembly.GetName().Name + ".g"; var resourceManager = new System.Resources.ResourceManager(resourceName, assembly); try { var resourceSet = resourceManager.GetResourceSet(culture, true, true); if (resourceSet.Cast <System.Collections.DictionaryEntry>() .Any(entry => (string)entry.Key == $@"resources/localization.{culture.TwoLetterISOLanguageName}.baml")) { Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri($@"Resources\Localization.{culture.TwoLetterISOLanguageName}.xaml", UriKind.Relative) }); } } finally { resourceManager.ReleaseAllResources(); } } //handle immersion mode change Setting.StaticPropertyChanged += Setting_StaticPropertyChanged; //get supported extensions foreach (var ext in RegistryHelpers.GetWICDecoders().Select(s => s.ToLowerInvariant())) { if (!ImageExtensions.Contains(ext)) { ImageExtensions.Add(ext); } } //set working directory Directory.SetCurrentDirectory(ExeDir); //load config Setting.LoadConfigFromFile(); //create resources var fa_brush = new SolidColorBrush(Color.FromArgb(40, 255, 255, 255)); fa_meh = GetFaIcon(EFontAwesomeIcon.Solid_Meh, fa_brush); fa_spinner = GetFaIcon(EFontAwesomeIcon.Solid_Spinner, fa_brush); fa_exclamation = GetFaIcon(EFontAwesomeIcon.Solid_ExclamationCircle, fa_brush); fa_file = GetFaIcon(EFontAwesomeIcon.Solid_File, fa_brush); fa_folder = GetFaIcon(EFontAwesomeIcon.Solid_Folder, fa_brush); fa_archive = GetFaIcon(EFontAwesomeIcon.Solid_FileArchive, fa_brush); fa_image = GetFaIcon(EFontAwesomeIcon.Solid_FileImage, fa_brush); //make sure thumbs db is correct CheckThumbsDB(); //check args if (e.Args?.Length > 0) { #if DEBUG if (e.Args.Contains("-cleandb")) { Execute(Table.Thumbs, (table, con) => { using (var cmd = new SQLiteCommand(con)) { cmd.CommandText = $@"delete from {table.Name}"; cmd.ExecuteNonQuery(); cmd.CommandText = @"vacuum"; cmd.ExecuteNonQuery(); } return(0); }); } #endif try { //use the last arg as path var path = e.Args[e.Args.Length - 1]; var objInfo = new ObjectInfo(path, GetPathType(path)); if (e.Args.Contains("-slideshow")) { new SlideshowWindow(objInfo.ContainerPath).Show(); return; } else { switch (objInfo.Flags) { case FileFlags.Image: new ViewWindow(objInfo.ContainerPath, objInfo.FileName).Show(); return; default: new MainWindow() { InitialPath = objInfo.ContainerPath }.Show(); return; } } } catch (Exception ex) { MessageBox.Show(ex.Message, GetRes("ttl_ParamStartError"), MessageBoxButton.OK, MessageBoxImage.Error); } } //show mainwindow if no cmdline args new MainWindow().Show(); //check for updates Task.Run(() => { var _ = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; var localVer = new Version(_.Major, _.Minor, _.Build); var req = (HttpWebRequest)WebRequest.Create(@"https://api.github.com/repos/changbowen/zipimageviewer/releases/latest"); req.ContentType = @"application/json; charset=utf-8"; req.UserAgent = nameof(ZipImageViewer); try { using (var res = req.GetResponse() as HttpWebResponse) using (var stream = res.GetResponseStream()) using (var reader = new StreamReader(stream, System.Text.Encoding.UTF8)) { var jObj = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadToEnd()); string tag_name = @"tag_name"; if (!jObj.ContainsKey(tag_name)) { return; } _ = Version.Parse(jObj[tag_name].ToString().TrimStart('v')); var remoteVer = new Version(_.Major, _.Minor, _.Build); if (localVer < remoteVer && MessageBox.Show(GetRes(@"msg_NewVersionPrompt", localVer.ToString(3), remoteVer.ToString(3)), string.Empty, MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK) { Helpers.Run(@"explorer", @"https://github.com/changbowen/ZipImageViewer/releases"); } } } catch { } }); } catch (Exception ex) { MessageBox.Show(ex.Message, GetRes("ttl_AppStartError"), MessageBoxButton.OK, MessageBoxImage.Error); Current.Shutdown(); } }
private void RunCheck(object sender1, StartupEventArgs e1) { //check if app is already running if (SingleInstance.CheckExist(MutexString, ref mtx)) { SingleInstance.SendNotifyMessage(SingleInstance.HWND_BROADCAST, SingleInstance.RegisteredWM, IntPtr.Zero, IntPtr.Zero); Current.Shutdown(); return; } AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs e) => { var desiredAssembly = new System.Reflection.AssemblyName(e.Name).Name; switch (desiredAssembly) { case "Xceed.Wpf.Toolkit": case "Hardcodet.Wpf.TaskbarNotification": var ressourceName = "DesktopNote.Resources." + desiredAssembly + ".dll"; using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(ressourceName)) { byte[] assemblyData = new byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return(System.Reflection.Assembly.Load(assemblyData)); } default: return(null); } }; //localization var lang = System.Threading.Thread.CurrentThread.CurrentCulture.Name.Substring(0, 2); //check if stringresources.lang exist bool langadded = false; var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var resourceName = assembly.GetName().Name + ".g"; var resourceManager = new System.Resources.ResourceManager(resourceName, assembly); try { var resourceSet = resourceManager.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true); foreach (System.Collections.DictionaryEntry resource in resourceSet) { if ((string)resource.Key == @"resources/stringresources." + lang + ".baml") { var dict = new ResourceDictionary { Source = new Uri(@"Resources\StringResources." + lang + ".xaml", UriKind.Relative) }; Resources.MergedDictionaries.Add(dict); langadded = true; break; } } } finally { resourceManager.ReleaseAllResources(); } //set english as fallback language if (!langadded) { Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(@"Resources\StringResources.en.xaml", UriKind.Relative) }); } //other run checks if (PathIsNetworkPath(AppDomain.CurrentDomain.BaseDirectory)) { Helpers.MsgBox("msgbox_run_from_network", button: MessageBoxButton.OK, image: MessageBoxImage.Exclamation); Current.Shutdown(); return; } Res = Current.Resources; //load notes foreach (var path in Setting.NoteList.Cast <string>().ToArray()) { Helpers.OpenNote(path)?.Show(); } if (MainWindows.Count == 0) { Helpers.NewNote(); } }