コード例 #1
0
ファイル: WndPin.xaml.cs プロジェクト: qwandery/PNotes.NET
 private bool EnumWindowsProc(IntPtr hwnd, int lParam)
 {
     try
     {
         if (!PNInterop.IsWindowVisible(hwnd))
         {
             return(true);
         }
         var count = PNInterop.GetWindowTextLength(hwnd);
         if (count <= 0)
         {
             return(true);
         }
         var sb = new StringBuilder(count + 1);
         PNInterop.GetWindowText(hwnd, sb, count + 1);
         var sbClass = new StringBuilder(1024);
         PNInterop.GetClassName(hwnd, sbClass, sbClass.Capacity);
         m_Windows.Add(new PinWindow {
             ClassWnd = sbClass.ToString(), TextWnd = sb.ToString()
         });
         return(true);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return(false);
     }
 }
コード例 #2
0
 private bool importSearchProviders(string iniPath)
 {
     try
     {
         bool result = false;
         int  size   = 1024;
         var  buffer = new string(' ', size);
         while (PNInterop.GetPrivateProfileString("search_engines", null, null, buffer, size, iniPath) ==
                size - 2)
         {
             // loop until sufficient buffer size
             size  *= 2;
             buffer = new string(' ', size);
         }
         var names     = buffer.Split('\0');
         var keys      = names.Where(n => n.Trim().Length > 0);
         var sqlList   = new List <string>();
         var providers = new List <PNSearchProvider>();
         foreach (var key in keys)
         {
             var query = new StringBuilder(1024);
             while (
                 PNInterop.GetPrivateProfileStringByBuilder("search_engines", key, "", query, query.Capacity,
                                                            iniPath) == query.Capacity - 1)
             {
                 query.Capacity *= 2;
             }
             providers.Add(new PNSearchProvider {
                 Name = key, QueryString = query.ToString()
             });
             var sb = new StringBuilder();
             sb.Append("INSERT OR REPLACE INTO SEARCH_PROVIDERS (SP_NAME, SP_QUERY) VALUES(");
             sb.Append("'");
             sb.Append(key);
             sb.Append("', ");
             sb.Append("'");
             sb.Append(query);
             sb.Append("'");
             sb.Append(")");
             sqlList.Add(sb.ToString());
         }
         if (sqlList.Count > 0 && PNData.ExecuteTransactionForList(sqlList, PNData.ConnectionString))
         {
             result = true;
             foreach (var prv in providers)
             {
                 PNStatic.SearchProviders.RemoveAll(pr => pr.Name == prv.Name);
                 PNStatic.SearchProviders.Add(prv);
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return(false);
     }
 }
コード例 #3
0
ファイル: WndPin.xaml.cs プロジェクト: qwandery/PNotes.NET
 private void DlgPin_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         PNLang.Instance.ApplyControlLanguage(this);
         Title += @" [" + m_NoteName + @"]";
         PNInterop.EnumWindowsProcDelegate enumProc = EnumWindowsProc;
         PNInterop.EnumWindows(enumProc, 0);
         grdWindows.ItemsSource = m_Windows;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
コード例 #4
0
        private void popComps_Opened(object sender, EventArgs e)
        {
            try
            {
                lstComps.Items.Clear();
                var comps = PNInterop.GetNetworkComputers();
                foreach (var c in comps)
                {
                    var st = new StackPanel {
                        Orientation = Orientation.Horizontal
                    };
                    var img = new Image
                    {
                        Source            = TryFindResource("computer") as BitmapImage,//new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "computer.png")),
                        Margin            = new Thickness(4),
                        Stretch           = Stretch.None,
                        VerticalAlignment = VerticalAlignment.Center
                    };

                    var tb = new TextBlock
                    {
                        Text = c,
                        VerticalAlignment = VerticalAlignment.Center,
                        Margin            = new Thickness(4)
                    };
                    st.Children.Add(img);
                    st.Children.Add(tb);
                    lstComps.Items.Add(st);
                }
                lstComps.Focus();
                if (string.IsNullOrWhiteSpace(txtCompName.Text))
                {
                    return;
                }
                foreach (
                    var st in
                    lstComps.Items.OfType <StackPanel>()
                    .Where(st => st.Children.OfType <TextBlock>().Any(tb => tb.Text == txtCompName.Text)))
                {
                    lstComps.SelectedItem = st;
                    return;
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
コード例 #5
0
        internal static ImageSource ToImageSource(this Icon icon)
        {
            var bitmap  = icon.ToBitmap();
            var hBitmap = bitmap.GetHbitmap();

            ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(
                hBitmap,
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            if (!PNInterop.DeleteObject(hBitmap))
            {
                throw new Win32Exception();
            }

            return(wpfBitmap);
        }
コード例 #6
0
 private bool importTags(string iniPath)
 {
     try
     {
         var result = false;
         var tags   = new StringBuilder(1024);
         while (
             PNInterop.GetPrivateProfileStringByBuilder("tags_pre", "tags", "", tags, tags.Capacity, iniPath) ==
             tags.Capacity - 1)
         {
             tags.Capacity *= 2;
         }
         if (tags.Length > 0)
         {
             var arr     = tags.ToString().Split(',');
             var listSql = new List <string>();
             foreach (var tag in arr)
             {
                 var sb = new StringBuilder();
                 sb.Append("INSERT OR REPLACE INTO TAGS (TAG) VALUES('");
                 sb.Append(tag);
                 sb.Append("')");
                 listSql.Add(sb.ToString());
             }
             if (PNData.ExecuteTransactionForList(listSql, PNData.ConnectionString))
             {
                 result = true;
                 foreach (string tag in arr)
                 {
                     if (!PNStatic.Tags.Contains(tag))
                     {
                         PNStatic.Tags.Add(tag);
                     }
                 }
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return(false);
     }
 }
コード例 #7
0
        void Reposition()
        {
            //release DispatcherOperation
            _repositionCallback = null;
            //get WPF Window location
            var translatePoint = _PlacementTarget.TranslatePoint(new Point(), _WpfWindow);
            //get size of placement target
            var translateSize = new Point(_PlacementTarget.ActualWidth, _PlacementTarget.ActualHeight);
            //get HwndSource of WPF Window
            var hwndSource = (HwndSource)PresentationSource.FromVisual(_WpfWindow);

            if (hwndSource == null)
            {
                return;
            }
            //get the visual manager of target window
            CompositionTarget ct = hwndSource.CompositionTarget;

            if (ct == null)
            {
                return;
            }
            //transform location and size
            translatePoint = ct.TransformToDevice.Transform(translatePoint);
            translateSize  = ct.TransformToDevice.Transform(translateSize);

            var screenLocation = new PNInterop.POINTINT(translatePoint);

            PNInterop.ClientToScreen(hwndSource.Handle, ref screenLocation);
            var screenSize = new PNInterop.POINTINT(translateSize);

            //move WinForm
            PNInterop.MoveWindow(_WinForm.Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
            if (EditControlSizeChanged != null)
            {
                //raise EditControlSizeChanged event providing new PNRichEditBox size
                EditControlSizeChanged(this,
                                       new EditControlSizeChangedEventArgs(new Rectangle(new System.Drawing.Point(0, 0),
                                                                                         _EditBox.Size)));
            }
        }
コード例 #8
0
 private bool importExternals(string iniPath)
 {
     try
     {
         var result = false;
         var size   = 1024;
         var buffer = new string(' ', size);
         while (PNInterop.GetPrivateProfileString("external_programs", null, null, buffer, size, iniPath) ==
                size - 2)
         {
             // loop until sufficient buffer size
             size  *= 2;
             buffer = new string(' ', size);
         }
         var names     = buffer.Split('\0');
         var keys      = names.Where(n => n.Trim().Length > 0);
         var listSql   = new List <string>();
         var externals = new List <PNExternal>();
         foreach (string key in keys)
         {
             var prog = new StringBuilder(1024);
             while (
                 PNInterop.GetPrivateProfileStringByBuilder("external_programs", key, "", prog, prog.Capacity,
                                                            iniPath) == prog.Capacity - 1)
             {
                 prog.Capacity *= 2;
             }
             var data = prog.ToString().Split((char)1);
             var ext  = new PNExternal {
                 Name = key, Program = data[0]
             };
             var sb = new StringBuilder();
             sb.Append("INSERT OR REPLACE INTO EXTERNALS (EXT_NAME, PROGRAM, COMMAND_LINE) VALUES(");
             sb.Append("'");
             sb.Append(key);
             sb.Append("', ");
             sb.Append("'");
             sb.Append(data[0]);
             sb.Append("', ");
             sb.Append("'");
             if (data.Length == 2)
             {
                 sb.Append(data[1]);
                 ext.CommandLine = data[1];
             }
             sb.Append("'");
             sb.Append(")");
             listSql.Add(sb.ToString());
             externals.Add(ext);
         }
         if (listSql.Count > 0 && PNData.ExecuteTransactionForList(listSql, PNData.ConnectionString))
         {
             result = true;
             foreach (PNExternal ext in externals)
             {
                 PNStatic.Externals.RemoveAll(ex => ex.Name == ext.Name);
                 PNStatic.Externals.Add(ext);
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return(false);
     }
 }
コード例 #9
0
 private bool importContacts(string iniPath)
 {
     try
     {
         var result = false;
         var size   = 1024;
         var buffer = new string(' ', size);
         while (PNInterop.GetPrivateProfileString("contacts", null, null, buffer, size, iniPath) == size - 2)
         {
             // loop until sufficient buffer size
             size  *= 2;
             buffer = new string(' ', size);
         }
         var names    = buffer.Split('\0');
         var keys     = names.Where(n => n.Trim().Length > 0);
         var sqlList  = new List <string>();
         var contacts = new List <PNContact>();
         int tempID   = 0;
         if (PNStatic.Contacts.Count > 0)
         {
             tempID = PNStatic.Contacts.Max(c => c.ID) + 1;
         }
         foreach (var key in keys)
         {
             var cont = new PCONTPROP();
             cont = PNInterop.ReadINIStructure(iniPath, "contacts", key, cont);
             if (cont.name != null && cont.name.Trim().Length > 0)
             {
                 var pnc = new PNContact
                 {
                     ComputerName    = cont.host,
                     GroupID         = cont.group,
                     Name            = cont.name,
                     UseComputerName = cont.usename
                 };
                 if (cont.address != 0)
                 {
                     pnc.IpAddress = buildAddressString(cont.address);
                 }
                 var temp = PNStatic.Contacts.FirstOrDefault(c => c.Name == pnc.Name);
                 pnc.ID = temp != null ? temp.ID : tempID++;
                 contacts.Add(pnc);
             }
         }
         // get contact froups
         size   = 1024;
         buffer = new string(' ', size);
         while (PNInterop.GetPrivateProfileString("cont_groups", null, null, buffer, size, iniPath) == size - 2)
         {
             // loop until sufficient buffer size
             size  *= 2;
             buffer = new string(' ', size);
         }
         names = buffer.Split('\0');
         keys  = names.Where(n => n.Trim().Length > 0);
         var groups = new List <PNContactGroup>();
         tempID = 0;
         if (PNStatic.ContactGroups.Count > 0)
         {
             tempID = PNStatic.ContactGroups.Max(g => g.ID) + 1;
         }
         foreach (var key in keys)
         {
             var grp = new PCONTGROUP();
             grp = PNInterop.ReadINIStructure(iniPath, "cont_groups", key, grp);
             if (grp.name == null || grp.name.Trim().Length <= 0)
             {
                 continue;
             }
             var pg = new PNContactGroup {
                 Name = grp.name
             };
             var temp = PNStatic.ContactGroups.FirstOrDefault(g => g.Name == grp.name);
             pg.ID = temp != null ? temp.ID : tempID++;
             groups.Add(pg);
         }
         // build sql
         foreach (var pg in groups)
         {
             var sb = new StringBuilder();
             sb.Append("INSERT OR REPLACE INTO CONTACT_GROUPS (ID, GROUP_NAME) VALUES(");
             sb.Append(pg.ID);
             sb.Append(", '");
             sb.Append(pg.Name);
             sb.Append("')");
             sqlList.Add(sb.ToString());
         }
         foreach (var pc in contacts)
         {
             var sb = new StringBuilder();
             sb.Append(
                 "INSERT OR REPLACE INTO CONTACTS (ID, GROUP_ID, CONTACT_NAME, COMP_NAME, IP_ADDRESS, USE_COMP_NAME) VALUES(");
             sb.Append(pc.ID);
             sb.Append(", ");
             sb.Append(pc.GroupID);
             sb.Append(", '");
             sb.Append(pc.Name);
             sb.Append("', '");
             sb.Append(pc.ComputerName);
             sb.Append("', '");
             sb.Append(pc.IpAddress);
             sb.Append("', ");
             sb.Append(Convert.ToInt32(pc.UseComputerName));
             sb.Append(")");
             sqlList.Add(sb.ToString());
         }
         if (sqlList.Count > 0 && PNData.ExecuteTransactionForList(sqlList, PNData.ConnectionString))
         {
             result = true;
             foreach (PNContactGroup pg in groups)
             {
                 PNStatic.ContactGroups.RemoveAll(g => g.Name == pg.Name);
                 PNStatic.ContactGroups.Add(pg);
             }
             foreach (PNContact pc in contacts)
             {
                 PNStatic.Contacts.RemoveAll(c => c.Name == pc.Name);
                 PNStatic.Contacts.Add(pc);
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return(false);
     }
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: qwandery/PNotes.NET
        private static bool enumAllWindowsProc(IntPtr hwnd, int msg)
        {
            try
            {
                var sb = new StringBuilder(256);

                PNInterop.GetWindowText(hwnd, sb, 256);
                if (sb.Length > 0 && sb.ToString() == "PNotes.NET Main Window")
                {
                    if (msg == PNInterop.WM_COPYDATA)
                    {
                        var cpdata = new PNInterop.COPYDATASTRUCT {
                            dwData = new IntPtr((int)_copyDataType)
                        };
                        var data = new StringBuilder();
                        switch (_copyDataType)
                        {
                        case CopyDataType.NewNote:
                            cpdata.cbData = Encoding.Default.GetBytes(_newNoteString).Count() +
                                            Encoding.Default.GetBytes(_newNoteName).Count() +
                                            Encoding.Default.GetBytes(_newNoteTags).Count() + 3;
                            data.Append(_newNoteString);
                            data.Append(PNStrings.DEL_CHAR);
                            data.Append(_newNoteName);
                            data.Append(PNStrings.DEL_CHAR);
                            data.Append(_newNoteTags);
                            break;

                        case CopyDataType.LoadNotes:
                            foreach (var f in _FilesToLoad)
                            {
                                cpdata.cbData += Encoding.Default.GetBytes(f).Count() + 1;
                                data.Append(f);
                                data.Append(PNStrings.DEL_CHAR);
                            }
                            if (data.Length > 0)
                            {
                                data = data.Remove(data.Length - 1, 1);
                            }
                            break;

                        case CopyDataType.ShowNoteById:
                            cpdata.cbData = Encoding.Default.GetBytes(_idToShow).Count();
                            data.Append(_idToShow);
                            break;
                        }
                        cpdata.lpData = data.ToString();
                        PNInterop.SendMessageCopyData(hwnd, (uint)msg, IntPtr.Zero, ref cpdata);
                    }
                    else
                    {
                        PNInterop.SendMessage(hwnd, (uint)msg, 0, 0);
                    }
                    _mainWindowExists = true;
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return(false);
            }
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: qwandery/PNotes.NET
        private static void Main()
        {
            try
            {
                var nonetwork = false;
                var nosplash  = false;
                var args      = Environment.GetCommandLineArgs();

                PNStatic.CultureInvariant = (CultureInfo)CultureInfo.InvariantCulture.Clone();
                PNStatic.CultureInvariant.NumberFormat.NumberDecimalSeparator = ".";

                var currentDomain = AppDomain.CurrentDomain;
                currentDomain.UnhandledException += currentDomain_UnhandledException;
                checkPreRun();

                if (args.Length > 1)
                {
                    switch (args[1])
                    {
                    case "-x":
                        PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WPM_CLOSE_PROG);
                        return;

                    case "-xs":
                        PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WPM_CLOSE_SILENT_SAVE);
                        return;

                    case "-xn":
                        PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WPM_CLOSE_SILENT_WO_SAVE);
                        return;

                    case "-c":
                        PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WPM_NEW_NOTE);
                        return;

                    case "-cr":
                        PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WPM_NEW_NOTE_FROM_CB);
                        return;

                    case "-cd":
                        PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WPM_NEW_DIARY);
                        return;

                    case "-cn":
                        if (args.Length > 2)
                        {
                            _newNoteString = args[2];
                        }
                        if (args.Length > 3)
                        {
                            _newNoteName = args[3];
                        }
                        if (args.Length > 4)
                        {
                            _newNoteTags = args[4];
                        }
                        _copyDataType = CopyDataType.NewNote;
                        PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WM_COPYDATA);
                        return;

                    case "-l":
                        if (args.Length > 2)
                        {
                            _FilesToLoad.AddRange(args.Skip(2));
                        }
                        _copyDataType = CopyDataType.LoadNotes;
                        PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WM_COPYDATA);
                        return;

                    case "-i":
                        if (args.Length > 2)
                        {
                            _idToShow = args[2];
                        }
                        _copyDataType = CopyDataType.ShowNoteById;
                        PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WM_COPYDATA);
                        if (_mainWindowExists)
                        {
                            //return if main window exists and program is already running
                            return;
                        }
                        //continue to start the program and add note's id to be proceeded later
                        PNSingleton.Instance.NoteFromShortcut = _idToShow;
                        break;

                    case "-r":
                        PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WPM_RELOAD_NOTES);
                        return;

                    case "-b":
                        if (args.Length >= 3)
                        {
                            var backFile = Path.Combine(args[2], DateTime.Now.ToString("yyyyMMddHHmmss") + PNStrings.FULL_BACK_EXTENSION);
                            PNStatic.CreateFullBackup(backFile);
                            return;
                        }
                        if (PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WPM_BACKUP))
                        {
                            // if no previos instance of PNotes is running - create backup at default directory and exit
                            var backFile = Path.Combine(PNPaths.Instance.BackupDir, DateTime.Now.ToString("yyyyMMddHHmmss") + PNStrings.FULL_BACK_EXTENSION);
                            PNStatic.CreateFullBackup(backFile);
                        }
                        return;

                    case "-nosplash":
                        if (isPrevInstance())
                        {
                            return;
                        }
                        nosplash = true;
                        break;

                    case "-nonetwork":
                        if (isPrevInstance())
                        {
                            return;
                        }
                        nonetwork = true;
                        if (args[args.Length - 1] == "nosplash")
                        {
                            nosplash = true;
                        }
                        break;

                    case "-updater":
                        if (args.Length == 3)
                        {
                            var updPath = args[2];
                            if (!string.IsNullOrEmpty(updPath))
                            {
                                var name = Path.GetFileName(updPath);
                                if (!string.IsNullOrEmpty(name))
                                {
                                    var localPath = Path.Combine(System.Windows.Forms.Application.StartupPath, name);
                                    if (File.Exists(updPath))
                                    {
                                        File.Copy(updPath, localPath, true);
                                        var dir = Path.GetDirectoryName(updPath);
                                        if (!string.IsNullOrEmpty(dir))
                                        {
                                            Directory.Delete(dir, true);
                                        }
                                    }
                                }
                            }
                        }
                        break;

                    case "-conf":
                    case "-config":
                    case "-confnonetwork":
                    case "-confignonetwork":
                        if (isPrevInstance())
                        {
                            return;
                        }
                        if (args.Length >= 3 && args[2].Trim().Length > 0)
                        {
                            PNPaths.Instance.SettingsDir = args[2];
                        }
                        if (args.Length >= 4 && args[3].Trim().Length > 0)
                        {
                            PNPaths.Instance.DataDir = args[3];
                        }
                        if (args.Length >= 5 && args[4].Trim().Length > 0)
                        {
                            PNPaths.Instance.SkinsDir = args[4];
                        }
                        if (args.Length >= 6 && args[5].Trim().Length > 0)
                        {
                            PNPaths.Instance.BackupDir = args[5];
                        }
                        if (args.Length >= 7 && args[6].Trim().Length > 0)
                        {
                            PNPaths.Instance.LangDir = args[6];
                        }
                        if (args.Length >= 8 && args[7].Trim().Length > 0)
                        {
                            PNPaths.Instance.SoundsDir = args[7];
                        }
                        if (args.Length >= 9 && args[8].Trim().Length > 0)
                        {
                            PNPaths.Instance.FontsDir = args[8];
                        }
                        if (args.Length >= 10 && args[9].Trim().Length > 0)
                        {
                            PNPaths.Instance.DictDir = args[9];
                        }
                        if (args.Length >= 11 && args[10].Trim().Length > 0)
                        {
                            PNPaths.Instance.PluginsDir = args[10];
                        }
                        if (args.Length >= 12 && args[11].Trim().Length > 0)
                        {
                            PNPaths.Instance.ThemesDir = args[11];
                        }
                        if (args[1] == "-confnonetwork" || args[1] == "-confignonetwork")
                        {
                            nonetwork = true;
                        }
                        if (args[args.Length - 1] == "nosplash")
                        {
                            nosplash = true;
                        }
                        break;

                    default:
                        if (args[1].StartsWith("/u"))
                        {
                            string[] pars = args[1].Split('=');
                            if (pars.Length == 2)
                            {
                                string guid = pars[1];
                                string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86),
                                                           "msiexec.exe");
                                var psi = new ProcessStartInfo(path, "/x " + guid);
                                Process.Start(psi);
                                return;
                            }
                        }
                        break;
                    }
                }

                if (!isPrevInstance())
                {
                    installFonts();
                    if (!nosplash && File.Exists(Path.Combine(PNPaths.Instance.DataDir, PNStrings.NOSPLASH)))
                    {
                        nosplash = true;
                    }
                    if (!nosplash)
                    {
                        PNStatic.SplashThread = new Thread(PNStatic.ShowSplash);
                        PNStatic.SplashThread.SetApartmentState(ApartmentState.STA);
                        PNStatic.SplashThread.Start();
                    }
                    PNStatic.StartProgram(nonetwork);

                    PNStatic.FormMain = new WndMain();
                    var app = new Application();

                    var res1 = new ResourceDictionary
                    {
                        Source = new Uri(@"/styles/Resources.xaml", UriKind.Relative)
                    };
                    var res2 = new ResourceDictionary
                    {
                        Source = new Uri(@"/styles/Images.xaml", UriKind.Relative)
                    };
                    var name        = res1["ThemeName"] as string;
                    var sampleImage = res2["sample"] as BitmapImage;
                    PNStatic.Themes.Add(name,
                                        Tuple.Create(new Uri(@"/styles/Resources.xaml", UriKind.Relative),
                                                     new Uri(@"/styles/Images.xaml", UriKind.Relative), sampleImage, "", new Version()));

                    loadThemes();

                    app.Resources.MergedDictionaries.Add(res1);
                    app.Resources.MergedDictionaries.Add(res2);
                    app.Resources.MergedDictionaries.Add(new ResourceDictionary
                    {
                        Source = new Uri(@"/styles/Styles.xaml", UriKind.Relative)
                    });
                    app.Resources.MergedDictionaries.Add(new ResourceDictionary
                    {
                        Source = new Uri(@"/Themes/generic.xaml", UriKind.Relative)
                    });

                    PNStatic.ApplyTheme(PNStatic.Settings.Behavior.Theme);

                    app.Run(PNStatic.FormMain);

                    if (PNStatic.Settings != null)
                    {
                        PNStatic.Settings.Dispose();
                    }
                    if (PNSingleton.Instance.Restart)
                    {
                        System.Windows.Forms.Application.Restart();
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(PNSingleton.Instance.UpdaterCommandLine))
                        {
                            var psi = new ProcessStartInfo
                            {
                                FileName        = Path.Combine(System.Windows.Forms.Application.StartupPath, "PNUpdater.exe"),
                                Arguments       = PNSingleton.Instance.UpdaterCommandLine,
                                UseShellExecute = true
                            };
                            var prc = new Process {
                                StartInfo = psi
                            };
                            prc.Start();
                        }
                    }
                }
                else
                {
                    PNInterop.EnumWindows(enumAllWindowsProc, PNInterop.WPM_START_FROM_ANOTHER_INSTANCE);
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }