3030using System . Net ;
3131using System . IO . Compression ;
3232using System . Drawing ;
33+ using ORTS . Common ;
3334
3435namespace ORTS
3536{
@@ -131,8 +132,8 @@ private void dataGridViewDownloadContent_SelectionChanged(object sender, EventAr
131132 }
132133 #endregion
133134
134- #region InstallPathButton
135- private void InstallPathButton_Click ( object sender , EventArgs e )
135+ #region InstallPathBrowseButton
136+ private void InstallPathBrowseButton_Click ( object sender , EventArgs e )
136137 {
137138 using ( FolderBrowserDialog folderBrowser = new FolderBrowserDialog ( ) )
138139 {
@@ -151,13 +152,33 @@ private void InstallPathButton_Click(object sender, EventArgs e)
151152 private void DownloadContentButton_Click ( object sender , EventArgs e )
152153 {
153154 string installPath = InstallPathTextBox . Text ;
155+ if ( installPath . EndsWith ( @"\" ) )
156+ {
157+ installPath = installPath . Remove ( installPath . Length - 1 , 1 ) ;
158+ }
159+ installPath = Path . GetFullPath ( installPath ) ;
160+
154161 string installPathRoute = Path . Combine ( installPath , RouteName ) ;
155162 string message ;
156163
157164 DisableButtons ( ) ;
158165
159166 // various checks for the directory where the route is installed
160167
168+ string pathDirectoryExe = System . IO . Path . GetDirectoryName ( System . Reflection . Assembly . GetExecutingAssembly ( ) . GetName ( ) . CodeBase ) ;
169+
170+ string topPathDirectoryExe = DirectoryAndFiles . determineTopDirectory ( pathDirectoryExe . Substring ( 6 ) ) ;
171+ string topInstallPath = DirectoryAndFiles . determineTopDirectory ( installPath ) ;
172+
173+ if ( topPathDirectoryExe . Equals ( topInstallPath , StringComparison . OrdinalIgnoreCase ) )
174+ {
175+ message = Catalog . GetStringFmt ( "Top directory {0} is the same for exe and route, installing in this directory not allowed" , topInstallPath ) ;
176+ MessageBox . Show ( message , Catalog . GetString ( "Attention" ) , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
177+ // cancelled
178+ EnableButtons ( ) ;
179+ return ;
180+ }
181+
161182 DriveInfo dInfo = new DriveInfo ( installPathRoute ) ;
162183
163184 long size = Routes [ RouteName ] . InstallSize + Routes [ RouteName ] . DownloadSize ;
@@ -600,14 +621,15 @@ void StartButton_Click(object sender, EventArgs e)
600621 Cursor . Current = Cursors . WaitCursor ;
601622
602623 RouteSettings . Route route = Routes [ RouteName ] ;
624+ string contentName = route . ContentName ;
603625 MainForm mainForm = ( ( MainForm ) Owner ) ;
604626
605627 mainForm . DoWithTask = false ;
606628
607629 try
608630 {
609631 mainForm . LoadFolderList ( ) ;
610- mainForm . comboBoxFolder . SelectedIndex = determineSelectedIndex ( mainForm . comboBoxFolder , RouteName ) ;
632+ mainForm . comboBoxFolder . SelectedIndex = determineSelectedIndex ( mainForm . comboBoxFolder , contentName ) ;
611633
612634 mainForm . LoadRouteList ( ) ;
613635 mainForm . comboBoxRoute . SelectedIndex = determineSelectedIndex ( mainForm . comboBoxRoute , route . Start . Route ) ;
@@ -739,7 +761,7 @@ void DeleteButton_Click(object sender, EventArgs e)
739761 }
740762 Cursor . Current = Cursors . WaitCursor ;
741763
742- directoryDelete ( Routes [ RouteName ] . DirectoryInstalledIn ) ;
764+ DirectoryAndFiles . directoryDelete ( Routes [ RouteName ] . DirectoryInstalledIn ) ;
743765
744766 if ( Settings . Folders . Folders [ Routes [ RouteName ] . ContentName ] == Routes [ RouteName ] . ContentDirectory )
745767 {
@@ -757,28 +779,6 @@ void DeleteButton_Click(object sender, EventArgs e)
757779
758780 EnableButtons ( ) ;
759781 }
760-
761- private void directoryDelete ( string directoryName )
762- {
763- if ( Directory . Exists ( directoryName ) )
764- {
765- directoryRemoveReadOnlyFlags ( directoryName ) ;
766- Directory . Delete ( directoryName , true ) ;
767- }
768- }
769-
770- private void directoryRemoveReadOnlyFlags ( string directoryName )
771- {
772- foreach ( string filename in Directory . GetFiles ( directoryName ) )
773- {
774- FileInfo file = new FileInfo ( filename ) ;
775- file . IsReadOnly = false ;
776- }
777- foreach ( string subDirectoryName in Directory . GetDirectories ( directoryName ) )
778- {
779- directoryRemoveReadOnlyFlags ( subDirectoryName ) ;
780- }
781- }
782782 #endregion
783783
784784 private void DisableButtons ( )
0 commit comments