Created
October 17, 2013 21:05
-
-
Save Kruithne/7032189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using System.IO; | |
namespace RimJob | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
if (!this.checkSkyrimFolder()) | |
{ | |
this.showError("Could not locate Skyrim user folder!"); | |
Environment.Exit(0); | |
} | |
else | |
{ | |
this.showRandomShield(); | |
this.createFolders(); | |
this.makeProfileFromExisting(); | |
this.getProfileList(); | |
} | |
} | |
private bool checkSkyrimFolder() | |
{ | |
String path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\My Games\\Skyrim"; | |
if (Directory.Exists(path)) | |
{ | |
this.skyrimFolder = path; | |
this.saveFolder = path + "\\Saves"; | |
this.profileFolder = path + "\\Profiles"; | |
return true; | |
} | |
return false; | |
} | |
private void getProfileList() | |
{ | |
profileList.Items.Clear(); // Clear the list before re-render it. | |
this.addProfileToList(this.skyrimFolder + "\\Saves", true); // Add the current profile to the list. | |
String[] profiles = Directory.GetDirectories(this.skyrimFolder + "\\Profiles"); | |
for (int i = 0; i < profiles.Length; i++) | |
this.addProfileToList(profiles[i], false); | |
this.profileDirectories = profiles; | |
} | |
private void addProfileToList(String path, Boolean loaded) | |
{ | |
String name = this.getProfileName(path); | |
if (loaded) | |
name = name + " (LOADED)"; | |
profileList.Items.Add(name); | |
} | |
private String getProfileName(String path) | |
{ | |
String profileFile = path + "\\profile.txt"; | |
return File.ReadAllLines(profileFile)[0]; | |
} | |
private void makeProfileFromExisting() | |
{ | |
String profileFile = this.saveFolder + "\\profile.txt"; | |
if (!File.Exists(profileFile)) | |
{ | |
// The current save is not a profile, make it one. | |
using (StreamWriter writer = new StreamWriter(profileFile)) | |
{ | |
writer.WriteLine("Unnamed Profile"); | |
} | |
} | |
} | |
private void createFolders() | |
{ | |
Directory.CreateDirectory(this.saveFolder); | |
Directory.CreateDirectory(this.profileFolder); | |
} | |
private void showError(String errorText) | |
{ | |
MessageBox.Show(errorText, "Filthy Milkdrinker...", MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
} | |
private void loadProfile(String path) | |
{ | |
// Move everything from the current profile away. | |
String profileName = this.getProfileName(this.saveFolder); // Name of the loaded profile. | |
String profilePath = this.profileFolder + "\\" + profileName; | |
Directory.CreateDirectory(profilePath); // Create the folder, it should not exist. | |
String[] files = Directory.GetFiles(this.saveFolder); // Grab all the files. | |
foreach (String file in files) | |
File.Move(file, profilePath + "\\" + Path.GetFileName(file)); // Move each file. | |
String[] newFiles = Directory.GetFiles(path); // Grab all the new files. | |
foreach (String file in newFiles) | |
File.Move(file, this.saveFolder + "\\" + Path.GetFileName(file)); // Move each file. | |
Directory.Delete(path); // Delete the profile folder now we've moved everything. | |
this.getProfileList(); // Re-render the profile list. | |
} | |
private void loadProfileButton_Click(object sender, EventArgs e) | |
{ | |
String profilePath = this.getSelectedPath(); | |
if (profilePath != null) | |
this.loadProfile(profilePath); | |
} | |
private void renameProfileButton_Click(object sender, EventArgs e) | |
{ | |
this.editingProfile = this.getSelectedPath(); // Grab the path of the selected profile. | |
this.setInputState(true); // Enable the input controls. | |
inputBox.Focus(); // Focus the input box. | |
inputBox.Text = this.getProfileName(this.editingProfile); // Fill the profile name into input box. | |
} | |
private String getSelectedPath() | |
{ | |
int index = profileList.SelectedIndex; | |
if (index > 0) | |
return this.profileDirectories[index - 1]; | |
else if (index == 0) | |
return this.saveFolder; | |
return null; | |
} | |
private void setInputState(bool state) | |
{ | |
inputBox.Enabled = okayButton.Enabled = cancelButton.Enabled = state; | |
} | |
private void resetInput() | |
{ | |
this.setInputState(false); // Disable inputs. | |
inputBox.Text = ""; // Blank the input box. | |
this.editingProfile = null; // NULL the current editing profile. | |
} | |
private void cancelButton_Click(object sender, EventArgs e) | |
{ | |
this.resetInput(); | |
} | |
private void okayButton_Click(object sender, EventArgs e) | |
{ | |
String newPath = this.profileFolder + "\\" + inputBox.Text; | |
if (this.editingProfile == null) | |
{ | |
Directory.CreateDirectory(newPath); // Create the profile directory. | |
} | |
else | |
{ | |
if (Path.GetFileName(this.editingProfile) != "Saves") | |
Directory.Move(this.editingProfile, newPath); | |
else | |
newPath = this.saveFolder; | |
} | |
String profileFile = newPath + "\\profile.txt"; | |
using (StreamWriter writer = new StreamWriter(profileFile)) | |
{ | |
writer.WriteLine(inputBox.Text); // Write the new name to the profile file. | |
} | |
this.resetInput(); | |
this.getProfileList(); | |
} | |
private void createNewProfileButton_Click(object sender, EventArgs e) | |
{ | |
this.editingProfile = null; // Set editing profile to NULL just incase. | |
this.setInputState(true); // Enable the input controls. | |
inputBox.Focus(); // Focus the input box. | |
} | |
private void deleteProfileButton_Click(object sender, EventArgs e) | |
{ | |
int index = profileList.SelectedIndex; | |
if (index > 0) | |
{ | |
String path = this.profileDirectories[index - 1]; | |
String[] files = Directory.GetFiles(path); | |
foreach (String file in files) | |
File.Delete(file); // Delete files. | |
Directory.Delete(path); // Delete the directory. | |
} | |
this.getProfileList(); | |
} | |
private void showRandomShield() | |
{ | |
int random = new Random().Next(1, 9); | |
switch (random) | |
{ | |
case 1: shield.BackgroundImage = RimJob.Properties.Resources._1; break; | |
case 2: shield.BackgroundImage = RimJob.Properties.Resources._2; break; | |
case 3: shield.BackgroundImage = RimJob.Properties.Resources._3; break; | |
case 4: shield.BackgroundImage = RimJob.Properties.Resources._4; break; | |
case 5: shield.BackgroundImage = RimJob.Properties.Resources._5; break; | |
case 6: shield.BackgroundImage = RimJob.Properties.Resources._6; break; | |
case 7: shield.BackgroundImage = RimJob.Properties.Resources._7; break; | |
case 8: shield.BackgroundImage = RimJob.Properties.Resources._8; break; | |
case 9: shield.BackgroundImage = RimJob.Properties.Resources._9; break; | |
} | |
} | |
private String skyrimFolder; | |
private String saveFolder; | |
private String profileFolder; | |
private String[] profileDirectories; | |
private String editingProfile; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment