Jump to content

Prints a char normally, but full string when debugged.

Tech N Gamer

So for some reason, when it run's normally, my program will print the first string it get's as a single char, but as soon as it's in debug mode and hits the breakpoint, it writes the entire string into the console. I am finding this to be annoying, can anyone help? The .cs file will be attached to this post.

Program.cs

Brah, do you even Java?

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, fizzlesticks said:

Please copy/paste the code into your post using code tags.

I did link it to download, but if you want it in the code tags (if you want the whole 170 lines in a post, just tell me):

static void PrintInstallerName( string name, int installNumber ) {
	installNumber = installNumber % ( Console.WindowHeight - 1 );
	//Checks to see if it has the full name of the installer and if so, isolate the name.
	if ( name.Contains( Path.DirectorySeparatorChar ) ) {
		name = name.Substring( name.LastIndexOf( Path.DirectorySeparatorChar ) + 1 );
		int length = Console.WindowWidth - name.Length;
		while(length > 0 ) {
			name = name + " ";
			length--;
		}
	}
	//Set's the console cursor to the point of printing it.
	Console.SetCursorPosition( 0, installNumber );
	//Prints the executables name to the console.
	Console.Write( name );
}

 

Brah, do you even Java?

Link to comment
Share on other sites

Link to post
Share on other sites

10 hours ago, Tech N Gamer said:

I did link it to download

Most people don't like downloading random files posted online.

Quote

if you want the whole 170 lines in a post, just tell me

Go ahead and do that, I tried the function you posted and it seems to work fine for me both while debugging and not.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, fizzlesticks said:

Most people don't like downloading random files posted online.

Go ahead and do that, I tried the function you posted and it seems to work fine for me both while debugging and not.

Have you tried it when it's in a subdirectory, I'm just trying to think of all possibilities.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Diagnostics;

namespace Installer {
	class Program {
		//Set's the current working directory to the program's unless specified below.
		static string cwd = Environment.CurrentDirectory;

		static void Main( string[] args ) {
			//Set's up the console to a better way.
			SetUpConsole();
			//Read it's comment lazy ass.
			ArgsSetup( args );
			//Get's the stack from the GetInstallers method and uses the cwd.
			Stack<string> executables = GetInstallers( );
			//Total is how many were in the stack before the programs went poppen out.
			int done = 0, total = 0;

			total = executables.Count;
			//Set's the varible up for usage.
			ProcessStartInfo program = new ProcessStartInfo();
			Process currentProgram = new Process();
			//Itterates throught the stack, popping them off after they have been executed and finished.
			while ( executables.Count > 0 ) {

				program.FileName = executables.Pop();

				PrintInstallerName( program.FileName, done );

				DrawTextBar( done, total );

				try {
					currentProgram = Process.Start( program );

					while ( currentProgram != null && !currentProgram.HasExited ) {
						Thread.Sleep( 25 );
					}
				} catch (Exception e ) {
					
				}

				done++;
			}

			Console.Beep();
			Console.Write( "Process is done! Press any key to close." );
			while(Console.ReadKey() == null ) {

			}

			Environment.Exit( 0 );
		}
		//Goes through the arguments to see if any has been passed.
		static void ArgsSetup( string[] args ) {
			for ( int i = 0; i < args.Length; i++ ) {
				if ( args[ i ].Contains( "=" ) ) {
					string[] argI = args[ i ].Split( '=' );

					if ( argI[ 0 ].ToLower().Equals( "--path" ) ) {
						try {
							if ( ( File.GetAttributes( argI[ 1 ] ) & FileAttributes.Directory ) == FileAttributes.Directory ) {
								cwd = argI[ 1 ];
							}
						} catch (Exception e ) {
							Console.Write( "Invalid path, please make sure you typed it in correctly." );
							Console.Beep( 3000, 750 );
							Thread.Sleep( TimeSpan.FromMinutes(0.75) );
							Environment.Exit( -1 );
						}
					}
				}
			}
		}

		static Stack<string> GetInstallers( string path = null ) {
			//Checks to see if the path is null, and if so, assign it to the cwd.
			if(path == null ) {
				path = cwd;
			}

			Stack<string> executables = new Stack<string>();
			//Itterates over the insides of a directory for installer files.
			foreach ( string file in Directory.GetFileSystemEntries( path ) ) {
				//Checks to make sure that it doesn't add itself to the list.
				if ( !file.Substring( file.LastIndexOf( "\\" ) + 1 ).Equals( "Installer.exe" ) ) {
					/*
					 * Can we all agree not to capitalize the extention, please? It's so stupid and annoying.
					 * It's like, "Oh hey, you know what the most dumbass thing to do is, is to capitalize the extention so that way it's totally inconsistant and makes programmers do slightly more work."
					 * Yeah, fuck those guys.
					 * And if any of you dumbasses out there read this, DON'T FUCKING DO IT! It's stupid, pointless, and adds a tad bit more work to check to make sure it's lowercase. Like goddamn, lowecase extentions just look nicer, .exe looks way better than .EXE or .app looks better than .APP.
					 */
					string fileLower = file.ToLower();
					//Checks to see if it's a .exe or .msi and if so, add it to the stack other wise, check to see if it's a directory.
					if ( fileLower.EndsWith( ".exe" ) || fileLower.EndsWith( ".msi" ) ) {
						executables.Push( file );
					}
					else if ( ( File.GetAttributes( file ) & FileAttributes.Directory ) == FileAttributes.Directory ) {
						//Goes and recalls this method to gather all the files from it and store it in this stack.
						foreach ( string file2 in GetInstallers( file ) ) {
							executables.Push( file2 );
						}
					}
				}
			}
			//Returns the Stack of executable installers.
			return executables;
		}
		#region ConsoleOutputMethods
		static void SetUpConsole() {
			//Removes the cursor.
			Console.CursorVisible = false;
			//Sets the color of the console.
			Console.BackgroundColor = ConsoleColor.Black;
			Console.ForegroundColor = ConsoleColor.Red;
			//Set's the console's width and height.
			Console.BufferHeight = Console.WindowHeight + 1;
			Console.BufferWidth = Console.WindowWidth;
		}

		static void DrawTextBar( int progress, int total, char loadSymbol = '#', char unloadSymbol = '-' ) {
			//Checks to make sure load and unload symbols are not the same.
			if ( loadSymbol == unloadSymbol ) {
				throw new Exception( "Load and Unload symbols cannot be the same. It will confuse the user and is bad design." );
			}
			//Last visiable line of the console.
			int visableLine = Console.WindowTop + Console.WindowHeight - 1;
			//Draws the empty progress bar.
			Console.SetCursorPosition( 0, visableLine );
			StringBuilder builder = new StringBuilder( "[" );
			//Draws the loaded symbol.
			int loadTo = (int)( Console.BufferWidth * ( progress / (float)total ) );
			for ( int i = 1; i < Console.BufferWidth - 1; i++ ) {
				if ( i <= loadTo ) {
					builder.Append( loadSymbol );
				}
				else {
					builder.Append( unloadSymbol );
				}
			}
			//Draws the end of the bar.
			builder.Append( "]" );
			Console.Write( builder.ToString() );
			//I DON'T KNOW HOW TO STOP THE COMMAND PROMPT FORM GOING TO THE NEXT LINE! SO I have to do this hack.
			Console.SetCursorPosition( 0, 0 );
		}

		static void PrintInstallerName( string name, int installNumber ) {
			installNumber = installNumber % ( Console.WindowHeight - 1 );
			//Checks to see if it has the full name of the installer and if so, isolate the name.
			if ( name.Contains( Path.DirectorySeparatorChar ) ) {
				name = name.Substring( name.LastIndexOf( Path.DirectorySeparatorChar ) + 1 );
				int length = Console.WindowWidth - name.Length;
				while(length > 0 ) {
					name = name + " ";
					length--;
				}
			}
			//Set's the console cursor to the point of printing it.
			Console.SetCursorPosition( 0, installNumber );
			//Prints the executables name to the console.
			Console.Write( name );
		}
		#endregion
	}
}

Sorry for that little rant in the middle of the program in the comments.

Brah, do you even Java?

Link to comment
Share on other sites

Link to post
Share on other sites

11 minutes ago, Tech N Gamer said:

Have you tried it when it's in a subdirectory, I'm just trying to think of all possibilities.

Yup tried that. Are you able to reproduce the bug by just calling that 1 function with a hardcoded string? 

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, fizzlesticks said:

Yup tried that. Are you able to reproduce the bug by just calling that 1 function with a hardcoded string? 

I'll try in the morning, right now I'm preparing to sleep.

Brah, do you even Java?

Link to comment
Share on other sites

Link to post
Share on other sites

On 9/16/2017 at 11:47 PM, fizzlesticks said:

Yup tried that. Are you able to reproduce the bug by just calling that 1 function with a hardcoded string? 

Sorry for the long wait, probably also breaking a forum rule here, but I wanted to inform you that after building the program, it doesn't do that single char thing, however, it does make a double progress bar 1 time. However, that did seem to be a one-time thing.

Brah, do you even Java?

Link to comment
Share on other sites

Link to post
Share on other sites

Regarding the capitalisation of file format extensions, I guess that's kindOfLikeCamelCase. I prefer not to be bothered by it; when we allow ourselves to be so easily upset, we heighten the risk of heart attacks and other forms of physical harm. There's no need to be that bothered, right? I suggest anger management...

Regarding your question, it isn't entirely clear what the problem is. You say a char is being printed... Which char? We can't see it. You say you expect a string... Which string? Again, we can't see it! This information would help us to help you get a quick answer. 

In a striking twist of character, you seem to have developed a preference for CAPITALISATION!
 

Quote

//I DON'T KNOW HOW TO STOP THE COMMAND PROMPT FORM GOING TO THE NEXT LINE! SO I have to do this hack.


Do you want us to respond to that? It seems like it could be relevant (shame it wasn't in the question), as you're technically not guaranteed to `Write` as many bytes as `SetCursorPosition` have seeked back over...

Yet it also seems that a programmer should seek out his own research, and you wouldn't believe what I found in the second result of a search for "how to stop command prompt from going to the next line in C#":
 

Quote

Notice the few spaces after the number to make sure that whatever was there before is erased


I reckon this is your EUREKA MOMENT! CAN WE USE CAPITALS TO EXPRESS OUR EXCITEMENT? This might resolve your phenomena, but even if it doesn't, it's certainly something you'd want to fix...

Let us not forget, when the words "see attached" are found, one should ALWAYS open WHACKA~1.EXE.

Link to comment
Share on other sites

Link to post
Share on other sites

24 minutes ago, Sebivor said:

Regarding the capitalisation of file format extensions, I guess that's kindOfLikeCamelCase. I prefer not to be bothered by it; when we allow ourselves to be so easily upset, we heighten the risk of heart attacks and other forms of physical harm. There's no need to be that bothered, right? I suggest anger management...

Regarding your question, it isn't entirely clear what the problem is. You say a char is being printed... Which char? We can't see it. You say you expect a string... Which string? Again, we can't see it! This information would help us to help you get a quick answer. 

In a striking twist of character, you seem to have developed a preference for CAPITALISATION!
 


Do you want us to respond to that? It seems like it could be relevant (shame it wasn't in the question), as you're technically not guaranteed to `Write` as many bytes as `SetCursorPosition` have seeked back over...

Yet it also seems that a programmer should seek out his own research, and you wouldn't believe what I found in the second result of a search for "how to stop command prompt from going to the next line in C#":
 


I reckon this is your EUREKA MOMENT! CAN WE USE CAPITALS TO EXPRESS OUR EXCITEMENT? This might resolve your phenomena, but even if it doesn't, it's certainly something you'd want to fix...

Let us not forget, when the words "see attached" are found, one should ALWAYS open WHACKA~1.EXE.

First off, I found this to be very funny. Second, it would be a random char, like 'A' or 'B' when it's something like "Android Studio.exe". Third, that "hack" I did is good enough. I'm not releasing it to be used on mass.

Brah, do you even Java?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×