'Author: Troy Simpson - VMDiskSize - VMWare Disk Size Changer (wrapper) 'Copyright (C) 2005 Troy Simpson 'For more information, see http://www.ebswift.com ' 'This program is free software; you can redistribute it and/or 'modify it under the terms of the GNU General Public License 'as published by the Free Software Foundation; either version 2 'of the License, or (at your option) any later version. ' 'This program is distributed in the hope that it will be useful, 'but WITHOUT ANY WARRANTY; without even the implied warranty of 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 'GNU General Public License for more details. ' 'You should have received a copy of the GNU General Public License 'along with this program; if not, write to the Free Software 'Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Imports Proc Imports System.IO ' Created by SharpDevelop. ' User: simpsont ' Date: 11/11/2005 ' Time: 9:13 AM ' ' To change this template use Tools | Options | Coding | Edit Standard Headers. ' Public Class MainForm Inherits System.Windows.Forms.Form Private processCaller As ProcessCaller Public Sub New() ' ' The Me.InitializeComponent call is required for Windows Forms designer support. ' Me.InitializeComponent ' ' TODO : Add constructor code after InitializeComponents ' AddHandler Me.Closing, AddressOf Me_OnClosing End Sub #Region " Windows Forms Designer generated code " ' This method is required for Windows Forms designer support. ' Do not change the method contents inside the source code editor. The Forms designer might ' not be able to load this method if it was changed manually. Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container Me.ctxWhatsThis = New System.Windows.Forms.ContextMenuStrip(Me.components) Me.whatsThisToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem Me.btnChangeSize = New System.Windows.Forms.Button Me.lblDest = New System.Windows.Forms.Label Me.btnSelectDest = New System.Windows.Forms.Button Me.btnCancel = New System.Windows.Forms.Button Me.label1 = New System.Windows.Forms.Label Me.linkLabel1 = New System.Windows.Forms.LinkLabel Me.tabControl1 = New System.Windows.Forms.TabControl Me.tabPage1 = New System.Windows.Forms.TabPage Me.txtNewSize = New System.Windows.Forms.TextBox Me.label2 = New System.Windows.Forms.Label Me.txtOutput = New System.Windows.Forms.TextBox Me.btnExit = New System.Windows.Forms.Button Me.statusStrip1 = New System.Windows.Forms.StatusStrip Me.StatusLabel1 = New System.Windows.Forms.ToolStripStatusLabel Me.ProgressBar1 = New System.Windows.Forms.ToolStripProgressBar Me.helpProvider1 = New System.Windows.Forms.HelpProvider Me.openFileDialog1 = New System.Windows.Forms.OpenFileDialog Me.ctxWhatsThis.SuspendLayout Me.tabControl1.SuspendLayout Me.tabPage1.SuspendLayout Me.statusStrip1.SuspendLayout Me.SuspendLayout ' 'ctxWhatsThis ' Me.ctxWhatsThis.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.whatsThisToolStripMenuItem}) Me.ctxWhatsThis.Name = "ctxWhatsThis" Me.helpProvider1.SetShowHelp(Me.ctxWhatsThis, false) Me.ctxWhatsThis.Size = New System.Drawing.Size(146, 26) Me.ctxWhatsThis.Text = "What's This?" ' 'whatsThisToolStripMenuItem ' Me.whatsThisToolStripMenuItem.Name = "whatsThisToolStripMenuItem" Me.whatsThisToolStripMenuItem.Size = New System.Drawing.Size(145, 22) Me.whatsThisToolStripMenuItem.Text = "What's This?" ' 'btnChangeSize ' Me.btnChangeSize.Enabled = false Me.btnChangeSize.Location = New System.Drawing.Point(0, 225) Me.btnChangeSize.Name = "btnChangeSize" Me.btnChangeSize.Size = New System.Drawing.Size(96, 23) Me.btnChangeSize.TabIndex = 2 Me.btnChangeSize.Text = "Change Size" Me.btnChangeSize.UseCompatibleTextRendering = true Me.btnChangeSize.UseVisualStyleBackColor = true AddHandler Me.btnChangeSize.Click, AddressOf Me.BtnChangeSizeClick ' 'lblDest ' Me.lblDest.AllowDrop = true Me.lblDest.AutoEllipsis = true Me.lblDest.BackColor = System.Drawing.Color.Transparent Me.lblDest.Location = New System.Drawing.Point(36, 9) Me.lblDest.Name = "lblDest" Me.lblDest.Size = New System.Drawing.Size(261, 52) Me.lblDest.TabIndex = 3 Me.lblDest.Text = "Select the VMWare Virtual Disk Drive" Me.lblDest.UseCompatibleTextRendering = true ' 'btnSelectDest ' Me.helpProvider1.SetHelpString(Me.btnSelectDest, "The new ISO file to output.") Me.btnSelectDest.Location = New System.Drawing.Point(3, 6) Me.btnSelectDest.Name = "btnSelectDest" Me.helpProvider1.SetShowHelp(Me.btnSelectDest, true) Me.btnSelectDest.Size = New System.Drawing.Size(27, 23) Me.btnSelectDest.TabIndex = 4 Me.btnSelectDest.Text = "..." Me.btnSelectDest.UseCompatibleTextRendering = true Me.btnSelectDest.UseVisualStyleBackColor = true ' 'btnCancel ' Me.btnCancel.Enabled = false Me.btnCancel.Location = New System.Drawing.Point(129, 225) Me.btnCancel.Name = "btnCancel" Me.btnCancel.Size = New System.Drawing.Size(75, 23) Me.btnCancel.TabIndex = 6 Me.btnCancel.Text = "Cancel" Me.btnCancel.UseCompatibleTextRendering = true Me.btnCancel.UseVisualStyleBackColor = true ' 'label1 ' Me.label1.Location = New System.Drawing.Point(109, 286) Me.label1.Name = "label1" Me.label1.Size = New System.Drawing.Size(183, 23) Me.label1.TabIndex = 7 Me.label1.Text = "Copyright © Troy Simpson 2005" Me.label1.UseCompatibleTextRendering = true ' 'linkLabel1 ' Me.linkLabel1.Location = New System.Drawing.Point(288, 286) Me.linkLabel1.Name = "linkLabel1" Me.linkLabel1.Size = New System.Drawing.Size(148, 23) Me.linkLabel1.TabIndex = 8 Me.linkLabel1.TabStop = true Me.linkLabel1.Text = "http://www.ebswift.com" Me.linkLabel1.UseCompatibleTextRendering = true AddHandler Me.linkLabel1.LinkClicked, AddressOf Me.LinkLabel1LinkClicked ' 'tabControl1 ' Me.tabControl1.Controls.Add(Me.tabPage1) Me.tabControl1.Location = New System.Drawing.Point(3, 3) Me.tabControl1.Name = "tabControl1" Me.tabControl1.SelectedIndex = 0 Me.tabControl1.Size = New System.Drawing.Size(689, 280) Me.tabControl1.TabIndex = 9 ' 'tabPage1 ' Me.tabPage1.BackColor = System.Drawing.SystemColors.ControlLightLight Me.tabPage1.Controls.Add(Me.txtNewSize) Me.tabPage1.Controls.Add(Me.label2) Me.tabPage1.Controls.Add(Me.txtOutput) Me.tabPage1.Controls.Add(Me.lblDest) Me.tabPage1.Controls.Add(Me.btnCancel) Me.tabPage1.Controls.Add(Me.btnSelectDest) Me.tabPage1.Controls.Add(Me.btnChangeSize) Me.tabPage1.Location = New System.Drawing.Point(4, 22) Me.tabPage1.Name = "tabPage1" Me.tabPage1.Padding = New System.Windows.Forms.Padding(3) Me.tabPage1.Size = New System.Drawing.Size(681, 254) Me.tabPage1.TabIndex = 0 Me.tabPage1.Text = "Change VMWare Disk Size" Me.tabPage1.UseVisualStyleBackColor = true ' 'txtNewSize ' Me.txtNewSize.Location = New System.Drawing.Point(92, 94) Me.txtNewSize.Name = "txtNewSize" Me.txtNewSize.Size = New System.Drawing.Size(85, 21) Me.txtNewSize.TabIndex = 9 ' 'label2 ' Me.label2.BackColor = System.Drawing.Color.Transparent Me.label2.Location = New System.Drawing.Point(6, 94) Me.label2.Name = "label2" Me.label2.Size = New System.Drawing.Size(100, 23) Me.label2.TabIndex = 8 Me.label2.Text = "New Size (GB):" Me.label2.UseCompatibleTextRendering = true ' 'txtOutput ' Me.txtOutput.Location = New System.Drawing.Point(321, 6) Me.txtOutput.Multiline = true Me.txtOutput.Name = "txtOutput" Me.txtOutput.ReadOnly = true Me.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical Me.txtOutput.Size = New System.Drawing.Size(354, 242) Me.txtOutput.TabIndex = 7 Me.txtOutput.Text = "VMDiskSize Alpha 1.0.0"&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)&"Copyright © Troy Simpson 2005"&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)&"http://www.ebswift.com"&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)& _ ""&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)&"Licensed under the GPL"&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)&"Contains code from Mike Mayer" ' 'btnExit ' Me.btnExit.Location = New System.Drawing.Point(3, 281) Me.btnExit.Name = "btnExit" Me.btnExit.Size = New System.Drawing.Size(75, 23) Me.btnExit.TabIndex = 10 Me.btnExit.Text = "Exit" Me.btnExit.UseCompatibleTextRendering = true Me.btnExit.UseVisualStyleBackColor = true ' 'statusStrip1 ' Me.statusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.StatusLabel1, Me.ProgressBar1}) Me.statusStrip1.Location = New System.Drawing.Point(0, 309) Me.statusStrip1.Name = "statusStrip1" Me.statusStrip1.Size = New System.Drawing.Size(693, 22) Me.statusStrip1.SizingGrip = false Me.statusStrip1.TabIndex = 11 Me.statusStrip1.Text = "statusStrip1" ' 'StatusLabel1 ' Me.StatusLabel1.Name = "StatusLabel1" Me.StatusLabel1.Size = New System.Drawing.Size(162, 17) Me.StatusLabel1.Text = "Awaiting Source and Destination" ' 'ProgressBar1 ' Me.ProgressBar1.Name = "ProgressBar1" Me.ProgressBar1.Size = New System.Drawing.Size(100, 16) Me.ProgressBar1.Visible = false ' 'openFileDialog1 ' Me.openFileDialog1.DefaultExt = "vmdx" Me.openFileDialog1.Filter = "VMWare Disk Images|*.vmdk" ' 'MainForm ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6!, 13!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(693, 331) Me.Controls.Add(Me.statusStrip1) Me.Controls.Add(Me.btnExit) Me.Controls.Add(Me.tabControl1) Me.Controls.Add(Me.linkLabel1) Me.Controls.Add(Me.label1) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog Me.HelpButton = true Me.MaximizeBox = false Me.MinimizeBox = false Me.Name = "MainForm" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Change VMWare Disk Size" Me.ctxWhatsThis.ResumeLayout(false) Me.tabControl1.ResumeLayout(false) Me.tabPage1.ResumeLayout(false) Me.tabPage1.PerformLayout Me.statusStrip1.ResumeLayout(false) Me.statusStrip1.PerformLayout Me.ResumeLayout(false) Me.PerformLayout End Sub Private ProgressBar1 As System.Windows.Forms.ToolStripProgressBar Private WithEvents txtNewSize As System.Windows.Forms.TextBox Private label2 As System.Windows.Forms.Label Private openFileDialog1 As System.Windows.Forms.OpenFileDialog Private txtOutput As System.Windows.Forms.TextBox Private WithEvents whatsThisToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem Private ctxWhatsThis As System.Windows.Forms.ContextMenuStrip Private ContextMenuStrip As System.Windows.Forms.ToolStripMenuItem Private helpProvider1 As System.Windows.Forms.HelpProvider Private StatusLabel1 As System.Windows.Forms.ToolStripStatusLabel Private statusStrip1 As System.Windows.Forms.StatusStrip Private WithEvents btnExit As System.Windows.Forms.Button Private tabPage1 As System.Windows.Forms.TabPage Private tabControl1 As System.Windows.Forms.TabControl Private linkLabel1 As System.Windows.Forms.LinkLabel Private label1 As System.Windows.Forms.Label Private WithEvents btnCancel As System.Windows.Forms.Button Private WithEvents btnSelectDest As System.Windows.Forms.Button Private WithEvents lblDest As System.Windows.Forms.Label Private btnChangeSize As System.Windows.Forms.Button Private components As System.ComponentModel.IContainer #End Region Sub BtnSelectDestClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSelectDest.Click openFileDialog1.ShowDialog() lblDest.Text = openFileDialog1.FileName showChangeSizeButton() End Sub Sub showChangeSizeButton() If txtNewSize.Text <> "" And openFileDialog1.FileName <> "" Then BtnChangeSize.Enabled = True End If End Sub Sub BtnCancelClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click If (Not processCaller Is Nothing) Then processCaller.Cancel() End If End Sub ''' ''' Handles the events of StdOutReceived. ''' ''' ''' Private Sub writeStreamInfo(ByVal sender As Object, ByVal e As DataReceivedEventArgs) Dim tmpstr As String If sender.cancelledFlag Or sender.failedFlag Then Exit Sub End If If InStr(e.Text, "Grow:") Then If StatusLabel1.Text <> "Working, Please Wait..." Then StatusLabel1.Text = "Working, Please Wait..." End If tmpstr = Mid(LTrim(e.Text), InStr(LTrim(e.Text), " ") + 1) tmpstr = Mid(tmpstr, 1, InStr(tmpstr, "%") - 1) ProgressBar1.Value = tmpstr Else StatusLabel1.Text = e.Text End If End Sub ''' ''' Handles the events of processCompleted & processCanceled ''' Private Sub processCompletedOrCanceled(ByVal sender As Object, ByVal e As EventArgs) Me.Cursor = Cursors.Default Me.btnChangeSize.Enabled = True Me.btnCancel.Enabled = False Me.ProgressBar1.Visible = False If sender.cancelledflag Then StatusLabel1.Text = "User Cancelled" ElseIf sender.failedFlag Then StatusLabel1.Text = "Operation Failed" ElseIf sender.completeFlag Then StatusLabel1.Text = "Operation completed successfully" End If End Sub Sub BtnExitClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub Sub Me_OnClosing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) If (Not processCaller Is Nothing) Then processCaller.Cancel() End If End Sub Sub LinkLabel1LinkClicked(sender As Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Process.Start("http://www.ebswift.com") End Sub ' this is a helper for getting the file/folder for destination ' if the user chooses to drag a folder location it will be used ' in the folder dialog. If they drag a file it will be used for output. Sub lblDestDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDest.DragDrop mybase.OnDragDrop(e) Dim data As String() = e.Data.GetData(DataFormats.FileDrop) Dim s As String For Each s In data ' stop on the first valid file/folder found lblDest.Text = s openFileDialog1.FileName = s BtnSelectDestClick(Nothing, Nothing) Exit For Next End Sub Sub lblDestDragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDest.DragEnter mybase.OnDragEnter(e) Dim data As String() = e.Data.GetData(DataFormats.FileDrop) Dim s As String For Each s In data ' stop on the first valid file/folder found e.Effect = DragDropEffects.Copy Exit For Next End Sub Sub txtNewSizeTextChanged(sender As Object, e As System.EventArgs) Handles txtNewSize.TextChanged showChangeSizeButton() End Sub Sub BtnChangeSizeClick(sender As Object, e As System.EventArgs) Dim toRun As String StatusLabel1.Text = "Changing VMWare Disk Size..." ProgressBar1.Visible = True btnCancel.Enabled = True toRun = "C:\Program Files\VMware\VMware Workstation\vmware-vdiskmanager.exe" Me.Cursor = Cursors.AppStarting Me.btnChangeSize.Enabled = False processCaller = New ProcessCaller(Me) processCaller.FileName = "" + toRun processCaller.WorkingDirectory = "C:\Program Files\VMware\VMware Workstation\" processCaller.Arguments = "-x " & txtNewSize.Text & "GB " & chr(34) & lblDest.Text & chr(34) AddHandler processCaller.StdErrReceived, AddressOf writeStreamInfo AddHandler processCaller.StdOutReceived, AddressOf writeStreamInfo AddHandler processCaller.Completed, AddressOf processCompletedOrCanceled AddHandler processCaller.Cancelled, AddressOf processCompletedOrCanceled ' the following function starts a process and returns immediately, ' thus allowing the form to stay responsive. processCaller.Start() End Sub End Class