source: branches/eraser6/Eraser/AboutForm.cs @ 903

Revision 903, 9.7 KB checked in by lowjoel, 6 years ago (diff)

Ran Static code analysis on the Eraser project and implemented a few recommendations.

-Use more specific exceptions to allow code to determine the type of exception.
-Made GUIProgram implement IDisposable since the global mutex must be freed.
-Mde AboutForm? implement IDisposable, clearing the caching bitmaps on dispose.
-Made a few CommandLineProgram? functions static since they don't reference this.
-Name parameters/local with more unique, descriptive names for clarity.
-Use EventHandler?<EventArg?> instead of declaring our own delegate and event types as the type of the evenr handler

  • Property svn:keywords set to Id
RevLine 
[349]1/*
2 * $Id$
3 * Copyright 2008 The Eraser Project
4 * Original Author: Joel Low <lowjoel@users.sourceforge.net>
[652]5 * Modified By: Kasra Nassiri <cjax@users.sourceforge.net>
[349]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
[119]22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
[471]27using System.Drawing.Imaging;
[119]28using System.Text;
29using System.Windows.Forms;
[470]30using System.Runtime.InteropServices;
31using System.Reflection;
[471]32using Eraser.Util;
[474]33using System.Diagnostics;
[119]34
35namespace Eraser
36{
37    public partial class AboutForm : Form
38    {
[471]39        private Bitmap AboutBitmap;
40        private Point AboutBitmapPos;
[472]41        private string AboutText;
[471]42        private Bitmap AboutTextBitmap;
43        private Rectangle AboutTextRect;
[470]44
[471]45        private Bitmap ParentBitmap;
46        private int ParentOpacity;
47        private int AboutTextScrollTop;
48
[474]49        private Rectangle WebsiteRect;
50        private Rectangle DonateRect;
51
[471]52        private Bitmap DoubleBufferBitmap;
53
[470]54        public AboutForm(Control parent)
[119]55        {
[471]56            //Create and position the dialog
[119]57            InitializeComponent();
[470]58            ClientSize = new Size(parent.ClientSize.Width, parent.ClientSize.Height);
59            Point point = parent.PointToScreen(new Point(0, 0));
60            Left = point.X;
61            Top = point.Y;
62
[472]63            //Load the localised About Text
[500]64            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.
[472]65
[483]66Erasure Method Credits:
67Gutmann (35 Pass):      Copyright Peter Gutmann & Colin Plumb
68Gutmann Lite (10 pass):         Copyright Peter Gutmann & Colin Plumb
69US DoD (7 pass):            Copyright United States Department of
70                Defense
71US DoD (3 pass):            Copyright United States Department of
72                Defense
[509]73US Air Force 5020 (3 pass): Copyright United States Department of
[483]74                Defense
75US Army AR380-19 (3 pass):  Copyright United States Department of
76                Defense
77RCMP TSSIT OPS-II (7 pass): Copyright Government of Canada,
78                Royal Canadian Mounted Police
[500]79Schneier's Method (7 pass): Copyright Bruce Schneier
[483]80German VSITR (7 pass):      Copyright Germany BSI Verschlusssachen
81                -IT-Richtlinien
82British HMG IS5 (3 pass):       Copyright British Government
83British HMG IS5 (1 pass):       Copyright British Government
84Russian GOST P50739-95 (2 pass):    Copyright Government of the Soviet
85                Union
86Pseudorandom data (1 pass): Public Domain
87First/Last 16Kb:            Copyright The Eraser Project
88
89Eraser Copyright " + "\u00A9" + @" The Eraser Project
90
91Eraser Project Members:
[509]92" + "\u2022" + @" Sami Tolvanen:        Mentor/Initiator
[483]93" + "\u2022" + @" Garrett Trant:        Mentor/Researcher
94" + "\u2022" + @" Joel Low:     Lead Developer
[655]95" + "\u2022" + @" Kasra Nassiri:        Developer/Security Researcher
96" + "\u2022" + @" Dennis van Lith:      Designer");
[483]97
[471]98            //Create the About bitmap localised for the current version (sans scrolling
99            //text) so it can be drawn quickly later.
100            AboutBitmap = Properties.Resources.AboutDialog;
101            AboutBitmap = AboutBitmap.Clone(new Rectangle(0, 0, AboutBitmap.Width,
102                AboutBitmap.Height), PixelFormat.DontCare);
103            using (Graphics g = Graphics.FromImage(AboutBitmap))
[470]104            {
105                //Version number
106                Font boldFont = new Font(Font, FontStyle.Bold);
[474]107                Font underlineFont = new Font(Font, FontStyle.Underline);
[470]108                Brush textBrush = new SolidBrush(Color.White);
[471]109                PointF eraserPos = new PointF(168, 80);
[470]110                SizeF eraserSize = g.MeasureString(S._("Eraser"), boldFont);
111                g.DrawString(S._("Eraser"), boldFont, textBrush, eraserPos);
112                g.DrawString(Assembly.GetExecutingAssembly().GetName().Version.ToString(),
[600]113                    Font, textBrush, new PointF(eraserPos.X + eraserSize.Width + 3, eraserPos.Y));
[470]114
115                //Copyright and Website
116                string copyrightText = S._("copyright \u00a9 2008 The Eraser Project");
117                PointF copyrightPos = new PointF(eraserPos.X, eraserPos.Y + eraserSize.Height);
118                SizeF copyrightSize = g.MeasureString(copyrightText, Font);
119                g.DrawString(copyrightText, Font, textBrush, copyrightPos);
120
121                string websiteText = "http://eraser.sourceforge.net/";
122                PointF websitePos = new PointF(copyrightPos.X, copyrightPos.Y + copyrightSize.Height);
123                SizeF websiteSize = g.MeasureString(websiteText, Font);
[474]124                g.DrawString(websiteText, underlineFont, textBrush, websitePos);
125                WebsiteRect = new Rectangle((int)websitePos.X, (int)websitePos.Y,
126                    (int)websiteSize.Width, (int)websiteSize.Height);
[470]127
128                //Open source disclaimer.
129                string disclaimerText = S._("Eraser is free open-source software!");
130                PointF disclaimerPos = new PointF(websitePos.X, websitePos.Y + websiteSize.Height * 1.5f);
131                g.DrawString(disclaimerText, Font, textBrush, disclaimerPos);
132
133                //Donation statement
[852]134                string donationText = S._("Please help us to continue developing Eraser - donate some coffee!");
[470]135                PointF donationPos = new PointF(disclaimerPos.X, disclaimerPos.Y + 170);
136                SizeF donationSize = g.MeasureString(donationText, Font);
137                g.DrawString(donationText, Font, textBrush, donationPos);
[474]138                DonateRect = new Rectangle((int)donationPos.X, (int)donationPos.Y,
139                    (int)donationSize.Width, (int)donationSize.Height);
[470]140            }
141
[471]142            //Calculate the position of the About bitmap
143            AboutBitmapPos = new Point((ClientSize.Width - AboutBitmap.Width) / 2,
144                (ClientSize.Height - AboutBitmap.Height) / 2);
[474]145            WebsiteRect.X += AboutBitmapPos.X;
146            WebsiteRect.Y += AboutBitmapPos.Y;
147            DonateRect.X += AboutBitmapPos.X;
148            DonateRect.Y += AboutBitmapPos.Y;
[471]149
150            //And calculate the bounds of the About Text.
151            AboutTextRect = new Rectangle(AboutBitmapPos.X + 19 + 149, AboutBitmapPos.Y + 20 + 147,
152                AboutBitmap.Width - 19 - 149 - 20, 130);
153
154            //Create the About Text laid out on screen.
155            SizeF aboutTextSize = SizeF.Empty;
156            using (Bitmap b = new Bitmap(1, 1))
157            using (Graphics g = Graphics.FromImage(b))
158                aboutTextSize = g.MeasureString(AboutText, Font, AboutTextRect.Width);
159            AboutTextBitmap = new Bitmap(AboutTextRect.Width, (int)aboutTextSize.Height);
160            using (Graphics g = Graphics.FromImage(AboutTextBitmap))
[470]161            {
[471]162                g.Clear(Color.FromArgb(0, 0, 0, 0));
163                g.DrawString(AboutText, Font, new SolidBrush(Color.White), new RectangleF(
164                    0.0f, 0.0f, AboutTextRect.Width, aboutTextSize.Height));
[470]165            }
166
[471]167            //Get the parent dialog's screen buffer.
168            ParentBitmap = new Bitmap(parent.ClientSize.Width, parent.ClientSize.Height);
169            using (Graphics dest = Graphics.FromImage(ParentBitmap))
[470]170            {
[471]171                parent.Refresh();
172                Point parentPos = parent.PointToScreen(new Point(0, 0));
173                dest.CopyFromScreen(parentPos, new Point(0, 0), parent.ClientSize);
174            }
[470]175
[471]176            AboutTextScrollTop = AboutTextRect.Height / 2;
177            animationTimer_Tick(null, null);
[470]178        }
179
[119]180        private void AboutForm_Click(object sender, EventArgs e)
181        {
[474]182            Point cursorPos = PointToClient(Cursor.Position);
183            if (WebsiteRect.IntersectsWith(new Rectangle(cursorPos, new Size(1, 1))))
[853]184                Process.Start("http://eraser.heidi.ie/");
[474]185            else if (DonateRect.IntersectsWith(new Rectangle(cursorPos, new Size(1, 1))))
186                Process.Start("https://euro.swreg.org/cgi-bin/s.cgi?r=1&s=80181&db_key=1512312&x=0&lang=&lnk=");
187            else
188                //Dismiss the dialog.
189                Close();
[119]190        }
[470]191
[856]192        private void AboutForm_Paint(object sender, PaintEventArgs e)
193        {
194            DrawComposite(e.Graphics);
195        }
196
[474]197        private void AboutForm_MouseMove(object sender, MouseEventArgs e)
198        {
199            Cursor.Current = Cursors.Default;
200            if (WebsiteRect.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))) ||
201                DonateRect.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
202                Cursor.Current = Cursors.Hand;
203        }
204
205        private void AboutForm_MouseLeave(object sender, EventArgs e)
206        {
207            Cursor.Current = Cursors.Default;
208        }
209
[471]210        private void animationTimer_Tick(object sender, EventArgs e)
[470]211        {
[471]212            if (ParentOpacity <= 128)
213                ParentOpacity += 8;
214            if (AboutTextBitmap.Height < -AboutTextScrollTop)
215                AboutTextScrollTop = AboutTextRect.Height;
216            else
217                AboutTextScrollTop -= 1;
[470]218
[856]219            using (Graphics g = CreateGraphics())
220                DrawComposite(g);
[471]221        }
222
[856]223        private void DrawComposite(Graphics g)
[471]224        {
225            if (DoubleBufferBitmap == null)
226                DoubleBufferBitmap = new Bitmap(ClientSize.Width, ClientSize.Height);
[856]227            using (Graphics bg = Graphics.FromImage(DoubleBufferBitmap))
[470]228            {
[471]229                //Draw the parent image with a fading out effect
[856]230                if (ParentOpacity > 128)
231                    bg.Clip = new Region(AboutTextRect);
232
[471]233                Brush brush = new SolidBrush(Color.FromArgb(ParentOpacity, 0, 0, 0));
[856]234                bg.DrawImageUnscaled(ParentBitmap, 0, 0);
235                bg.FillRectangle(brush, ClientRectangle);
[470]236
[471]237                //Then draw the About bitmap (which we cached in the constructor)
[856]238                bg.DrawImageUnscaled(AboutBitmap, AboutBitmapPos);
[470]239
[471]240                //And the scrolling text
[856]241                bg.Clip = new Region(AboutTextRect);
242                bg.DrawImageUnscaled(AboutTextBitmap, AboutTextRect.Left,
[471]243                    AboutTextRect.Top + AboutTextScrollTop);
[856]244                bg.ResetClip();
[470]245            }
246
[856]247            if (ParentOpacity > 128)
248                if (g.Clip != null)
249                    g.Clip.Complement(new Region(AboutTextRect));
250                else
251                    g.Clip = new Region(AboutTextRect);
252            g.DrawImageUnscaled(DoubleBufferBitmap, 0, 0);
[470]253        }
[119]254    }
[472]255}
Note: See TracBrowser for help on using the repository browser.