Beispiel #1
0
        public void ShowDialog(params ProgressDialogBehavior[] flags)
        {
            if (_progressDialog != null)
            {
                return;
            }

            _progressDialog = new Win32ProgressDialog() as IProgressDialog;

            _progressDialog.SetTitle(_title);
            _progressDialog.SetCancelMsg(_cancelMessage, null);
            _progressDialog.SetLine(1, _line1, false, IntPtr.Zero);
            _progressDialog.SetLine(2, _line2, false, IntPtr.Zero);
            _progressDialog.SetLine(3, _line3, false, IntPtr.Zero);

            ProgressDialogBehavior dialogFlags = ProgressDialogBehavior.Normal;

            if (flags.Length != 0)
            {
                dialogFlags = flags[0];
                for (var i = 1; i < flags.Length; i++)
                {
                    dialogFlags = dialogFlags | flags[i];
                }
            }

            _progressDialog.StartProgressDialog(_parentHandle, null, dialogFlags, IntPtr.Zero);
        }
        public HRESULT CreatePlaylist(IShellItemArray psia)
        {
            _ppd = new IProgressDialog();
            _ppd.StartProgressDialog(dwFlags: PROGDLG.PROGDLG_AUTOTIME);
            _ppd.SetTitle("Building Playlist");
            _ppd.SetLine(1, "Finding music files...", false);

            var pnsw = new INamespaceWalk();

            pnsw.Walk(psia, NAMESPACEWALKFLAG.NSWF_TRAVERSE_STREAM_JUNCTIONS | NAMESPACEWALKFLAG.NSWF_DONT_ACCUMULATE_RESULT, 4, this);
            _fCountingFiles = false;
            _ppd.SetLine(1, "Adding files...", false);
            _pstm = _GetPlaylistStream();
            var hr = WriteHeader();

            if (hr.Succeeded)
            {
                pnsw.Walk(psia, NAMESPACEWALKFLAG.NSWF_TRAVERSE_STREAM_JUNCTIONS | NAMESPACEWALKFLAG.NSWF_DONT_ACCUMULATE_RESULT | NAMESPACEWALKFLAG.NSWF_SHOW_PROGRESS, 4, this);
                hr = WriteFooter();
            }

            _pstm.Commit(0);

            if (hr.Succeeded)
            {
                var psiCreated = _GetPlaylistItem <IShellItem>();
                hr = OpenFolderAndSelectItem(psiCreated);
            }
            _ppd.StopProgressDialog();
            _ExitMessageLoop();
            return(0);
        }
Beispiel #3
0
        public void ShowDialog(IWin32Window Parent, DialogFlags flags)
        {
            if (_ProgressDialog == null)
            {
                _ProgressDialog = (IProgressDialog) new ProgressDialogClass();

                _ProgressDialog.SetTitle(this._Title);
                _ProgressDialog.SetCancelMsg(this._CancelMessage, null);
                _ProgressDialog.SetLine(1, this._Line1, false, IntPtr.Zero);
                _ProgressDialog.SetLine(2, this._Line2, false, IntPtr.Zero);
                _ProgressDialog.SetLine(3, this._Line3, false, IntPtr.Zero);

                _ProgressDialog.StartProgressDialog(Parent.Handle, null, flags, IntPtr.Zero);
            }
        }
Beispiel #4
0
        private void updateTitleKeysToolStripMenuItem_Click(object sender, EventArgs e)
        {
            progressDialog = (IProgressDialog) new ProgressDialog();
            progressDialog.StartProgressDialog(Handle, "Downloading title keys");

            progressDialog.SetLine(2, String.Format("Downloading from {0}", Common.TITLE_KEYS_URI), true, IntPtr.Zero);

            int count = Process.keyset?.TitleKeys?.Count ?? 0;

            if (Process.updateTitleKeys())
            {
                Process.log?.WriteLine("\nFound {0} updated title keys", (Process.keyset?.TitleKeys?.Count ?? 0) - count);

                progressDialog.StopProgressDialog();
                Activate();

                MessageBox.Show(String.Format("Found {0} updated title keys", (Process.keyset?.TitleKeys?.Count ?? 0) - count), Application.ProductName);
            }
            else
            {
                progressDialog.StopProgressDialog();
                Activate();

                MessageBox.Show("Failed to download title keys", Application.ProductName);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Displays the progress dialog and starts the timer.
        /// </summary>
        /// <param name="parent">The dialog box's parent window.</param>
        public void Show(IWin32Window parent)
        {
            // Throw an exception if we are already running
            if (_state != ProgressDialogState.Stopped)
            {
                throw new InvalidOperationException("Timer is already running.");
            }

            // Get parent window handle
            if (parent == null)
            {
                parent = Form.ActiveForm;
            }
            IntPtr handle = (parent == null) ? IntPtr.Zero : parent.Handle;

            // Setup the window
            _nativeProgressDialog = (IProgressDialog)Activator.CreateInstance(_progressDialogType);
            _nativeProgressDialog.SetTitle(_title);
            _nativeProgressDialog.SetCancelMsg(_cancelMessage, null);
            if (ShowTimeRemaining)
            {
                _nativeProgressDialog.SetLine(3, "Estimating time remaining...", false, IntPtr.Zero);
            }

            // Create Window
            _nativeProgressDialog.StartProgressDialog(handle, null, _flags, IntPtr.Zero);

            _value = 0;
            _state = ProgressDialogState.Running;
            _nativeProgressDialog.Timer(PDTIMER.Reset, null);
        }
Beispiel #6
0
        internal static void StartProgressDialog(this IProgressDialog progressDialog, IntPtr hwndParent, string pwzString)
        {
            progressDialog.SetTitle(Application.ProductName);
            progressDialog.SetCancelMsg("Please wait until the current process is finished", IntPtr.Zero);
            progressDialog.SetLine(1, pwzString, false, IntPtr.Zero);

            progressDialog.StartProgressDialog(hwndParent, null, (uint)(IPD_Flags.Modal | IPD_Flags.AutoTime | IPD_Flags.NoMinimize), IntPtr.Zero);
            progressDialog.SetProgress(0, 100);
        }
Beispiel #7
0
        private void backgroundWorkerProcess_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (progressDialog.HasUserCancelled())
            {
                if (backgroundWorkerProcess.IsBusy)
                {
                    backgroundWorkerProcess.CancelAsync();
                }
            }

            if (e.ProgressPercentage == -1)
            {
                progressDialog.SetLine(1, e.UserState as string, false, IntPtr.Zero);
            }
            else
            {
                progressDialog.SetLine(2, e.UserState as string, true, IntPtr.Zero);
                progressDialog.SetProgress((uint)e.ProgressPercentage, 100);
            }
        }
Beispiel #8
0
        private void updateVersionListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            progressDialog = (IProgressDialog) new ProgressDialog();
            progressDialog.StartProgressDialog(Handle, "Downloading version list");

            progressDialog.SetLine(2, String.Format("Downloading from {0}", Common.TAGAYA_VERSIONLIST), true, IntPtr.Zero);

            if (Process.updateVersionList())
            {
                uint count = 0;

                foreach (var title in titles)
                {
                    if (title.type == TitleType.Application || title.type == TitleType.Patch)
                    {
                        if (Process.versionList.TryGetValue(title.titleIDApplication, out uint version))
                        {
                            if (title.latestVersion == unchecked ((uint)-1) || version > title.latestVersion)
                            {
                                title.latestVersion = version;
                                count++;
                            }
                        }
                    }
                }

                if (count != 0)
                {
                    reloadData();

                    Common.History.Default.Titles.Add(titles.ToList());
                    if (Common.History.Default.Titles.Count > Common.HISTORY_SIZE)
                    {
                        Common.History.Default.Titles.RemoveRange(0, Common.History.Default.Titles.Count - Common.HISTORY_SIZE);
                    }
                    Common.History.Default.Save();
                }

                Process.log?.WriteLine("\n{0} titles have updated version", count);

                progressDialog.StopProgressDialog();
                Activate();

                MessageBox.Show(String.Format("{0} titles have updated version", count), Application.ProductName);
            }
            else
            {
                progressDialog.StopProgressDialog();
                Activate();

                MessageBox.Show("Failed to download version list", Application.ProductName);
            }
        }
        /// <summary>
        /// Displays the progress dialog and starts the timer.
        /// </summary>
        /// <param name="parent">The dialog box's parent window.</param>
        public void Show(IWin32Window parent)
        {
            if (_state != ProgressDialogState.Stopped)
            {
                throw new InvalidOperationException("Timer is already running.");
            }

            if (parent == null)
            {
                parent = Form.ActiveForm;
            }
            IntPtr handle = (parent == null) ? IntPtr.Zero : parent.Handle;

            _nativeProgressDialog = (IProgressDialog)Activator.CreateInstance(_progressDialogType);
            _nativeProgressDialog.SetCancelMsg(_cancelMessage, null);
            if (ShowTimeRemaining)
            {
                _nativeProgressDialog.SetLine(3, "Estimating time remaining...", false, IntPtr.Zero);
            }
            //Temporary title for progressbar handler detection
            string guidTitle = Guid.NewGuid().ToString();

            _nativeProgressDialog.SetTitle(guidTitle);
            _nativeProgressDialog.StartProgressDialog(handle, null, _flags, IntPtr.Zero);
            //Workaround to manipulate progressbar style
            IntPtr handler = IntPtr.Zero;

            while (true)
            {
                handler = FindWindow(null, guidTitle);
                if (handler == IntPtr.Zero)
                {
                    Thread.Sleep(25);
                }
                else
                {
                    break;
                }
            }
            handler = FindWindowEx(handler, IntPtr.Zero, "DirectUIHWND", null);
            IntPtr childHandler = FindWindowEx(handler, IntPtr.Zero, "CtrlNotifySink", null);

            childHandler        = FindWindowEx(handler, childHandler, "CtrlNotifySink", null);
            childHandler        = FindWindowEx(handler, childHandler, "CtrlNotifySink", null);
            _progressBarHandler = FindWindowEx(childHandler, IntPtr.Zero, "msctls_progress32", null);
            //Real title
            _nativeProgressDialog.SetTitle(_title);
            _value = 0;
            _state = ProgressDialogState.Running;
            _nativeProgressDialog.Timer(PDTIMER.Reset, null);
        }
Beispiel #10
0
        public void InitTest()
        {
            var idlg = new IProgressDialog();

            idlg.SetTitle("Testing progress");
            idlg.SetCancelMsg("Don't like this?");
            idlg.SetLine(1, "Doing something really slow.", false);
            idlg.SetLine(2, @"C:\Users\you\Documents\GitHubRepos\Vanara\UnitTests\PInvoke\Shell32\ProgressDialogTests.cs", true);

            idlg.StartProgressDialog(IntPtr.Zero, null, PROGDLG.PROGDLG_AUTOTIME);
            var rnd = new Random();

            for (uint i = 0; i < 100; i++)
            {
                if (idlg.HasUserCancelled())
                {
                    break;
                }
                idlg.SetProgress(i, 100);
                Thread.Sleep(rnd.Next(50, 750));
            }
            idlg.StopProgressDialog();
        }
Beispiel #11
0
        public void reloadData()
        {
            uint index = 0, count = (uint)titles.Count;

            objectListView.SetObjects(titles);

            foreach (OLVListItem listItem in objectListView.Items)
            {
                Title title = listItem.RowObject as Title;

                progressDialog?.SetLine(2, title.titleName, true, IntPtr.Zero);
                progressDialog?.SetProgress(index++, count);

                string titleID = title.type == TitleType.AddOnContent ? title.titleID : title.baseTitleID ?? "";

                Process.latestVersions.TryGetValue(titleID, out uint latestVersion);
                Process.versionList.TryGetValue(titleID, out uint version);
                Process.titleVersions.TryGetValue(titleID, out uint titleVersion);

                if (latestVersion < version || latestVersion < titleVersion)
                {
                    listItem.BackColor = title.signature != true ? Color.OldLace : Color.LightYellow;
                }
                else if (title.signature != true)
                {
                    listItem.BackColor = Color.WhiteSmoke;
                }

                if (title.permission == Title.Permission.Dangerous)
                {
                    listItem.ForeColor = Color.DarkRed;
                }
                else if (title.permission == Title.Permission.Unsafe)
                {
                    listItem.ForeColor = Color.Indigo;
                }
            }
        }
        // INamespaceWalkCB
        public HRESULT FoundItem(IShellFolder psf, IntPtr pidl)
        {
            HRESULT hr = HRESULT.S_OK;

            if (_fCountingFiles)
            {
                _cFilesTotal++;
            }
            else
            {
                _cFileCur++;

                var psi = SHCreateItemWithParent <IShellItem2>(psf, pidl);
                hr = _ProcessItem(psi);
                try
                {
                    string pszName = psi.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY);
                    _ppd.SetProgress64(_cFileCur, _cFilesTotal);
                    _ppd.SetLine(2, pszName, true);
                }
                catch { }
            }
            return(_ppd.HasUserCancelled() ? HRESULT_FROM_WIN32(Win32Error.ERROR_CANCELLED) : hr);
        }
Beispiel #13
0
        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Title  = "Export Titles";
            saveFileDialog.Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*";

            Process.log?.WriteLine("\nExport Titles");

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                using (var writer = new StreamWriter(saveFileDialog.FileName))
                {
                    progressDialog = (IProgressDialog) new ProgressDialog();
                    progressDialog.StartProgressDialog(Handle, "Exporting titles");

                    writer.WriteLine("{0} {1}", aboutBox.AssemblyTitle, aboutBox.AssemblyVersion);
                    writer.WriteLine("--------------------------------------------------------------\n");

                    writer.WriteLine("Export titles starts at {0}\n", String.Format("{0:F}", DateTime.Now));

                    uint index = 0, count = (uint)titles.Count;

                    foreach (var title in titles)
                    {
                        if (progressDialog.HasUserCancelled())
                        {
                            break;
                        }

                        progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero);
                        progressDialog.SetProgress(index++, count);

                        writer.WriteLine("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}",
                                         title.titleID,
                                         title.titleName,
                                         title.displayVersion,
                                         title.versionString,
                                         title.latestVersionString,
                                         title.firmware,
                                         title.masterkeyString,
                                         title.filename,
                                         title.filesizeString,
                                         title.typeString,
                                         title.distribution,
                                         title.structureString,
                                         title.signatureString,
                                         title.permissionString,
                                         title.error);
                    }

                    writer.WriteLine("\n{0} of {1} titles exported", index, titles.Count);

                    Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);

                    progressDialog.StopProgressDialog();
                    Activate();

                    MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName);
                }
            }
        }
Beispiel #14
0
 /// <summary>
 /// Установить текст в одной из строк диалога
 /// </summary>
 /// <param name="lineNumber">Номер строки от 1 до 3</param>
 /// <param name="text">Текст строки</param>
 /// <param name="compact">Использовать ли компактную версию пути в строке, если текст окажется слишком длинным</param>
 public void SetLine(uint lineNumber, string text, bool compact)
 {
     _progressDialog.SetLine(lineNumber, text, compact, IntPtr.Zero);
 }
        /// <summary>
        /// Displays the progress dialog and starts the timer.
        /// </summary>
        /// <param name="parent">The dialog box's parent window.</param>
        public void Show(IWin32Window parent)
        {
            // Throw an exception if we are already running
            if (_state != ProgressDialogState.Stopped)
                throw new InvalidOperationException("Timer is already running.");

            // Get parent window handle
            if (parent == null) parent = Form.ActiveForm;
            IntPtr handle = (parent == null) ? IntPtr.Zero : parent.Handle;

            // Setup the window
            _nativeProgressDialog = (IProgressDialog)Activator.CreateInstance(_progressDialogType);
            _nativeProgressDialog.SetTitle(_title);
            _nativeProgressDialog.SetCancelMsg(_cancelMessage, null);
            if (ShowTimeRemaining)
                _nativeProgressDialog.SetLine(3, "Estimating time remaining...", false, IntPtr.Zero);

            // Create Window
            _nativeProgressDialog.StartProgressDialog(handle, null, _flags, IntPtr.Zero);

            _value = 0;
            _state = ProgressDialogState.Running;
            _nativeProgressDialog.Timer(PDTIMER.Reset, null);
        }
Beispiel #16
0
        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Title  = "Export Titles";
            saveFileDialog.Filter = "CSV File (*.csv)|*.csv";

            Process.log?.WriteLine("\nExport Titles");

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string filename = saveFileDialog.FileName;

                if (filename.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
                {
                    using (var writer = new StreamWriter(filename))
                    {
                        progressDialog = (IProgressDialog) new ProgressDialog();
                        progressDialog.StartProgressDialog(Handle, "Exporting titles");

                        char separator = Common.Settings.Default.CsvSeparator;
                        if (separator != '\0')
                        {
                            writer.WriteLine("sep={0}", separator);
                        }
                        else
                        {
                            separator = ',';
                        }

                        writer.WriteLine("# publisher {0} {1}", Application.ProductName, Application.ProductVersion);
                        writer.WriteLine("# updated {0}", String.Format("{0:F}", DateTime.Now));

                        writer.WriteLine(String.Join(separator.ToString(), Common.Title.Properties));

                        uint index = 0, count = (uint)titles.Count;

                        foreach (var title in titles)
                        {
                            if (progressDialog.HasUserCancelled())
                            {
                                break;
                            }

                            progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero);
                            progressDialog.SetProgress(index++, count);

                            writer.WriteLine(String.Join(separator.ToString(), new string[] {
                                title.titleID.Quote(separator),
                                title.baseTitleID.Quote(separator),
                                title.titleName.Quote(separator),
                                title.displayVersion.Quote(separator),
                                title.versionString.Quote(separator),
                                title.latestVersionString.Quote(separator),
                                title.systemUpdateString.Quote(separator),
                                title.systemVersionString.Quote(separator),
                                title.applicationVersionString.Quote(separator),
                                title.masterkeyString.Quote(separator),
                                title.titleKey.Quote(separator),
                                title.publisher.Quote(separator),
                                title.languagesString.Quote(separator),
                                title.filename.Quote(separator),
                                title.filesizeString.Quote(separator),
                                title.typeString.Quote(separator),
                                title.distribution.ToString().Quote(separator),
                                title.structureString.Quote(separator),
                                title.signatureString.Quote(separator),
                                title.permissionString.Quote(separator),
                                title.error.Quote(separator),
                            }));
                        }

                        Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);

                        progressDialog.StopProgressDialog();
                        Activate();

                        MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName);
                    }
                }
                else
                {
                    MessageBox.Show(String.Format("This file type is not supported {0}", Path.GetExtension(filename)), Application.ProductName);
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// Displays the progress dialog and starts the timer.
        /// </summary>
        /// <param name="parent">The dialog box's parent window.</param>
        public void Show(IWin32Window parent)
        {
            if (_state != ProgressDialogState.Stopped)
                throw new InvalidOperationException("Timer is already running.");

            if (_parentForm == null)
                _parentForm = Form.ActiveForm;

            IntPtr handle = parent?.Handle ?? IntPtr.Zero;

            //_nativeProgressDialog = (IProgressDialog)Activator.CreateInstance(_progressDialogType);
            _nativeProgressDialog = (IProgressDialog) new ProgressDialogImpl();
            _nativeProgressDialog.SetTitle(_title);
            _nativeProgressDialog.SetCancelMsg(_cancelMessage, null);
            if (ShowTimeRemaining)
                _nativeProgressDialog.SetLine(3, "Estimating time remaining...", false, IntPtr.Zero);

            _nativeProgressDialog.StartProgressDialog(handle, null, _flags, IntPtr.Zero);

            _value = 0;
            _state = ProgressDialogState.Running;
            _nativeProgressDialog.Timer(PDTIMER.Reset, null);
            _statePollingTimer.Change(TimeSpan.FromMilliseconds(250), TimeSpan.FromMilliseconds(250));
        }
Beispiel #18
0
        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Title  = "Export Titles";
            saveFileDialog.Filter = "CSV File (*.csv)|*.csv|Excel Workbook (*.xlsx)|*.xlsx";

            Process.log?.WriteLine("\nExport Titles");

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string filename = saveFileDialog.FileName;

                if (filename.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
                {
                    using (var writer = new StreamWriter(filename))
                    {
                        progressDialog = (IProgressDialog) new ProgressDialog();
                        progressDialog.StartProgressDialog(Handle, "Exporting titles");

                        char separator = Common.Settings.Default.CsvSeparator;
                        if (separator != '\0')
                        {
                            writer.WriteLine("sep={0}", separator);
                        }
                        else
                        {
                            separator = ',';
                        }

                        writer.WriteLine("# publisher {0} {1}", Application.ProductName, Application.ProductVersion);
                        writer.WriteLine("# updated {0}", String.Format("{0:F}", DateTime.Now));

                        writer.WriteLine(String.Join(separator.ToString(), Common.Title.Properties));

                        uint index = 0, count = (uint)titles.Count;

                        foreach (var title in titles)
                        {
                            if (progressDialog.HasUserCancelled())
                            {
                                break;
                            }

                            progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero);
                            progressDialog.SetProgress(index++, count);

                            writer.WriteLine(String.Join(separator.ToString(), new string[] {
                                title.titleID.Quote(separator),
                                title.baseTitleID.Quote(separator),
                                title.titleName.Quote(separator),
                                title.displayVersion.Quote(separator),
                                title.versionString.Quote(separator),
                                title.latestVersionString.Quote(separator),
                                title.systemUpdateString.Quote(separator),
                                title.systemVersionString.Quote(separator),
                                title.applicationVersionString.Quote(separator),
                                title.masterkeyString.Quote(separator),
                                title.titleKey.Quote(separator),
                                title.publisher.Quote(separator),
                                title.languagesString.Quote(separator),
                                title.filename.Quote(separator),
                                title.filesizeString.Quote(separator),
                                title.typeString.Quote(separator),
                                title.distribution.ToString().Quote(separator),
                                title.structureString.Quote(separator),
                                title.signatureString.Quote(separator),
                                title.permissionString.Quote(separator),
                                title.error.Quote(separator),
                            }));
                        }

                        Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);

                        progressDialog.StopProgressDialog();
                        Activate();

                        MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName);
                    }
                }
                else if (filename.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase))
                {
                    using (ExcelPackage excel = new ExcelPackage())
                    {
                        progressDialog = (IProgressDialog) new ProgressDialog();
                        progressDialog.StartProgressDialog(Handle, "Exporting titles");

                        ExcelWorksheet worksheet = excel.Workbook.Worksheets.Add(Common.History.Default.Titles.LastOrDefault().description ?? Application.ProductName);

                        worksheet.Cells[1, 1, 1, Title.Properties.Count()].LoadFromArrays(new List <string[]> {
                            Title.Properties
                        });
                        worksheet.Cells["1:1"].Style.Font.Bold = true;
                        worksheet.Cells["1:1"].Style.Font.Color.SetColor(Color.White);
                        worksheet.Cells["1:1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                        worksheet.Cells["1:1"].Style.Fill.BackgroundColor.SetColor(Color.MidnightBlue);

                        uint index = 0, count = (uint)titles.Count;

                        foreach (var title in titles)
                        {
                            if (progressDialog.HasUserCancelled())
                            {
                                break;
                            }

                            progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero);
                            progressDialog.SetProgress(index++, count);

                            var data = new List <string[]>
                            {
                                new string[] {
                                    title.titleID,
                                    title.baseTitleID,
                                    title.titleName,
                                    title.displayVersion,
                                    title.versionString,
                                    title.latestVersionString,
                                    title.systemUpdateString,
                                    title.systemVersionString,
                                    title.applicationVersionString,
                                    title.masterkeyString,
                                    title.titleKey,
                                    title.publisher,
                                    title.languagesString,
                                    title.filename,
                                    title.filesizeString,
                                    title.typeString,
                                    title.distribution.ToString(),
                                    title.structureString,
                                    title.signatureString,
                                    title.permissionString,
                                    title.error,
                                }
                            };

                            worksheet.Cells[(int)index + 1, 1].LoadFromArrays(data);

                            string titleID = title.type == TitleType.AddOnContent ? title.titleID : title.baseTitleID ?? "";

                            Process.latestVersions.TryGetValue(titleID, out uint latestVersion);
                            Process.versionList.TryGetValue(titleID, out uint version);
                            Process.titleVersions.TryGetValue(titleID, out uint titleVersion);

                            if (latestVersion < version || latestVersion < titleVersion)
                            {
                                worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                                worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.BackgroundColor.SetColor(title.signature != true ? Color.OldLace : Color.LightYellow);
                            }
                            else if (title.signature != true)
                            {
                                worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                                worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.BackgroundColor.SetColor(Color.WhiteSmoke);
                            }

                            if (title.permission == Title.Permission.Dangerous)
                            {
                                worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(Color.DarkRed);
                            }
                            else if (title.permission == Title.Permission.Unsafe)
                            {
                                worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(Color.Indigo);
                            }
                        }

                        ExcelRange range = worksheet.Cells[1, 1, (int)count + 1, Title.Properties.Count()];
                        range.Style.Border.Top.Style    = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
                        range.Style.Border.Left.Style   = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
                        range.Style.Border.Right.Style  = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
                        range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;

                        worksheet.Column(1).Width = 18;
                        worksheet.Column(2).Width = 18;
                        worksheet.Column(3).AutoFit();
                        worksheet.Column(3).Width  = Math.Max(worksheet.Column(3).Width, 30);
                        worksheet.Column(4).Width  = 16;
                        worksheet.Column(5).Width  = 16;
                        worksheet.Column(6).Width  = 16;
                        worksheet.Column(7).Width  = 16;
                        worksheet.Column(8).Width  = 16;
                        worksheet.Column(9).Width  = 16;
                        worksheet.Column(10).Width = 16;
                        worksheet.Column(11).AutoFit();
                        worksheet.Column(11).Width = Math.Max(worksheet.Column(11).Width, 36);
                        worksheet.Column(12).AutoFit();
                        worksheet.Column(12).Width = Math.Max(worksheet.Column(12).Width, 30);
                        worksheet.Column(13).Width = 18;
                        worksheet.Column(14).AutoFit();
                        worksheet.Column(14).Width = Math.Max(worksheet.Column(14).Width, 54);
                        worksheet.Column(15).Width = 10;
                        worksheet.Column(16).Width = 10;
                        worksheet.Column(17).Width = 12;
                        worksheet.Column(18).Width = 12;
                        worksheet.Column(19).Width = 10;
                        worksheet.Column(20).Width = 10;
                        worksheet.Column(21).Width = 40;

                        excel.SaveAs(new FileInfo(filename));

                        Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);

                        progressDialog.StopProgressDialog();
                        Activate();

                        MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName);
                    }
                }
                else
                {
                    MessageBox.Show(String.Format("This file type is not supported {0}", Path.GetExtension(filename)), Application.ProductName);
                }
            }
        }
Beispiel #19
0
        private void RunProgressDialog(IntPtr owner, object argument)
        {
            if (_backgroundWorker.IsBusy)
            {
                throw new InvalidOperationException(Resources.ProgressDialogRunning);
            }

            if (Animation != null)
            {
                try
                {
                    _currentAnimationModuleHandle = Animation.LoadLibrary();
                }
                catch (Win32Exception ex)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.AnimationLoadErrorFormat, ex.Message), ex);
                }
                catch (FileNotFoundException ex)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.AnimationLoadErrorFormat, ex.Message), ex);
                }
            }

            _cancellationPending = false;
            _dialog = new Interop.ProgressDialog();
            _dialog.SetTitle(WindowTitle);
            if (Animation != null)
            {
                _dialog.SetAnimation(_currentAnimationModuleHandle, (ushort)Animation.ResourceId);
            }

            if (CancellationText.Length > 0)
            {
                _dialog.SetCancelMsg(CancellationText, null);
            }
            _dialog.SetLine(1, Text, UseCompactPathsForText, IntPtr.Zero);
            _dialog.SetLine(2, Description, UseCompactPathsForDescription, IntPtr.Zero);

            ProgressDialogFlags flags = ProgressDialogFlags.Normal;

            if (owner != IntPtr.Zero)
            {
                flags |= ProgressDialogFlags.Modal;
            }
            switch (ProgressBarStyle)
            {
            case ProgressBarStyle.None:
                flags |= ProgressDialogFlags.NoProgressBar;
                break;

            case ProgressBarStyle.MarqueeProgressBar:
                if (NativeMethods.IsWindowsVistaOrLater)
                {
                    flags |= ProgressDialogFlags.MarqueeProgress;
                }
                else
                {
                    flags |= ProgressDialogFlags.NoProgressBar; // Older than Vista doesn't support marquee.
                }
                break;
            }
            if (ShowTimeRemaining)
            {
                flags |= ProgressDialogFlags.AutoTime;
            }
            if (!ShowCancelButton)
            {
                flags |= ProgressDialogFlags.NoCancel;
            }
            if (!MinimizeBox)
            {
                flags |= ProgressDialogFlags.NoMinimize;
            }

            _dialog.StartProgressDialog(owner, null, flags, IntPtr.Zero);
            _backgroundWorker.RunWorkerAsync(argument);
        }