source: branches/eraser6/6.0/Eraser/AboutForm.cs @ 1641

Revision 1641, 11.1 KB checked in by lowjoel, 5 years ago (diff)

Fixed crash when user clicks on About dialog links but there was an error starting the process. This results in Process.Start throwing a Win32Exception which we now catch and show the error to the user.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008-2009 The Eraser Project
4 * Original Author: Joel Low <lowjoel@users.sourceforge.net>
5 * Modified By: Kasra Nassiri <cjax@users.sourceforge.net>
6 *
7 * This file is part of Eraser.
8 *
9 * Eraser is free software: you can redistribute it and/or modify it under the
10 * terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
13 *
14 * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * A copy of the GNU General Public License can be found at
19 * <http://www.gnu.org/licenses/>.
20 */
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Drawing.Imaging;
28using System.Text;
29using System.Windows.Forms;
30using System.Runtime.InteropServices;
31using System.Reflection;
32using Eraser.Util;
33using System.Diagnostics;
34using System.Globalization;
35
36namespace Eraser
37{
38    public partial class AboutForm : Form
39    {
40        private Bitmap AboutBitmap;
41        private Point AboutBitmapPos;
42        private string AboutText;
43        private Bitmap AboutTextBitmap;
44        private Rectangle AboutTextRect;
45
46        private Bitmap ParentBitmap;
47        private int ParentOpacity;
48        private int AboutTextScrollTop;
49
50        private Rectangle WebsiteRect;
51        private Rectangle DonateRect;
52
53        private Bitmap DoubleBufferBitmap;
54
55        public AboutForm(Control parent)
56        {
57            //Create and position the dialog
58            InitializeComponent();
59            UXThemeApi.UpdateControlTheme(this);
60            ClientSize = new Size(parent.ClientSize.Width, parent.ClientSize.Height);
61            Point point = parent.PointToScreen(new Point(0, 0));
62            Left = point.X;
63            Top = point.Y;
64
65            //Load the localised About Text
66            AboutText = S._(@"Eraser is an advanced security tool for Windows, which allows you to completely remove sensitive data from your hard drive by overwriting it several times with carefully selected patterns. Eraser is Free software and its source code is released under GNU General Public License.
67
68Erasure Method Credits:
69Gutmann (35 Pass):      Copyright Peter Gutmann & Colin Plumb
70Gutmann Lite (10 pass):         Copyright Peter Gutmann & Colin Plumb
71US DoD (7 pass):            Copyright United States Department of
72                Defense
73US DoD (3 pass):            Copyright United States Department of
74                Defense
75US Air Force 5020 (3 pass): Copyright United States Department of
76                Defense
77US Army AR380-19 (3 pass):  Copyright United States Department of
78                Defense
79RCMP TSSIT OPS-II (7 pass): Copyright Government of Canada,
80                Royal Canadian Mounted Police
81Schneier's Method (7 pass): Copyright Bruce Schneier
82German VSITR (7 pass):      Copyright Germany BSI Verschlusssachen
83                -IT-Richtlinien
84British HMG IS5 (3 pass):       Copyright British Government
85British HMG IS5 (1 pass):       Copyright British Government
86Russian GOST P50739-95 (2 pass):    Copyright Government of the Soviet
87                Union
88Pseudorandom data (1 pass): Public Domain
89First/Last 16Kb:            Copyright The Eraser Project
90
91Eraser Copyright " + "\u00A9" + @" The Eraser Project
92
93Eraser Project Members:
94" + "\u2022" + @" Sami Tolvanen:        Mentor/Initiator
95" + "\u2022" + @" Garrett Trant:        Mentor/Researcher
96" + "\u2022" + @" Joel Low:     Lead Developer
97" + "\u2022" + @" Kasra Nassiri:        Developer/Security Researcher
98" + "\u2022" + @" Dennis van Lith:      Designer");
99
100            //Create the About bitmap localised for the current version (sans scrolling
101            //text) so it can be drawn quickly later.
102            AboutBitmap = Properties.Resources.AboutDialog;
103            AboutBitmap = AboutBitmap.Clone(new Rectangle(0, 0, AboutBitmap.Width,
104                AboutBitmap.Height), PixelFormat.DontCare);
105            using (Graphics g = Graphics.FromImage(AboutBitmap))
106            {
107                //Version number
108                Font boldFont = new Font(Font, FontStyle.Bold);
109                Font underlineFont = new Font(Font, FontStyle.Underline);
110                Brush textBrush = new SolidBrush(Color.White);
111                PointF eraserPos = new PointF(168, 80);
112                SizeF eraserSize = g.MeasureString(S._("Eraser"), boldFont);
113                g.DrawString(S._("Eraser"), boldFont, textBrush, eraserPos);
114
115                #pragma warning disable 429
116                string versionString = BuildInfo.CustomBuild ?
117                    S._("{0} (Built: {1:F}, special build)") : S._("{0} (Built: {1:F})");
118                #pragma warning restore 429
119
120                g.DrawString(string.Format(CultureInfo.CurrentCulture, versionString,
121                    Assembly.GetExecutingAssembly().GetName().Version, BuildInfo.BuildDate),
122                    Font, textBrush, new PointF(eraserPos.X + eraserSize.Width + 3, eraserPos.Y));
123
124                //Copyright and Website
125                string copyrightText = S._("copyright \u00a9 2008-2009 The Eraser Project");
126                PointF copyrightPos = new PointF(eraserPos.X, eraserPos.Y + eraserSize.Height);
127                SizeF copyrightSize = g.MeasureString(copyrightText, Font);
128                g.DrawString(copyrightText, Font, textBrush, copyrightPos);
129
130                string websiteText = "http://eraser.heidi.ie/";
131                PointF websitePos = new PointF(copyrightPos.X, copyrightPos.Y + copyrightSize.Height);
132                SizeF websiteSize = g.MeasureString(websiteText, Font);
133                g.DrawString(websiteText, underlineFont, textBrush, websitePos);
134                WebsiteRect = new Rectangle((int)websitePos.X, (int)websitePos.Y,
135                    (int)websiteSize.Width, (int)websiteSize.Height);
136
137                //Open source disclaimer.
138                string disclaimerText = S._("Eraser is free open-source software!");
139                PointF disclaimerPos = new PointF(websitePos.X, websitePos.Y + websiteSize.Height * 1.5f);
140                g.DrawString(disclaimerText, Font, textBrush, disclaimerPos);
141
142                //Donation statement
143                string donationText = S._("Please help us to continue developing Eraser - donate some coffee!");
144                PointF donationPos = new PointF(disclaimerPos.X, disclaimerPos.Y + 170);
145                SizeF donationSize = g.MeasureString(donationText, Font);
146                g.DrawString(donationText, Font, textBrush, donationPos);
147                DonateRect = new Rectangle((int)donationPos.X, (int)donationPos.Y,
148                    (int)donationSize.Width, (int)donationSize.Height);
149            }
150
151            //Calculate the position of the About bitmap
152            AboutBitmapPos = new Point((ClientSize.Width - AboutBitmap.Width) / 2,
153                (ClientSize.Height - AboutBitmap.Height) / 2);
154            WebsiteRect.X += AboutBitmapPos.X;
155            WebsiteRect.Y += AboutBitmapPos.Y;
156            DonateRect.X += AboutBitmapPos.X;
157            DonateRect.Y += AboutBitmapPos.Y;
158
159            //And calculate the bounds of the About Text.
160            AboutTextRect = new Rectangle(AboutBitmapPos.X + 19 + 149, AboutBitmapPos.Y + 20 + 147,
161                AboutBitmap.Width - 19 - 149 - 20, 130);
162
163            //Create the About Text laid out on screen.
164            SizeF aboutTextSize = SizeF.Empty;
165            using (Bitmap b = new Bitmap(1, 1))
166            using (Graphics g = Graphics.FromImage(b))
167                aboutTextSize = g.MeasureString(AboutText, Font, AboutTextRect.Width);
168            AboutTextBitmap = new Bitmap(AboutTextRect.Width, (int)aboutTextSize.Height);
169            using (Graphics g = Graphics.FromImage(AboutTextBitmap))
170            {
171                g.Clear(Color.FromArgb(0, 0, 0, 0));
172                g.DrawString(AboutText, Font, new SolidBrush(Color.White), new RectangleF(
173                    0.0f, 0.0f, AboutTextRect.Width, aboutTextSize.Height));
174            }
175
176            //Get the parent dialog's screen buffer.
177            ParentBitmap = new Bitmap(parent.ClientSize.Width, parent.ClientSize.Height);
178            using (Graphics dest = Graphics.FromImage(ParentBitmap))
179            {
180                parent.Refresh();
181                Point parentPos = parent.PointToScreen(new Point(0, 0));
182                dest.CopyFromScreen(parentPos, new Point(0, 0), parent.ClientSize);
183            }
184
185            AboutTextScrollTop = AboutTextRect.Height / 2;
186            animationTimer_Tick(null, null);
187        }
188
189        private void AboutForm_Click(object sender, EventArgs e)
190        {
191            Point cursorPos = PointToClient(Cursor.Position);
192            try
193            {
194                if (WebsiteRect.IntersectsWith(new Rectangle(cursorPos, new Size(1, 1))))
195                    Process.Start("http://eraser.heidi.ie/");
196                else if (DonateRect.IntersectsWith(new Rectangle(cursorPos, new Size(1, 1))))
197                    Process.Start("https://euro.swreg.org/cgi-bin/s.cgi?r=1&s=80181&db_key=1512312&x=0&lang=&lnk=");
198                else if ((DateTime.Now - mouseDownTime < mouseSpeedUpSpan))
199                    //Dismiss the dialog.
200                    Close();
201            }
202            catch (Win32Exception ex)
203            {
204                //We've got an error executing the the browser to pass the links: show an error
205                //to the user.
206                MessageBox.Show(S._("Could not open the required web page. The error returned " +
207                    "was: {0}", ex.Message), S._("Eraser"), MessageBoxButtons.OK,
208                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
209                    S.IsRightToLeft(null) ? MessageBoxOptions.RtlReading : 0);
210            }
211        }
212
213        private void AboutForm_Paint(object sender, PaintEventArgs e)
214        {
215            DrawComposite(e.Graphics);
216        }
217
218        private void AboutForm_MouseMove(object sender, MouseEventArgs e)
219        {
220            Cursor.Current = Cursors.Default;
221            if (WebsiteRect.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))) ||
222                DonateRect.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
223                Cursor.Current = Cursors.Hand;
224        }
225
226        private void AboutForm_MouseLeave(object sender, EventArgs e)
227        {
228            Cursor.Current = Cursors.Default;
229        }
230
231        private void animationTimer_Tick(object sender, EventArgs e)
232        {
233            if (ParentOpacity <= 128)
234                ParentOpacity += 8;
235
236            if (AboutTextBitmap.Height < -AboutTextScrollTop)
237                AboutTextScrollTop = AboutTextRect.Height;
238            else if (AboutTextBitmap.Height < AboutTextScrollTop)
239                AboutTextScrollTop = -AboutTextRect.Height;
240            else
241            {
242                if (mouseSpeed == 0.0)
243                {
244                    AboutTextScrollTop -= 1;
245                }
246                else
247                {
248                    int speed = (mouseBotton == MouseButtons.Left ? -1 : +1);
249                    speed *= (int)mouseSpeed;
250
251                    AboutTextScrollTop += speed;
252
253                    // clamp so it doesnt go out of hand
254                    mouseSpeed = Math.Min(8.0, mouseSpeed + 0.1);
255                }
256            }
257
258            using (Graphics g = CreateGraphics())
259                DrawComposite(g);
260        }
261
262        private void DrawComposite(Graphics g)
263        {
264            if (DoubleBufferBitmap == null)
265                DoubleBufferBitmap = new Bitmap(ClientSize.Width, ClientSize.Height);
266            using (Graphics bg = Graphics.FromImage(DoubleBufferBitmap))
267            {
268                //Draw the parent image with a fading out effect
269                if (ParentOpacity > 128)
270                    bg.Clip = new Region(AboutTextRect);
271
272                Brush brush = new SolidBrush(Color.FromArgb(ParentOpacity, 0, 0, 0));
273                bg.DrawImageUnscaled(ParentBitmap, 0, 0);
274                bg.FillRectangle(brush, ClientRectangle);
275
276                //Then draw the About bitmap (which we cached in the constructor)
277                bg.DrawImageUnscaled(AboutBitmap, AboutBitmapPos);
278
279                //And the scrolling text
280                bg.Clip = new Region(AboutTextRect);
281                bg.DrawImageUnscaled(AboutTextBitmap, AboutTextRect.Left,
282                    AboutTextRect.Top + AboutTextScrollTop);
283                bg.ResetClip();
284            }
285
286            if (ParentOpacity > 128)
287                if (g.Clip != null)
288                    g.Clip.Complement(new Region(AboutTextRect));
289                else
290                    g.Clip = new Region(AboutTextRect);
291            g.DrawImageUnscaled(DoubleBufferBitmap, 0, 0);
292        }
293
294        private double mouseSpeed = 0.0;
295        private DateTime mouseDownTime = DateTime.MinValue;
296        private TimeSpan mouseSpeedUpSpan = new TimeSpan(0, 0, 0, 0, 230);
297        private MouseButtons mouseBotton;
298        private void AboutForm_MouseDown(object sender, MouseEventArgs e)
299        {
300            mouseSpeed = 2.0;
301            mouseBotton = e.Button;
302            animationTimer.Interval = 20;
303            mouseDownTime = DateTime.Now;
304        }
305
306        private void AboutForm_MouseUp(object sender, MouseEventArgs e)
307        {
308            mouseSpeed = 0.0;
309            animationTimer.Interval = 50;
310        }
311
312    }
313}
Note: See TracBrowser for help on using the repository browser.