Guest User

Untitled

a guest
Sep 16th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Cosmos.Hardware;
  6. using Cosmos.Hardware.BlockDevice;
  7. using GruntyOS.HAL;
  8. using GruntyOS.IO;
  9.  
  10. namespace InfinityOS.Application
  11. {
  12.     class Setup
  13.     {
  14.  
  15.         public static void Init()
  16.         {
  17.             Console.CursorLeft = 0;
  18.             Console.BackgroundColor = ConsoleColor.DarkBlue;
  19.  
  20.             Console.Clear();
  21.             fill(ConsoleColor.DarkBlue, 0, 85, 0, 26);
  22.             Console.CursorTop = 0;
  23.             Console.ForegroundColor = ConsoleColor.White;
  24.             Console.BackgroundColor = ConsoleColor.DarkRed;
  25.  
  26.             Console.WriteLine("GruntyOS Setup Wizard - Step 1: Pick a partition.                               ");
  27.             Console.BackgroundColor = ConsoleColor.DarkBlue;
  28.             List<string> parts = new List<string>();
  29.             List<Partition> partitions = new List<Partition>();
  30.             int d = 1;
  31.             for (int i = 0; i < BlockDevice.Devices.Count; i++)
  32.             {
  33.                 BlockDevice xDevice = BlockDevice.Devices[i];
  34.                 if (xDevice is Partition)
  35.                 {
  36.                     parts.Add("/dev/sda" + d.ToString());
  37.                     partitions.Add((Partition)xDevice);
  38.                     d++;
  39.                 }
  40.             }
  41.             fill(ConsoleColor.Gray, 15, 40, 4, 13);
  42.             Console.CursorLeft = 15;
  43.             Console.CursorTop = 4;
  44.             Console.BackgroundColor = ConsoleColor.Gray;
  45.             Console.ForegroundColor = ConsoleColor.Black;
  46.             Console.WriteLine("Please choose a partition");
  47.             uint selected = Menu(parts.ToArray(), 15, 5);
  48.  
  49.             fill(ConsoleColor.Gray, 15, 40, 4, 13);
  50.             Console.CursorTop = 0;
  51.             Console.ForegroundColor = ConsoleColor.White;
  52.             Console.BackgroundColor = ConsoleColor.DarkRed;
  53.             Console.WriteLine("GruntyOS Setup Wizard - Step 2: Create an account                               ");
  54.  
  55.             Console.BackgroundColor = ConsoleColor.Gray;
  56.             Console.ForegroundColor = ConsoleColor.Black;
  57.             Console.CursorLeft = 15;
  58.             Console.CursorTop = 4;
  59.             Console.WriteLine("Please create an account");
  60.             Console.CursorLeft = 15;
  61.             Console.CursorTop = 6;
  62.             Console.WriteLine("Password:");
  63.             Console.CursorTop = 5;
  64.             Console.CursorLeft = 15;
  65.             Console.Write("Username:");
  66.             string User = Console.ReadLine();
  67.             Console.CursorLeft = 15;
  68.             Console.Write("Password:");
  69.             string Pass = Console.ReadLine();
  70.             GLNFS fd = new GLNFS(partitions.ToArray()[selected]);
  71.             Console.BackgroundColor = ConsoleColor.Blue;
  72.             Console.Clear();
  73.             Console.CursorTop = 0;
  74.             Console.ForegroundColor = ConsoleColor.White;
  75.             Console.BackgroundColor = ConsoleColor.DarkRed;
  76.             Console.WriteLine("GruntyOS Setup Wizard - Step 3: Installing Grunty OS                            ");
  77.  
  78.             Console.BackgroundColor = ConsoleColor.Blue;
  79.             Console.ForegroundColor = ConsoleColor.White;
  80.             Console.WriteLine("Formating selected partition to GLNFS..");
  81.             GruntyOS.CurrentUser.Username = "System";
  82.             fd.Format("GruntyOS");
  83.             Console.WriteLine("Creating Directory /bin/");
  84.             fd.makeDir("bin");
  85.             Console.WriteLine("Creating Directory /etc/");
  86.             Console.WriteLine("Creating Directory /usr/");
  87.             fd.makeDir("usr");
  88.             Console.WriteLine("Creating Directory /usr/include/");
  89.             fd.makeDir("/usr/include");
  90.             Console.WriteLine("Creating Directory /usr/doc/");
  91.             fd.makeDir("/usr/doc");
  92.             File.Save("usr/doc/readme.txt", @"Welcome to Grunty OS! A Cosmos based OS. The primary UI for Grunty OS is command line shell called 'GSHELL' , but
  93. GruntyOS does offer a GUI. You can access this GUI by typing 'GUI'. The command line shell has similar syntax to
  94. BASH but also implents many commands from Windows. For a list of commands look at the file commands.txt. For more
  95. detailed information about specific parts of the operating system setup has created several usefull documents in the
  96. /documents/ folder. ");
  97.             File.Save("usr/doc/viper.txt", @"Viper is a runtime enviroment , similar to Java VM that Grunty OS uses.At the core of Viper is the Viper virtual machine , the program that executes Viper bytecode. Viper programs are compiled into bytecode files with the extention .GEX. Grunty OS is equiped with a viper assembler , which can create Viper programs. You can use this with the vasm command.");
  98.             File.Save("usr/doc/file_structure.txt", @"The file structure of Grunty OS is very similar to unix / linux. The root consists of the following directories.
  99.  
  100.  
  101. /bin/   -   Binaries , command line programs are stored here
  102. /etc/   -   Configuration files and user profile information are stored here.
  103. /home/  -   This is were users folders are located.
  104. ");
  105.             File.Save("usr/doc/GLNFS.txt", @"GLNFS stands for Grunty OS Linked node file system and is the file system for Grunty OS. The File system consists of nodes (directories) containing a list of information. This information contains pointers to other nodes, and file information. ");
  106.  
  107.             Console.WriteLine("Creating File /usr/include/viper.h");
  108.             fd.makeDir("etc");
  109.             Console.WriteLine("Creating Directory /etc/profile/");
  110.             fd.makeDir("etc/profile");
  111.             BinaryWriter bw = new BinaryWriter(new FileStream("etc/profile/" + User + ".login", "w"));
  112.  
  113.             bw.Write(GruntyOS.Clock.GetDateTimeString());
  114.             bw.BaseStream.Close();
  115.             Console.WriteLine("Creating Directory /etc/passwd/");
  116.             fd.makeDir("etc/passwd");
  117.             Console.WriteLine("Creating File: /etc/passwd/" + User + ".dat");
  118.             bw = new BinaryWriter(new FileStream("etc/passwd/" + User + ".dat", "w"));
  119.             bw.Write(GruntyOS.Crypto.Hash.GHash(Pass));
  120.             bw.BaseStream.Close();
  121.             Console.WriteLine("Creating File: /etc/profile/" + User + ".dat");
  122.             bw = new BinaryWriter(new FileStream("etc/profile/" + User + ".dat", "w"));
  123.             bw.Write(1);
  124.             bw.BaseStream.Close();
  125.             Console.WriteLine("Creating Directory /home/");
  126.             fd.makeDir("home");
  127.             fd.saveFile(new byte[] { 0x47, 0x45, 0x58, 0x33, 0x20, 0x53, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x4D, 0x79, 0x20, 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x06, 0x4E, 0x6F, 0x6E, 0x61, 0x6D, 0x65, 0x01, 0x64, 0x10, 0x70, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x2E, 0x62, 0x79, 0x74, 0x65, 0x63, 0x6F, 0x64, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x41, 0x74, 0x3A, 0x20, 0x30, 0x30, 0x3A, 0x35, 0x33, 0x3A, 0x35, 0x31, 0x20, 0x41, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x2E, 0x62, 0x79, 0x74, 0x65, 0x63, 0x6F, 0x64, 0x65, 0x2B, 0x01, 0x00, 0x00, 0x76, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x07, 0x2E, 0x66, 0x69, 0x65, 0x6C, 0x64, 0x73, 0x00, 0x05, 0x2E, 0x74, 0x65, 0x78, 0x74, 0xCC, 0x00, 0x00, 0x00, 0x09, 0x2D, 0x47, 0x72, 0x75, 0x6E, 0x74, 0x79, 0x20, 0x4F, 0x53, 0x20, 0x4C, 0x69, 0x6E, 0x65, 0x20, 0x45, 0x64, 0x69, 0x74, 0x6F, 0x72, 0x20, 0x43, 0x6F, 0x6D, 0x6D, 0x61, 0x6E, 0x64, 0x73, 0x3A, 0x20, 0x2D, 0x2D, 0x53, 0x41, 0x56, 0x45, 0x20, 0x2D, 0x2D, 0x45, 0x58, 0x49, 0x54, 0x34, 0x00, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0xBD, 0x00, 0x00, 0x00, 0x09, 0x01, 0x6A, 0x34, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x34, 0x02, 0x00, 0x00, 0x00, 0x09, 0x02, 0x2D, 0x20, 0x34, 0x03, 0x00, 0x00, 0x00, 0x35, 0x03, 0x00, 0x00, 0x00, 0x03, 0x07, 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0xB4, 0x00, 0x00, 0x00, 0x0D, 0x34, 0x01, 0x00, 0x00, 0x00, 0x35, 0x01, 0x00, 0x00, 0x00, 0x34, 0x05, 0x00, 0x00, 0x00, 0x09, 0x06, 0x2D, 0x2D, 0x45, 0x58, 0x49, 0x54, 0x35, 0x05, 0x00, 0x00, 0x00, 0x41, 0x1D, 0x01, 0x00, 0x00, 0x00, 0x08, 0x9D, 0x00, 0x00, 0x00, 0x06, 0xB2, 0x00, 0x00, 0x00, 0x35, 0x02, 0x00, 0x00, 0x00, 0x35, 0x01, 0x00, 0x00, 0x00, 0x15, 0x34, 0x02, 0x00, 0x00, 0x00, 0x06, 0x55, 0x00, 0x00, 0x00, 0x13, 0x13, 0x34, 0x06, 0x00, 0x00, 0x00, 0x31, 0x12, 0x13, 0x13, 0x34, 0x07, 0x00, 0x00, 0x00, 0x31, 0x12, 0x65, 0x00, 0x00, 0x00, 0x13, 0x13, 0x13, 0x13, 0x05, 0x2E, 0x6D, 0x65, 0x74, 0x61, 0x3C, 0x00, 0x00, 0x00, 0x3C, 0x70, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x3E, 0x0A, 0x3C, 0x6C, 0x61, 0x62, 0x65, 0x6C, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x2E, 0x63, 0x74, 0x6F, 0x72, 0x22, 0x20, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x20, 0x3D, 0x20, 0x22, 0x32, 0x30, 0x32, 0x22, 0x2F, 0x3E, 0x0A, 0x3C, 0x2F, 0x70, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x3E }, "bin/edit");
  128.             File.Chmod("bin/edit", "555");
  129.             Console.WriteLine("Creating Directory /home/" + User + "/");
  130.             fd.makeDir("home/" + User);
  131.             GruntyOS.CurrentUser.Username = User;
  132.             Console.WriteLine("Creating Directory /home/" + User + "/settings/");
  133.             fd.makeDir("home/" + User + "/settings");
  134.             Console.WriteLine("Creating Directory /home/" + User + "/documents/");
  135.  
  136.             fd.makeDir("home/" + User + "/documents");
  137.             File.Save("home/" + User + "/readme.txt", @"Welcome to Grunty OS! A Cosmos based OS. The primary UI for Grunty OS is command line shell called 'GSHELL' , but
  138. GruntyOS does offer a GUI. You can access this GUI by typing 'GUI'. The command line shell has similar syntax to
  139. BASH but also implents many commands from Windows. For a list of commands look at the file commands.txt. For more
  140. detailed information about specific parts of the operating system setup has created several usefull documents in the
  141. /documents/ folder. ");
  142.             File.Save("home/" + User + "/commands.txt", @"
  143.  
  144. GruntyOS Commands
  145. -----------------------------------------------
  146. echo           -     Prints a string
  147. cd             -     Changes the current directory
  148. dir            -     Briefly list directory contents
  149. ./             -     Executes a program in the current directory
  150. pwd            -     Prints working directory
  151. ls             -     List information about about the directory
  152. mkdir          -     Creates a new directory
  153. passwd         -     Modify a password
  154. su             -     Subsitute user
  155. sudo           -     Execute command with root privilages
  156. mount          -     Mount a Filesystem
  157. disk           -     Disk utility
  158. userdel        -     Delete a user account
  159. logout         -     Log out
  160. useradd        -     Create a new user
  161. mv             -     Move a file
  162. rm             -     Delete a file or directory
  163. unlink         -     See rm
  164. usermod        -     Modify account
  165. chmod          -     Change file permissions
  166.  
  167. ");
  168.  
  169.             Console.WriteLine("Creating Directory /home/" + User + "/desktop/");
  170.      
  171.            
  172.             Console.WriteLine("Creating File /home/" + User + "/readme.txt");
  173.             Console.ReadLine();
  174.             Console.BackgroundColor = ConsoleColor.Black;
  175.             Console.ForegroundColor = ConsoleColor.White;
  176.             Console.Clear();
  177.  
  178.             Cosmos.Core.Global.CPU.Reboot();
  179.             Console.WriteLine("Setup complete");
  180.             Console.WriteLine("Please reboot...");
  181.             while (true)
  182.             {
  183.             }
  184.  
  185.         }
  186.  
  187.         public static void fill(ConsoleColor c, int x, int width, int y, int height)
  188.         {
  189.             ConsoleColor prevColor = Console.BackgroundColor;
  190.             Console.BackgroundColor = c;
  191.             int left = Console.CursorLeft, top = Console.CursorTop;
  192.             for (int X = 0; X < width; X++)
  193.             {
  194.                 for (int Y = 0; Y < height; Y++)
  195.                 {
  196.                     Console.CursorLeft = X + x;
  197.                     Console.CursorTop = Y + y;
  198.                     Console.Write(" ");
  199.                 }
  200.             }
  201.             Console.CursorLeft = left;
  202.             Console.CursorTop = top;
  203.             Console.BackgroundColor = prevColor;
  204.         }
  205.         public static uint Menu(string[] items, int x, int y)
  206.         {
  207.             int curseleft = x;
  208.             uint selc = 0;
  209.             int cursetop = y;
  210.  
  211.         redraw:
  212.             Console.CursorTop = y;
  213.             for (int i = 0; i < items.Length; i++)
  214.             {
  215.                 Console.CursorLeft = curseleft;
  216.                 if (i == selc)
  217.                 {
  218.                     ConsoleColor c1 = Console.ForegroundColor;
  219.                     ConsoleColor c2 = Console.BackgroundColor;
  220.                     Console.BackgroundColor = c1;
  221.                     Console.ForegroundColor = c2;
  222.                     Console.WriteLine(items[i]);
  223.                     Console.ForegroundColor = c1;
  224.                     Console.BackgroundColor = c2;
  225.                 }
  226.                 else
  227.                 {
  228.  
  229.                     Console.CursorLeft = curseleft;
  230.                     Console.WriteLine(items[i]);
  231.                 }
  232.             }
  233.             byte c = (byte)Console.Read();
  234.             if (c == 145)
  235.             {
  236.                 selc--;
  237.                 goto redraw;
  238.             }
  239.             else if (c == (byte)147)
  240.             {
  241.                 selc++;
  242.                 goto redraw;
  243.             }
  244.             else if (c == (byte)10)
  245.             {
  246.  
  247.                 return selc;
  248.             }
  249.             else
  250.             {
  251.                 goto redraw;
  252.             }
  253.             Console.WriteLine(c.ToString());
  254.  
  255.         }
  256.     }
  257. }
Add Comment
Please, Sign In to add comment