public void SetDefaultValues(bool _initial) { if (_initial) { ResourceManagerMain = new PlainTXTResourceManager(); ProgSettingsV = new ProgSettings(); ProgSettingsV.ProgramVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); SavefileVersion = 0; SupportedSavefileVersionETS2 = new int[] { 39, 46 }; //Supported save version SupportedGameVersionETS2 = "1.33.x - 1.37.x"; //Last game version Tested on //SupportedSavefileVersionATS; SupportedGameVersionATS = "1.33.x - 1.37.x"; //Last game version Tested on comboBoxPrevProfiles.FlatStyle = comboBoxProfiles.FlatStyle = comboBoxSaves.FlatStyle = FlatStyle.Flat; ProfileETS2 = @"\Euro Truck Simulator 2"; ProfileATS = @"\American Truck Simulator"; dictionaryProfiles = new Dictionary <string, string> { { "ETS2", ProfileETS2 }, { "ATS", ProfileATS } }; GameType = "ETS2"; //Globals.CurrentGame = dictionaryProfiles[GameType]; CompaniesLngDict = new Dictionary <string, string>(); CitiesLngDict = new Dictionary <string, string>(); CountriesLngDict = new Dictionary <string, string>(); CargoLngDict = new Dictionary <string, string>(); UrgencyLngDict = new Dictionary <string, string>(); //CustomStringsDict = new Dictionary<string, string>(); TruckBrandsLngDict = new Dictionary <string, string>(); DriverNames = new Dictionary <string, string>(); DistancesTable = new DataTable(); DistancesTable.Columns.Add("SourceCity", typeof(string)); DistancesTable.Columns.Add("SourceCompany", typeof(string)); DistancesTable.Columns.Add("DestinationCity", typeof(string)); DistancesTable.Columns.Add("DestinationCompany", typeof(string)); DistancesTable.Columns.Add("Distance", typeof(int)); DistancesTable.Columns.Add("FerryTime", typeof(int)); DistancesTable.Columns.Add("FerryPrice", typeof(int)); CountryDictionary = new CountryDictionary(); CountriesDataList = new Dictionary <string, Country>(); PlayerLevelNames = new List <LevelNames>(); #region Player level names LevelNames lvl_name0 = new LevelNames(0, "Newbie", "FFE0E0E0"); LevelNames lvl_name1 = new LevelNames(5, "Enthusiast", "FF45C294"); LevelNames lvl_name2 = new LevelNames(10, "Workhorse", "FF75BAEA"); LevelNames lvl_name3 = new LevelNames(15, "Entrepeneur", "FF3A88F4"); LevelNames lvl_name4 = new LevelNames(20, "Master", "FF5847F0"); LevelNames lvl_name5 = new LevelNames(25, "Instructor", "FFDA9356"); LevelNames lvl_name6 = new LevelNames(30, "Elite", "FFF58493"); LevelNames lvl_name7 = new LevelNames(40, "King of the Road", "FFC99EF2"); LevelNames lvl_name8 = new LevelNames(50, "Legend", "FFC2F9FF"); LevelNames lvl_name9 = new LevelNames(100, "Divine Champion", "FFF1DEA5"); PlayerLevelNames.Add(lvl_name0); PlayerLevelNames.Add(lvl_name1); PlayerLevelNames.Add(lvl_name2); PlayerLevelNames.Add(lvl_name3); PlayerLevelNames.Add(lvl_name4); PlayerLevelNames.Add(lvl_name5); PlayerLevelNames.Add(lvl_name6); PlayerLevelNames.Add(lvl_name7); PlayerLevelNames.Add(lvl_name8); PlayerLevelNames.Add(lvl_name9); #endregion string curName = ""; string[] input; List <string> curLst = new List <string>(); #region Currency ETS2 curName = "EUR"; CurrencyDictConversionETS2.Add(curName, 1); input = new string[] { "", "€", "" }; curLst = new List <string>(input); CurrencyDictFormatETS2.Add(curName, curLst); curName = "CHF"; CurrencyDictConversionETS2.Add(curName, 1.142); input = new string[] { "", "", " CHF" }; curLst = new List <string>(input); CurrencyDictFormatETS2.Add(curName, curLst); curName = "CZK"; CurrencyDictConversionETS2.Add(curName, 25.88); input = new string[] { "", "", " Kč" }; curLst = new List <string>(input); CurrencyDictFormatETS2.Add(curName, curLst); curName = "GBP"; CurrencyDictConversionETS2.Add(curName, 0.875); input = new string[] { "", "£", "" }; curLst = new List <string>(input); CurrencyDictFormatETS2.Add(curName, curLst); curName = "PLN"; CurrencyDictConversionETS2.Add(curName, 4.317); input = new string[] { "", "", " zł" }; curLst = new List <string>(input); CurrencyDictFormatETS2.Add(curName, curLst); curName = "HUF"; CurrencyDictConversionETS2.Add(curName, 325.3); input = new string[] { "", "", " Ft" }; curLst = new List <string>(input); CurrencyDictFormatETS2.Add(curName, curLst); curName = "DKK"; CurrencyDictConversionETS2.Add(curName, 7.46); input = new string[] { "", "", " kr" }; curLst = new List <string>(input); CurrencyDictFormatETS2.Add(curName, curLst); curName = "SEK"; CurrencyDictConversionETS2.Add(curName, 10.52); input = new string[] { "", "", " kr" }; curLst = new List <string>(input); CurrencyDictFormatETS2.Add(curName, curLst); curName = "NOK"; CurrencyDictConversionETS2.Add(curName, 9.51); input = new string[] { "", "", " kr" }; curLst = new List <string>(input); CurrencyDictFormatETS2.Add(curName, curLst); curName = "RUB"; CurrencyDictConversionETS2.Add(curName, 77.05); input = new string[] { "", "₽", "" }; curLst = new List <string>(input); CurrencyDictFormatETS2.Add(curName, curLst); #endregion #region Currency ATS curName = "USD"; CurrencyDictConversionATS.Add(curName, 1); input = new string[] { "", "$", "" }; curLst = new List <string>(input); CurrencyDictFormatATS.Add(curName, curLst); curName = "CAD"; CurrencyDictConversionATS.Add(curName, 1.3); input = new string[] { "", "$", "" }; curLst = new List <string>(input); CurrencyDictFormatATS.Add(curName, curLst); curName = "MXN"; CurrencyDictConversionATS.Add(curName, 18.69); input = new string[] { "", "$", "" }; curLst = new List <string>(input); CurrencyDictFormatATS.Add(curName, curLst); curName = "EUR"; CurrencyDictConversionATS.Add(curName, 0.856); input = new string[] { "", "€", "" }; curLst = new List <string>(input); CurrencyDictFormatATS.Add(curName, curLst); #endregion //Urgency UrgencyArray = new int[] { 0, 1, 2 }; DistanceMultipliers = new Dictionary <string, double> { { "km", 1 }, { "mi", km_to_mileconvert } }; ADRImgS = new Image[6]; ADRImgSGrey = new Image[6]; SkillImgSBG = new Image[5]; SkillImgS = new Image[6]; GaragesImg = new Image[1]; GaragesHQImg = new Image[1]; CitiesImg = new Image[2]; UrgencyImg = new Image[3]; CargoTypeImg = new Image[3]; CargoType2Img = new Image[3]; GameIconeImg = new Image[2]; TruckPartsImg = new Image[5]; TrailerPartsImg = new Image[4]; ProgUIImgs = new Image[0]; TabpagesImages = new ImageList(); ADRbuttonArray = new CheckBox[6]; SkillButtonArray = new CheckBox[5, 6]; } unCertainRouteLength = ""; FileDecoded = false; SavefilePath = ""; tempInfoFileInMemory = null; tempSavefileInMemory = null; tempProfileFileInMemory = null; //Game dependant if (GameType == "ETS2") { Globals.PlayerLevelUps = new int[] { 200, 500, 700, 900, 1000, 1100, 1300, 1600, 1700, 2100, 2300, 2600, 2700, 2900, 3000, 3100, 3400, 3700, 4000, 4300, 4600, 4700, 4900, 5200, 5700, 5900, 6000, 6200, 6600, 6800 }; //Currency CurrencyDictFormat = CurrencyDictFormatETS2; CurrencyDictConversion = CurrencyDictConversionETS2; Globals.CurrencyName = ProgSettingsV.CurrencyMesETS2; } else { Globals.PlayerLevelUps = new int[] { 200, 500, 700, 900, 1100, 1300, 1500, 1700, 1900, 2100, 2300, 2500, 2700, 2900, 3100, 3300, 3500, 3700, 4000, 4300, 4600, 4900, 5200, 5500, 5800, 6100, 6400, 6700, 7000, 7300 }; //Currency CurrencyDictFormat = CurrencyDictFormatATS; CurrencyDictConversion = CurrencyDictConversionATS; Globals.CurrencyName = ProgSettingsV.CurrencyMesATS; } PlayerDataV = new PlayerData(); SFProfileData = new SaveFileProfileData(); UserCompanyAssignedTruckPlacementEdited = false; InfoDepContinue = false; CompaniesList = new List <string>(); CitiesList = new List <City>(); CountriesList = new List <string>(); CargoesList = new List <Cargo>(); TrailerDefinitionVariants = new Dictionary <string, List <string> >(); TrailerVariants = new List <string>(); HeavyCargoList = new List <string>(); CompanyTruckList = new List <CompanyTruck>(); CompanyTruckListDB = new List <CompanyTruck>(); CompanyTruckListDiff = new List <CompanyTruck>(); UserColorsList = new List <Color>(); GaragesList = new List <Garages>(); UserTruckDictionary = new Dictionary <string, UserCompanyTruckData>(); UserDriverDictionary = new Dictionary <string, UserCompanyDriverData>(); DriverPool = new List <string>(); UserTrailerDictionary = new Dictionary <string, UserCompanyTruckData>(); UserTrailerDefDictionary = new Dictionary <string, List <string> >(); extraVehicles = new List <string>(); extraDrivers = new List <string>(); VisitedCities = new List <VisitedCity>(); CargoesListDB = new List <Cargo>(); CitiesListDB = new List <string>(); CompaniesListDB = new List <string>(); CargoesListDiff = new List <Cargo>(); CitiesListDiff = new List <string>(); CompaniesListDiff = new List <string>(); DBDependencies = new List <string>(); SFDependencies = new List <string>(); ExternalCompanies = new List <ExtCompany>(); ExtCargoList = new List <ExtCargo>(); EconomyEventsTable = new string[0, 0]; EconomyEventUnitLinkStringList = new string[0]; JobsAmountAdded = 0; LastVisitedCity = ""; InGameTime = 0; RandomValue = new Random(); LastModifiedTimestamp = new DateTime(); AddedJobsDictionary = new Dictionary <string, List <JobAdded> >(); AddedJobsList = new List <JobAdded>(); GPSbehind = new Dictionary <string, List <string> >(); GPSahead = new Dictionary <string, List <string> >(); GPSAvoid = new Dictionary <string, List <string> >(); GPSbehindOnline = new Dictionary <string, List <string> >(); GPSaheadOnline = new Dictionary <string, List <string> >(); namelessList = new List <string>(); namelessLast = ""; LoopStartCity = ""; LoopStartCompany = ""; ProgPrevVersion = "0.0.1.0"; RouteList = new Routes(); DistancesTable.Clear(); components = null; }
//Buttons private void buttonAccept_Click(object sender, EventArgs e) { ReturnNewName = textBoxNewName.Text; switch (FormMode) { case "rename": { string NewProfileName = NewProfileName = textBoxNewName.Text.Trim(new char[] { ' ' }), NewFolderName = "", NewFolderPath = ""; byte progress = 0; //Get existing folders string[] existingDirs = Directory.GetDirectories(InitialPath.Remove(InitialPath.LastIndexOf('\\') + 1)); List <string> existingDirList = new List <string>(); foreach (string dir in existingDirs) { //Get name existingDirList.Add(Utilities.TextUtilities.FromHexToString(Path.GetFileName(dir))); } if (NewProfileName != InitialName || existingDirList.Contains(NewProfileName)) { try { //New folder name NewFolderName = Utilities.TextUtilities.FromStringToHex(NewProfileName); NewFolderPath = InitialPath.Remove(InitialPath.LastIndexOf('\\') + 1) + NewFolderName; progress = 1; //Create folder and copy Directory.CreateDirectory(NewFolderPath); progress = 2; Utilities.IO_Utilities.DirectoryCopy(InitialPath, NewFolderPath, true); progress = 3; //Decode profile.sii FormMain tF = new FormMain(); string[] profileFile = tF.NewDecodeFile(NewFolderPath + "\\profile.sii"); progress = 4; SaveFileProfileData ProfileData = new SaveFileProfileData(); ProfileData.Prepare(profileFile); progress = 5; //New name ProfileData.ProfileName = textBoxNewName.Text; progress = 6; //Write file using (StreamWriter SW = new StreamWriter(NewFolderPath + "\\profile.sii", false)) { ProfileData.WriteToStream(SW); } progress = 7; //Make backup if (checkBoxCreateBackup.Checked) { ZipFile.CreateFromDirectory(InitialPath, InitialPath + ".zip"); } progress = 8; //Delete old folder Directory.Delete(InitialPath, true); progress = 9; ReturnNewName = NewProfileName; ReturnRenamedSuccessful = true; } catch { switch (progress) { case 0: MessageBox.Show("Create new folder name failed"); break; case 1: MessageBox.Show("Directory was not created"); break; case 2: MessageBox.Show("Directory copy failed"); goto delete; case 3: MessageBox.Show("Profile not decoded"); goto delete; case 4: MessageBox.Show("Profile hase wrong version/format"); goto delete; case 5: MessageBox.Show("Profile name is not applied"); goto delete; case 6: MessageBox.Show("Profile write failed"); goto delete; case 7: MessageBox.Show("Profile backup creation failed. Keeping both versions. Delete old profile manually."); break; case 8: MessageBox.Show("Deleting old profile failed. Keeping both versions. Delete old profile manually."); ZipFile.ExtractToDirectory(InitialPath + ".zip", InitialPath); File.Delete(InitialPath + ".zip"); break; delete: Directory.Delete(NewFolderPath); break; default: MessageBox.Show("Unexpected error. Deleting new Profile."); Directory.Delete(NewFolderPath); break; } } } break; } case "clone": { //Get existing folders string[] existingDirs = Directory.GetDirectories(InitialPath.Remove(InitialPath.LastIndexOf('\\') + 1)); List <string> existingDirList = new List <string>(); foreach (string dir in existingDirs) { //Get name existingDirList.Add(Utilities.TextUtilities.FromHexToString(Path.GetFileName(dir))); } foreach (string newfile in textBoxNewName.Lines) { string NewProfileName = "", NewFolderPath = ""; byte progress = 0; try { //Check empty lines if (newfile.Length == 0 || newfile.Trim(new char[] { ' ' }).Length == 0) { continue; } NewProfileName = newfile.Trim(new char[] { ' ' }); //Check existing folders if (NewProfileName == InitialName || existingDirList.Contains(NewProfileName)) { continue; } //New folder string NewProfileNameHex = Utilities.TextUtilities.FromStringToHex(NewProfileName); NewFolderPath = InitialPath.Remove(InitialPath.LastIndexOf('\\') + 1) + NewProfileNameHex; progress = 1; //Validate If exist skip if (Directory.Exists(NewFolderPath)) { continue; } Directory.CreateDirectory(NewFolderPath); progress = 2; //Copy profile files .cfg .sii .png //Get the files in the initial directory and copy them to the new location. var files = Directory.EnumerateFiles(InitialPath, "*.*", SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".cfg") || s.EndsWith(".sii") || s.EndsWith(".png")).ToArray(); //Iterate files foreach (string file in files) { string temppath = Path.Combine(NewFolderPath, Path.GetFileName(file)); //new file path with name FileInfo tFI = new FileInfo(file); //fileinfo tFI.CopyTo(temppath, false); //Copy } progress = 3; //Create save folder string NewSaveFolder = NewFolderPath + "\\save"; Directory.CreateDirectory(NewSaveFolder); progress = 4; //Copy saves if (checkBoxFullCloning.Checked) { Utilities.IO_Utilities.DirectoryCopy(InitialPath + "\\save", NewSaveFolder, true); } else { Utilities.IO_Utilities.DirectoryCopy(InitialPath + "\\save\\autosave", NewSaveFolder + "\\autosave", false); } progress = 5; //Decode profile.sii string[] profileFile = ParentForm.NewDecodeFile(NewFolderPath + "\\profile.sii"); progress = 6; SaveFileProfileData ProfileData = new SaveFileProfileData(); ProfileData.Prepare(profileFile); progress = 7; //New name ProfileData.ProfileName = NewProfileName; ProfileData.CreationTime = Utilities.DateTimeUtilities.DateTimeToUnixTimeStamp(); progress = 8; //Write file using (StreamWriter SW = new StreamWriter(NewFolderPath + "\\profile.sii", false)) { ProfileData.WriteToStream(SW); } progress = 9; //Cloned folders existingDirList.Add(NewProfileName); ReturnClonedNames.Add(NewProfileName); } catch { switch (progress) { case 0: MessageBox.Show("Create new folder name failed"); break; case 1: MessageBox.Show("Directory was not created"); break; case 2: MessageBox.Show("Directory copy failed"); goto delete; case 3: MessageBox.Show("Directory for saves was not created"); goto delete; case 4: MessageBox.Show("Directory with saves copy failed"); goto delete; case 5: MessageBox.Show("Profile not decoded"); goto delete; case 6: MessageBox.Show("Profile hase wrong version/format"); goto delete; case 7: MessageBox.Show("Profile properties was not applied"); goto delete; case 8: MessageBox.Show("Profile write failed"); goto delete; delete: Directory.Delete(NewFolderPath); break; default: MessageBox.Show("Unexpected error. Deleting new Profile."); Directory.Delete(NewFolderPath); break; } } } if (ReturnClonedNames.Count > 0) { ReturnCloningSuccessful = true; } break; } } DialogResult = DialogResult.OK; Close(); }