TokkieGPT - C# Application

 How to create a C# command line application to launch ChatGPT on Windows



Devnote about this Task: (This demonstrates that such a tool can be entirely coded by ChatGPT with a bit of creative prompting and a few kicks in the butt)

Create a C# script for a console app named "TokkieGPT"
The script should play a sound file named "MagicSound.wav"
The script should open a website at "https://chat.openai.com"
The console window should appear in the center of the screen with a note "Creating a Super Intelligence..." and pause for 5 seconds then auto continues
During the pause part, show the progress percentage as an ASCII progress bar

Solution:
To solve this task, we used C# language and implemented several functionalities such as playing a sound file, opening a website, and displaying a message with progress using ASCII characters.

First, we imported the required namespaces such as System, System.Diagnostics, and System.Runtime.InteropServices.

Next, we defined a PlaySound method using the PlaySound function from the winmm.dll library. We used this function to play the "MagicSound.wav" file.

After that, we defined an OpenWebsite method using the Process.Start function to open the "https://chat.openai.com" URL in the default web browser.

To display a progress message, we used a for loop with a 1-second delay between each iteration. Inside the loop, we calculated the progress percentage and printed it to the console using ASCII characters to represent a progress bar. We also displayed the "Creating a Super Intelligence..." message at the center of the console window.

Finally, we called the PlaySound, OpenWebsite, and ShowProgress methods in the Main method, which runs the program.

We also made some improvements such as setting the console window size dynamically based on the size of the message and progress bar, and displaying the console window at the center of the screen.

Overall, this solution provides a simple and effective way to play a sound file, open a website, and display a progress message in a console window.

-----------------------------------------------------------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace TokkieGPT
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Creating a Super Intelligence...");
            for (int i = 1; i <= 5; i++)
            {
                Console.Write($"Progress: {20 * i}% ");
                System.Threading.Thread.Sleep(1000);
                Console.Write(new string('█', 20 * i / 5) + "\r");
            }

            Console.WriteLine("\nLaunching TokkieGPT...");
            PlaySound("MagicSound.wav");
            OpenWebsite("https://chat.openai.com");
        }

        static void PlaySound(string soundFilePath)
        {
            try
            {
                PlaySound(soundFilePath, IntPtr.Zero, 0x20000);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error playing sound: {ex.Message}");
            }
        }

        [DllImport("winmm.dll")]
        private static extern bool PlaySound(string fileName, IntPtr hMod, uint flags);

        static void OpenWebsite(string url)
        {
            try
            {
                Process.Start(new ProcessStartInfo
                {
                    FileName = url,
                    UseShellExecute = true
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error opening URL: {ex.Message}");
            }
        }
    }
}


Comments

Popular posts from this blog

Clone Command Bar Button in Model Driven App: Order & OrderDetails

Model-Driven Apps: Modern Command Bar Customization

Knowledge shared is power squared!