Creating installer for operating system Cosmos C# - c#

I need to create an installer for my operating system in Cosmos kernel but I don't know where to start or how to create it.
[See my Operating system]
https://www.mediafire.com/file/3nr6pbjfg7p1gfq/GoPixelOS.iso/file
I want to install the OS on the machine, how do I do that?

I think I can help you. but it actually makes a new user. but it still needs installation. but this won't work for another computer that does not have Filesystem.vmdk. maybe it is just a virtual file system
First you will need a file system
you will also need System.io
on before writing this codeā¬‡
if (!File.Exists("0:\\youros\\System.txt")) //you will need Using.System.io and ! mean not equal
{
Console.Clear();
Console.WriteLine("YourOS will be install in your pc");
Console.WriteLine("Create a username and password:");
Console.Write("Username: ");
string username = Console.ReadLine();
Console.Write("Password: ");
string cPassword = Console.ReadLine();
Console.Write(username +"> "); //when your put username variable it should look like this "The user name: "
Console.WriteLine("Creating System Directory..."); //Creating Directory or folder
fs.CreateDirectory("0:\\yourOS\\");
Console.WriteLine("Creating File for user");
fs.CreateFile("0:\\yourOS\\System.txt"); //Creating File System
fs.CreateFile("0:\\yourOS\\users.db");
fs.CreateFile("0:\\yourOS\\password.db"); //creating a password files
Console.WriteLine("Setting User Preferences...");
File.WriteAllText("0:\\yourOS\\System.txt", write);
File.WriteAllText("0:\\yourOS\\users.db", username); ` //This will save username
File.WriteAllText("0:\\yourOS\\password.db", cPassword); //this one will save the user password
Console.WriteLine("Reboot ONEOS in 3 seconds");
Cosmos.HAL.Global.PIT.Wait(3000);
Sys.Power.Reboot(); //when the installation done it will reboot`
else //after reboot it will go to else and just leave it blank. it will just go to run() after the else
{
password = File.ReadAllText("0:\\oneos\\password.db"); //this will show the
Console.Write("Type your password: ")
var type Console.ReadLine();
if (type == password)
{
//just leave it blank. it will go to protected override void run()
}
else
}
Sys.Power.Reboot(); //this will reboot the OS if user type wrong password
{
}
That is for the installation but if you want the installation to be more useful you will need this
//protected override void Run()
text = File.ReadAllText("0:\\oneos\\users.db"); //this will show the username
Console.Write(text + "> ");
var input = Console.ReadLine();
And that is if you want to make it show error put try and catch to your OS if there has an error.
if you can understand this you can make the os have user selection like windows logon screen.
If there is a problem please tell me

Related

Why do my objects properties values get overwritten?

My goal is to create a system that can create an endless amount of accounts and store them in a list, the system will then check this list to see if the account exists and if it does it well let the user login. Ultimately I want to create a method which can create accounts however for now I am sticking with 2. The way I expect my code to function is that it creates 2 separate accounts, each with its own object properties, and then let the user login with either account. What ends up happening is both accounts appear in the list however the 2nd account seems to overwrite all the properties of the first. I'm still new to c# and I'm not quite sure what caused this to happen/how I can fix it.
I have tried to separate the initialization of the 2 accounts however I'm not sure I've done it correctly or if that is even the right term.
The Main section of my code starts by creating a list, and then creating those accounts within the list using predetermined functions, It then prints out the account details so that they can clearly be seen.
static void Main(string[] args)
{
//This List is used to store Accounts
AccountInteractions accountInteractions = new AccountInteractions();
//First Account
Account account = new Account();
account.ReadAccount();
accountInteractions.AddAccount(account);
Console.WriteLine();
//Second Account
account = new Account();
account.ReadAccount();
accountInteractions.AddAccount(account);
//Listing accounts and account variables
foreach (var item in accountInteractions.AccountList)
{
Console.WriteLine("Name: {0}, Email: {1}, Password: ${2}", account.Username, account.UserEmail, account.UserPassword);
}
}
The methods below show how the users input is used to create the accounts, also shown is how the system checks for whether the account matches that within the list.
public void ReadAccount()
{
Console.Write("Username: ");
Username = Console.ReadLine();
Console.Write("Email: ");
UserEmail = Console.ReadLine();
Console.Write("Password: ");
UserPassword = Console.ReadLine();
Login = false;
}
public void LogInToAccount(Account account)
{
//Setup User Input
Console.WriteLine();
Console.Write("Email: ");
userEmailCheck = Console.ReadLine();
Console.Write("Password: ");
userPasswordCheck = Console.ReadLine();
//Verifying Details to check if account exists
if (account.userEmailCheck == account.UserEmail & account.userPasswordCheck == account.UserPassword)
{
account.Login = true;
Console.WriteLine("Login Successful");
}
else
{
Console.WriteLine("Invalid credentials, please try again.");
account.LogInToAccount(account);
}
}
This picture shows the output using basic details entered
As can be seen despite entering separate details both accounts end up having the same properties. Ultimately both accounts should be able to login using the LogInToAccount() method, and both should have their own unique properties.
You are using the wrong variable account instead of the loop variable item here:
foreach (var item in accountInteractions.AccountList)
{
Console.WriteLine("Name: {0}, Email: {1}, Password: ${2}", account.Username, account.UserEmail, account.UserPassword);
}
account refers to the last initialized account. The reason for such problems is that you do too much in the same scope. Use methods, for example one to output existing accounts.

Edit Skype's config.xml

I'm trying to edit Skype's config.xml file from code. It works fine, but after change Skype delete it and generate another one, undoing all my changes. For example, code:
public Core()
{
try
{
var processes = Process.GetProcessesByName("Skype");
if (processes.Length == 0)
{
AddRegistryKeys();
RemovePlaceholder();
}
else
{
RestartSkypeAndRun(processes[0],
() =>
{
AddRegistryKeys();
RemovePlaceholder();
});
}
Environment.Exit(0);
}
catch (Exception ex)
{
MessageBox.Show(string.Format("{0} - {1}", ex.GetType(), ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(-1);
}
}
private static void RemovePlaceholder()
{
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string skypePath = Path.Combine(appDataPath, "Skype");
foreach (var configPath in Directory.EnumerateFiles(skypePath, "config.xml", SearchOption.AllDirectories))
{
string userConfig = File.ReadAllText(configPath);
string fixedConfig = userConfig.Remove("<AdvertPlaceholder>1</AdvertPlaceholder>");
File.Move(configPath, configPath + ".bak");
File.WriteAllText(configPath, fixedConfig);
}
}
private static void RestartSkypeAndRun(Process skypeProc, Action action)
{
string skypeExePath = skypeProc.Modules[0].FileName;
skypeProc.Kill();
skypeProc.WaitForExit();
Thread.Sleep(TimeSpan.FromMilliseconds(500)); //just in case
action();
Process.Start(skypeExePath);
}
So how can it be done? I have no idea, except blocking file modification, e.g. change ACL and other permissions for file, set readonly attribute e.t.c.
See https://www.safaribooksonline.com/library/view/skype-hacks/0596101899/ch04s04.html
"Always stop Skype from running (by right-clicking on Skype in the system tray and choosing Quit) before making any changes to config.xml (or shared.xml), because even though your editor may tell you it has saved your updated version of config.xml, you may find that Skype ignores your changes and they are missing when you reopen config.xml. The procedure for editing any of Skype's configuration files should go like this: quit Skype (that is, stop it from running), edit (or delete) the configuration file, save the changes, and restart Skype."
C:\Documents and Settings\Username\Application Data\Skype\Skypename\config.xml
"There is another file, shared.xml, from which Skype obtains configuration information that is common to all users of Skype on the same Windows machine... You also can edit this file to tweak how Skype behaves, but the scope for tweaking is far more limited than for config.xml. You typically can find shared.xml in these locations on each platform:
Windows (version 1.3 and before)
C:\Documents and Settings\All Users\Application Data\Skype\shared.xml
Windows (version 1.4 and after)
C:\Documents and Settings\Username\Application Data\Skype\shared.xml
"

A piece of code working in WindowsFormApplication but not working in windows service, is there any mistake?

Here the code is
protected override void OnStart(string[] args)
{
Thread thr = new Thread(new ThreadStart(run));
thr.Start();
}
static void run()
{
while (true)
{
StreamWriter str = new StreamWriter("D:\\Sarojini.txt", true);
str.WriteLine();
str.WriteLine("**** List of Apllication*********");
str.WriteLine();
str.WriteLine("Service started on:" + DateTime.Now.ToString());
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
str.WriteLine();
str.WriteLine("the current user is " + userName);
Process[] processlist = Process.GetProcesses();
foreach (Process process in processlist)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
str.WriteLine("Process::{0} ID::{1} Title::{2}", process.ProcessName, process.Id, process.MainWindowTitle);
}
}
str.Close();
Thread.Sleep(3600000 / 10);
}
}
protected override void OnStop()
{
StreamWriter str = new StreamWriter("D:\\Sarojini.txt", true);
str.WriteLine();
str.WriteLine("the service has been stopped.");
}
here in this code , a text file is created and first line is written on it but the list of running application is not there , where as when i used this code in in windowsFormApllication it is running perfectly. i dont know what is the problem .
This is most likely due to the account you are running the service under not having the correct permissions to use the Process class. When trying to retrieve process names, IDs etc your application needs to have sufficient rights and the default Local System Account is unlikely to meet this.
When you run this code as a Windows Form Application WindowsIdentity.GetCurrent() will return the user who is currently signed in.
When you run this code as a Windows Service WindowsIdentity.GetCurrent() will return the user who setup under the User Account in the Service Setting.
This will show that they are running with different credentials. So, your service may be running under an account that does not have permission to perform the required actions.
To check this:
Go into Services and double-click your service.
Click on The Log On tab
By default Local System Account is checked but you want to select This Account and set a valid account.

Login administrator c# from local database bug

I have a problem when I try to connect an admin to my c# application.
I have created a local database to stock the main informations such as UserName, Password...
When the user enter the login interface, he enter his user name and password, then click to login like this:
<TextBox Name="UserNameBox"></TextBox>
<PasswordBox Name="PasswordBox"></PasswordBox>
<Button Content="Connection" Click="ConnectionClick"></Button>
The event click role is to check if the admin can log in, or not:
private void ConnectionClick(object sender, RoutedEventArgs e)
{
var username = UserNameBox.Text;
var password = PasswordBox.Password;
Admin admin = new Admin();
if((username == admin.UserName) && (password == admin.Password))
{
this.Close()
MainPage retourpageprincipale = new MainPage();
retourpageprincipale.Show();
}
else
{
MessageBox.Show("Bad Username/Password combo!");
}
}
I have created some fake users into my local database (Admin) and when I enter the correct login/password, I have the MessageBox. I always have the MessageBox.
Does anybody know what I am doing wrong?
I won't give You an answer, but I will show you what should be done in such cases:
Try to debug - put break point in line if((username == admin.UserName) && (password == admin.Password)) and using watch expression try to find out where is the problem
If step one is impossible - try to log everything to file, but remember after find a bug delete this logging because you will log admin password :)
Above steps should give you the answer

faulty login system, will not allow logins

ok, i got it sorted thanks to LordALMMa, but now i have another problem. I want to determine if the user clicks Admin or User radiobutton when registering. I think i should append it to the end of the line on the text file where the name and password is, but how would i do it? Here is the relevant code:
Radio Button Check
public bool radioButtons()
{
string usertypebutton;
if (!userButton.Checked && !adminButton.Checked)
{
MessageBox.Show("You must select an account type");
return false;
}
else
{
if (userButton.Checked)
{
usertypebutton = "User";
}
else
{
usertypebutton = "Admin";
}
return true;
}
}
Streamwriter for registering:
public void mySW()
{
string path = #"C:\Other\myFile.txt";
string userName = userNameBox.Text;
string password = passwordBox.Text;
string usertype = usertypebutton;
using (StreamWriter writer = new StreamWriter(path, true))
{
writer.WriteLine("Username: {0} Password: {1} Type: {3}" , userName, password, usertype);
// No need to close nor dispose your StreamWriter.
// You're inside a using statement for that!
}
MessageBox.Show("Thanks for registering! \n\nYou may now log in!", "Registration SuccessFul");
Application.OpenForms[0].Show();
this.Close();
}
Logging In:
private void logonButton_Click(object sender, EventArgs e)
{
// Loads your users storage
var users = File.ReadAllLines(#"C:\Other\myFile.txt");
// Creates the line with username + password
var usernamePassword = String.Format("Username: {0} Password: {1}", userNameBox.Text, passwordBox.Text);
// Locates the user on your storage
var userFound = users.SingleOrDefault(_u => _u.Equals(usernamePassword));
if (userFound != null)
{
MessageBox.Show("Welcome back, " + userNameBox.Text);
}
else
{
MessageBox.Show("Sorry, you have entered incorrect details\n\nPlease try again");
userNameBox.Text = "";
passwordBox.Text = "";
}
}
So (I think) essentially i want to pass the value usertypebutton from radiobutton method, to the SW. How would i do it, as i'm already passing a boolean value?
Anthony
One part of the problem is that you are not writing the same string that you're reading:
writer.WriteLine("Password: " + userName + " " + "Password: " + password);
I'm guessing that was a typo in your post... but if not that could be your issue.
The other problem is probably this right here:
using (StreamWriter writer = new StreamWriter(path, true))
If you look up the documentation on that overload of the StreamWriter constructor, you'd see that you specified append = true. You are appending each set of login credentials to a file on its own line. But then later, you are only reading the first line of that file. So you will always read the first set of credentials that were entered when the file was first created.
That aside, I hope you are just doing this as an experiment since it is not a secure way of managing passwords to write them to a file like that. Also, you don't need to call Close and Dispose on a Stream if you wrap it in a using block, so you should stick to doing that.
Anthony, dispite the fact that storing logins this way is a major security problem (it's not even a risk anymore), there are some changes to your code that I'd do.
The issue is that you're not storing "Username: [username] Password: [password]".
If you double-check your saving method, you're storing "Password: [username] Password: [password]". That's why they are never found.
Here follows some changes:
Consider:
public void mySW()
{
string path = #"C:\Other\myFile.txt";
string userName = userNameBox.Text;
string password = passwordBox.Text;
using (StreamWriter writer = new StreamWriter(path, true))
{
// This overload makes your life easier by auto-formatting variables for you.
// Also, avoid the "string1 + string2" concatenation mode.
// Use String.Format instead. It's easier to read and keep over time.
writer.WriteLine("Username: {0} Password: {1}", userName, password);
// No need to close nor dispose your StreamWriter.
// You're inside a using statement for that!
}
MessageBox.Show("Thanks for registering! \n\nYou may now log in!", "Registration SuccessFul");
Application.OpenForms[0].Show();
this.Close();
}
And your other method should look like:
{
// Loads your users storage
var users = File.ReadAllLines(#"C:\Other\myFile.txt");
// Creates the line with username + password
var usernamePassword = String.Format("Username: {0} Password: {1}", userNameBox.Text, passwordBox.Text);
// Locates the user on your storage
// This uses Linq syntax with lambda. Linq without lamba looks similar to SQL.
// Lambda is a bit more advanced but reduces code-size and it's easier to understand (IMHO).
// This code will iterate through users (list of string) and try to retrieve one that's equal to the contents of usernamePassword.
var userFound = users.SingleOrDefault(_u => _u.Equals(usernamePassword));
// If null, indicates that no username/password combination was found.
if (userFound != null)
{
MessageBox.Show("Welcome back, " + userNameBox.Text);
}
else
{
MessageBox.Show("Sorry, you have entered incorrect details\n\nPlease try again");
userNameBox.Text = "";
passwordBox.Text = "";
}
}
I'm not checking for the exception. SingleOrDefault will throw an exception if 2 or more records are found mathing the search pattern.
I'm not checking that because this will increase complexity here with try-catch and also because for that to work properly, I'd have to check if they exits BEFORE recording, so changing the register method.
But I think you've got the idea here.
Have you checked your output files? You are writing Password: X Password: Y:
writer.WriteLine("Password: " + userName + " " + "Password: " + password);
and you are checking Username: X Password: Y
if (user == ("Username: "+userNameBox.Text.Trim()+" "+"Password: "+passwordBox.Text.Trim()))
You are adding line as
writer.WriteLine("Password: " + userName + " " + "Password: " + password);
^1 ^2
^1 must be Username:
There are some points which I cannot pass without pointing:
What would you do if file structure corrupted?
What if a user wants to register twice with same username and password?
Please encode the passwords. This is not ethic. You put at risk your members who uses same account information in somewhere else.
Try using a database which is stronger and faster than a text file.

Categories

Resources