source: trunk/eraser6/Eraser/AboutForm.cs @ 1359

Revision 1359, 10.7 KB checked in by lowjoel, 5 years ago (diff)

Set svn:eol-style to native

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008 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            if (WebsiteRect.IntersectsWith(new Rectangle(cursorPos, new Size(1, 1))))
193                Process.Start("http://eraser.heidi.ie/");
194            else if (DonateRect.IntersectsWith(new Rectangle(cursorPos, new Size(1, 1))))
195                Process.Start("https://euro.swreg.org/cgi-bin/s.cgi?r=1&s=80181&db_key=1512312&x=0&lang=&lnk=");
196            else if ((DateTime.Now - mouseDownTime < mouseSpeedUpSpan))
197                //Dismiss the dialog.
198                Close();
199        }
200
201        private void AboutForm_Paint(object sender, PaintEventArgs e)
202        {
203            DrawComposite(e.Graphics);
204        }
205
206        private void AboutForm_MouseMove(object sender, MouseEventArgs e)
207        {
208            Cursor.Current = Cursors.Default;
209            if (WebsiteRect.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))) ||
210                DonateRect.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
211                Cursor.Current = Cursors.Hand;
212        }
213
214        private void AboutForm_MouseLeave(object sender, EventArgs e)
215        {
216            Cursor.Current = Cursors.Default;
217        }
218
219        private void animationTimer_Tick(object sender, EventArgs e)
220        {
221            if (ParentOpacity <= 128)
222                ParentOpacity += 8;
223
224            if (AboutTextBitmap.Height < -AboutTextScrollTop)
225                AboutTextScrollTop = AboutTextRect.Height;
226            else if (AboutTextBitmap.Height < AboutTextScrollTop)
227                AboutTextScrollTop = -AboutTextRect.Height;
228            else
229            {
230                if (mouseSpeed == 0.0)
231                {
232                    AboutTextScrollTop -= 1;
233                }
234                else
235                {
236                    int speed = (mouseBotton == MouseButtons.Left ? -1 : +1);
237                    speed *= (int)mouseSpeed;
238
239                    AboutTextScrollTop += speed;
240
241                    // clamp so it doesnt go out of hand
242                    mouseSpeed = Math.Min(8.0, mouseSpeed + 0.1);
243                }
244            }
245
246            using (Graphics g = CreateGraphics())
247                DrawComposite(g);
248        }
249
250        private void DrawComposite(Graphics g)
251        {
252            if (DoubleBufferBitmap == null)
253                DoubleBufferBitmap = new Bitmap(ClientSize.Width, ClientSize.Height);
254            using (Graphics bg = Graphics.FromImage(DoubleBufferBitmap))
255            {
256                //Draw the parent image with a fading out effect
257                if (ParentOpacity > 128)
258                    bg.Clip = new Region(AboutTextRect);
259
260                Brush brush = new SolidBrush(Color.FromArgb(ParentOpacity, 0, 0, 0));
261                bg.DrawImageUnscaled(ParentBitmap, 0, 0);
262                bg.FillRectangle(brush, ClientRectangle);
263
264                //Then draw the About bitmap (which we cached in the constructor)
265                bg.DrawImageUnscaled(AboutBitmap, AboutBitmapPos);
266
267                //And the scrolling text
268                bg.Clip = new Region(AboutTextRect);
269                bg.DrawImageUnscaled(AboutTextBitmap, AboutTextRect.Left,
270                    AboutTextRect.Top + AboutTextScrollTop);
271                bg.ResetClip();
272            }
273
274            if (ParentOpacity > 128)
275                if (g.Clip != null)
276                    g.Clip.Complement(new Region(AboutTextRect));
277                else
278                    g.Clip = new Region(AboutTextRect);
279            g.DrawImageUnscaled(DoubleBufferBitmap, 0, 0);
280        }
281
282        private double mouseSpeed = 0.0;
283        private DateTime mouseDownTime = DateTime.MinValue;
284        private TimeSpan mouseSpeedUpSpan = new TimeSpan(0, 0, 0, 0, 230);
285        private MouseButtons mouseBotton;
286        private void AboutForm_MouseDown(object sender, MouseEventArgs e)
287        {
288            mouseSpeed = 2.0;
289            mouseBotton = e.Button;
290            animationTimer.Interval = 20;
291            mouseDownTime = DateTime.Now;
292        }
293
294        private void AboutForm_MouseUp(object sender, MouseEventArgs e)
295        {
296            mouseSpeed = 0.0;
297            animationTimer.Interval = 50;
298        }
299
300    }
301}
Note: See TracBrowser for help on using the repository browser.