private void button_CreateTAD_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "TAD File (*.tad)|*.tad"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { string tadFilepath = saveFileDialog.FileName; string tacFilepath = Path.ChangeExtension(tadFilepath, ".tac"); TAD tad = new TAD(); tad.FilePath = tadFilepath; foreach (TADEntry entry in listBox_ArchiveFiles.Items) { tad.Entries.Add(entry); } TAC tac = new TAC(); tac.TAD = tad; LoadingDialog loadingDialog = new LoadingDialog(); loadingDialog.SetProgessable(tac); Thread thread = new Thread(delegate() { tac.Pack(tacFilepath); }); loadingDialog.ShowDialog(thread); tad.UnixTimestamp = dateTimePicker_TAD.Value; tad.Write(tadFilepath); } }
public void SeedData(TAD context) { var roleManager = new RoleManager <ApplicationRole>(new RoleStore <ApplicationRole>(context)); var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var getUser = new ApplicationUser(); getUser = userManager.FindByName("893569524V"); if (!roleManager.Roles.Any()) { roleManager.Create(new ApplicationRole { Name = SuperAdmin, CreatedBy = getUser.Id, CreatedDate = DateTime.Now, Status = true }); roleManager.Create(new ApplicationRole { Name = Admin, CreatedBy = getUser.Id, CreatedDate = DateTime.Now, Status = true }); } context.SaveChanges(); }
public void SeedData(TAD context) { var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var getUser = new ApplicationUser(); getUser = userManager.FindByName("893569524V"); context.Modules.AddRange(new List <Module> { new Module { Name = UserModule, CreatedBy = getUser.Id, CreatedDate = DateTime.Now, Status = true }, new Module { Name = RoleModule, CreatedBy = getUser.Id, CreatedDate = DateTime.Now, Status = true } }); context.SaveChanges(); }
public static ApplicationUserManager Create(TAD db) { var appUserManager = new ApplicationUserManager(new UserStore <ApplicationUser>(db)); // Configure validation logic for usernames appUserManager.UserValidator = new UserValidator <ApplicationUser>(appUserManager) { AllowOnlyAlphanumericUserNames = true, RequireUniqueEmail = false, }; appUserManager.MaxFailedAccessAttemptsBeforeLockout = 3; appUserManager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(3); // Configure validation logic for passwords appUserManager.PasswordValidator = new PasswordValidator { RequiredLength = 2, RequireNonLetterOrDigit = false, RequireDigit = false, RequireLowercase = false, RequireUppercase = false, }; return(appUserManager); }
private void button_SelectFolder_Click(object sender, EventArgs e) { VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog(); if (folderDialog.ShowDialog() == DialogResult.OK) { string folder = folderDialog.SelectedPath; List <string> files = GetFiles(folder); List <TADEntry> entries = new List <TADEntry>(); foreach (var file in files) { FileHash hash; string f = file.Replace(folder, ""); hash = MurmurHash2.GetFileHash(f, true); Console.WriteLine("{0} -> {1} : {2} -> {3}", hash.FilePath, hash.FilePathWithHash, hash.Hash.ToString("x8"), hash.FinalHash.ToString("x8")); FileInfo fileInfo = new FileInfo(file); TADEntry entry = new TADEntry(); entry.FilePath = file; entry.FileName = file; entry.FileSize = (uint)fileInfo.Length; entry.Index = 0; entry.FirstHash = hash.FinalHash; entry.SecondHash = hash.FilePathHash; entries.Add(entry); } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "TAD File (*.tad)|*.tad"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { string tadFilepath = saveFileDialog.FileName; string tacFilepath = Path.ChangeExtension(tadFilepath, ".tac"); TAD tad = new TAD(); tad.FilePath = tadFilepath; foreach (TADEntry entry in entries) { tad.Entries.Add(entry); } TAC tac = new TAC(); tac.TAD = tad; LoadingDialog loadingDialog = new LoadingDialog(); loadingDialog.SetProgessable(tac); Thread thread = new Thread(delegate() { tac.Pack(tacFilepath); }); loadingDialog.ShowDialog(thread); tad.UnixTimestamp = DateTime.Now; tad.Write(tadFilepath); } } }
private void button_Pack2_Click(object sender, EventArgs e) { InitializeJSON(); string folder = textBox_Folder2.Text + SM_TEXTURES; List <string> files = GetFiles(folder); List <TADEntry> entries = new List <TADEntry>(); // iterate through files in /textures/ and create TAD entry for each of them foreach (var file in files) { FileHash hash; string f = file.Replace(folder, ""); hash = MurmurHash2.GetFileHash(f, true); Console.WriteLine("{0} -> {1} : {2} -> {3}", hash.FilePath, hash.FilePathWithHash, hash.Hash.ToString("x8"), hash.FinalHash.ToString("x8")); FileInfo fileInfo = new FileInfo(file); TADEntry entry = new TADEntry(); entry.FilePath = file; entry.FileName = file; entry.FileSize = (uint)fileInfo.Length; entry.Index = 0; entry.FirstHash = hash.FinalHash; entry.SecondHash = hash.FilePathHash; entries.Add(entry); } // create tac/tad string tadFilepath = textBox_Folder2.Text + SM_ARCHIVE_DATA + "texture_mod.tad"; string tacFilepath = Path.ChangeExtension(tadFilepath, ".tac"); TAD tad = new TAD(); tad.FilePath = tadFilepath; foreach (TADEntry entry in entries) { tad.Entries.Add(entry); } TAC tac = new TAC(); tac.TAD = tad; LoadingDialog loadingDialog = new LoadingDialog(); loadingDialog.SetProgessable(tac); Thread thread = new Thread(delegate() { tac.Pack(tacFilepath); }); loadingDialog.ShowDialog(thread); tad.UnixTimestamp = DateTime.Now; tad.Write(tadFilepath); }
private void listBox_ExtractFiles_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { if (Path.GetExtension(file).ToUpper() != ".TAD") { continue; } TAD entry = new TAD(file); listBox_ExtractFiles.Items.Add(entry); } }
/// <summary> /// Extracts a given TAC file into the output directory provided /// </summary> /// <param name="tadFilepath">Path to TAC</param> /// <param name="folder">Path to output the extracted TAC</param> static void ExtractTAC(string tadFilepath, string folder) { try { TAD tad = new TAD(tadFilepath); TAC tac = new TAC(tad); tac.Unpack(bVerbose, false, folder); } catch (Exception e) { Console.WriteLine("Oops! {0} failed!\nException: {1}", tadFilepath, e.ToString()); } }
public static void RunSeeds(TAD context) { var seedList = new List <ISeed>(); seedList.Add(new Users()); seedList.Add(new Roles()); seedList.Add(new UserRole()); seedList.Add(new Modules()); seedList.Add(new Permissions()); seedList.Add(new RolePermissionMaps()); foreach (var seedResource in seedList) { seedResource.SeedData(context); } }
public void SeedData(TAD context) { var roleManager = new RoleManager <ApplicationRole>(new RoleStore <ApplicationRole>(context)); var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var getUser = new ApplicationUser(); getUser = userManager.FindByName("893569524V"); #region Super Admin var superAdminRole = roleManager.FindByName(Roles.SuperAdmin); foreach (var permission in context.Permissions) { context.RolePermissionMaps.Add(new RolePermissionMap { RoleId = superAdminRole.Id, PermissionId = permission.Id, CreatedBy = getUser.Id, CreatedDate = DateTime.Now, Status = true }); } #endregion #region Admin //var adminRole = roleManager.FindByName(Roles.Admin); //foreach (var permission in context.Permissions) //{ // context.RolePermissionMaps.Add(new RolePermissionMap // { // RoleId = superAdminRole.Id, // PermissionId = permission.Id, // CreatedBy = getUser.Id, // CreatedDate = DateTime.Now, // Status = true // }); //} #endregion context.SaveChanges(); }
public void SeedData(TAD context) { var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var getUser = new ApplicationUser(); getUser = userManager.FindByName("893569524V"); userManager.AddToRole(getUser.Id, Roles.SuperAdmin); var getUser1 = new ApplicationUser(); getUser1 = userManager.FindByName("893569525V"); userManager.AddToRole(getUser1.Id, Roles.Admin); context.SaveChanges(); }
/// <summary> /// Replaces a file in a given TAC file. /// </summary> /// <param name="file">Path to replace inside TAC file</param> /// <param name="tacFilepath">Path to TAC file</param> /// <param name="destination">Path to file in the given TAC file to replace</param> /// <param name="tadFilepath">(Optional) Path to corresponding TAD file. Will auto-detect if empty.</param> static void ReplaceFileInTAC(string file, string tacFilepath, string destination, string tadFilepath = "") { // If tadFilepath is empty, search for it.. if (String.IsNullOrEmpty(tadFilepath)) { tadFilepath = Path.ChangeExtension(tacFilepath, ".tad"); Console.WriteLine("{0}", tadFilepath); if (!File.Exists(tadFilepath)) { Console.WriteLine("ERROR: TAD file could not be found."); ++iNumFailedOperations; return; } } // Ensure the destination directory exists, if not, create it.. if (!Directory.Exists(Path.GetDirectoryName(destination))) { Directory.CreateDirectory(Path.GetFullPath(destination)); if (bVerbose) { Console.WriteLine("Creating directory \'{0}\'", Path.GetDirectoryName(destination)); } } // Read in the data and write it out.. if (bVerbose) { Console.WriteLine("Reading {0}..", tadFilepath); } TAD tad = new TAD(tadFilepath); TAC tac = new TAC(tad, tacFilepath); if (tac != null) { tac.Unpack(bVerbose, false); } }
public void SeedData(TAD context) { var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var getUser = new ApplicationUser(); getUser = userManager.FindByName("893569524V"); context.Permissions.AddRange(new List <Permission> { new Permission { Name = ViewUsers, CreatedBy = getUser.Id, CreatedDate = DateTime.Now, Status = true, ModuleId = 1 }, new Permission { Name = AddUsers, CreatedBy = getUser.Id, CreatedDate = DateTime.Now, Status = true, ModuleId = 1 }, new Permission { Name = DeleteUsers, CreatedBy = getUser.Id, CreatedDate = DateTime.Now, Status = true, ModuleId = 1 } }); context.SaveChanges(); }
private void button_Unpack2_Click(object sender, EventArgs e) { InitializeJSON(); // create json string sdtextureoverridePath = textBox_Folder2.Text + SM_TEXTURES + "\\" + SM_TEXOVER; if (!Directory.Exists(Path.GetDirectoryName(sdtextureoverridePath))) { Directory.CreateDirectory(Path.GetDirectoryName(sdtextureoverridePath)); } using (FileStream stream = File.Open(sdtextureoverridePath, FileMode.Create)) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(Resources.SDTextureOverride_SM2_Clean); } } // unpack mapped data from disk tac string tadFilepath = textBox_Folder2.Text + SM_ARCHIVE_DATA + SM2_DISK + ".tad"; string tacFilepath = textBox_Folder2.Text + SM_ARCHIVE_DATA + SM2_DISK + ".tac"; TAD tad = new TAD(tadFilepath); TAC tac = new TAC(tad); textures.Clear(); foreach (var entry in tad.Entries) { if (entry.FileName == "/misc/cold.bin") { continue; // not supported } byte[] buffer = tac.GetFileBuffer(entry); ReadFileRecursive(buffer); } bool first = true; string prevDdsPath = ""; string prevPngPath = ""; foreach (var tex in textures) { first = true; List <HashEntry> matches = new List <HashEntry>(); foreach (var t in SM2_Hashes) { if (tex.texID == t.texID) { if (first) // if first match, write DDS or PNG file { if (radioButton_DDS1.Checked) { DDS dds = new DDS(tex.image); string filepath = textBox_Folder2.Text + SM_TEXTURES + t.Filepath.Replace("/", "\\"); dds.MipHandling = DDSGeneral.MipHandling.KeepTopOnly; dds.AlphaSettings = DDSGeneral.AlphaSettings.KeepAlpha; dds.FormatDetails = new DDSFormats.DDSFormatDetails(DDSFormat.DDS_DXT3); dds.Write(filepath); prevDdsPath = filepath; } if (radioButton_PNG1.Checked) { PNG png = new PNG(tex.image); string filepath = textBox_Folder2.Text + SM_TEXTURES + t.Filepath.Replace("/", "\\"); string filepathPng = Path.ChangeExtension(filepath, ".png"); png.Write(filepathPng); prevPngPath = filepathPng; } first = false; } else // if duplicate, copy/paste the texture file (DDS and PNG writing costs alot of resources) { string filepath = textBox_Folder2.Text + SM_TEXTURES + t.Filepath.Replace("/", "\\"); string filepathPng = Path.ChangeExtension(filepath, ".png"); string dir = Path.GetDirectoryName(filepath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (radioButton_DDS1.Checked) { File.Copy(prevDdsPath, filepath, true); } if (radioButton_PNG1.Checked) { File.Copy(prevPngPath, filepathPng, true); } } matches.Add(t); } } // Remove matches to increase iteration speed, will result in the first found texture being used foreach (var match in matches) { SM2_Hashes.Remove(match); } } textures.Clear(); foreach (var hash in SM2_Hashes) { Console.WriteLine("Texture not found: {0} = {1}", hash.texID.HexStr, hash.Filepath); } }
public static string GetExtensionFromBuffer(byte[] buffer) { //Archives if (AFS.IsValid(buffer)) { return("AFS"); } if (GZ.IsValid(buffer)) { return("GZ"); } if (IDX.IsValid(buffer)) { return("IDX"); } if (IPAC.IsValid(buffer)) { return("IPAC"); } if (PKF.IsValid(buffer)) { return("PKF"); } if (PKS.IsValid(buffer)) { return("PKS"); } //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension if (TAD.IsValid(buffer)) { return("TAD"); } //Textures/Images if (TEXN.IsValid(buffer)) { return("TEXN"); } if (PVRT.IsValid(buffer)) { return("PVRT"); } if (DDS.IsValid(buffer)) { return("DDS"); } //Models if (MT5.IsValid(buffer)) { return("MT5"); } if (MT7.IsValid(buffer)) { return("MT7"); } //Subtitles if (SUB.IsValid(buffer)) { return("SUB"); } return("UNKNOWN"); }
public void SeedData(TAD context) { var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var getUser = new ApplicationUser(); var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, FirstName = "Super", LastName = "Admin", ActiveStatus = true, IsTempararyPassword = true, IsFirstAttempt = true, PhoneNumber = "0776532148", LockoutEnabled = false, CreatedBy = "SuperAdmin", CreatedDate = DateTime.Now, TermsAndConditionStatus = true, PhoneNumberConfirmed = true }; if (!context.Users.Any(u => u.UserName == user.UserName)) { var password = new PasswordHasher(); var hashed = password.HashPassword("12345"); user.PasswordHash = hashed; userManager.Create(user); context.SaveChanges(); } var user1 = new ApplicationUser { UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, FirstName = "Admin", LastName = "Admin", ActiveStatus = true, IsTempararyPassword = true, IsFirstAttempt = true, PhoneNumber = "0776532148", LockoutEnabled = false, CreatedBy = "SuperAdmin", CreatedDate = DateTime.Now, TermsAndConditionStatus = true, PhoneNumberConfirmed = true }; if (!context.Users.Any(u => u.UserName == user1.UserName)) { var password = new PasswordHasher(); var hashed = password.HashPassword("12345"); user1.PasswordHash = hashed; userManager.Create(user1); context.SaveChanges(); } }
public UserAccess(TAD context) { _context = context; _appUserManager = ApplicationUserManager.Create(_context); _appRoleManager = ApplicationRoleManager.Create(_context); }
public static ApplicationRoleManager Create(TAD db) { var appRoleManager = new ApplicationRoleManager(new RoleStore <ApplicationRole>(db)); return(appRoleManager); }
/// <summary> /// Extracts a file from a given TAC file. /// </summary> /// <param name="file">Path to file to extract from TAC file.</param> /// <param name="tacFilepath">Path to TAC file to extract the file from.</param> /// <param name="destination">Path to output the extracted file from the TAC file.</param> /// <param name="tadFilepath">(Optional) Path to corresponding TAD file. Will auto-detect if empty.</param> static void ExtractFileFromTAC(string file, string tacFilepath, string destination, string tadFilepath = "") { // If tadFilepath is empty, search for it.. if (String.IsNullOrEmpty(tadFilepath)) { tadFilepath = Path.ChangeExtension(tacFilepath, ".tad"); Console.WriteLine("{0}", tadFilepath); if (!File.Exists(tadFilepath)) { Console.WriteLine("ERROR: TAD file could not be found."); ++iNumFailedOperations; return; } } // Ensure the destination directory exists, if not, create it.. if (!Directory.Exists(Path.GetDirectoryName(destination))) { Directory.CreateDirectory(Path.GetFullPath(destination)); if (bVerbose) { Console.WriteLine("Creating directory \'{0}\'", Path.GetDirectoryName(destination)); } } // Read in the data and write it out.. if (bVerbose) { Console.WriteLine("Reading {0}..", tadFilepath); } TAD tad = new TAD(tadFilepath); TAC tac = new TAC(tad, tacFilepath); byte[] bytes = tac.GetFileBuffer(file); if (tac != null && bytes != null) { try { destination += "\\"; if (String.IsNullOrEmpty(Path.GetFileName(destination))) { destination += Path.GetFileName(file); } FileStream fs = File.Open(destination, FileMode.OpenOrCreate, FileAccess.Write); fs.Write(bytes, 0, bytes.Length); fs.Close(); tac.Close(); Console.WriteLine("Finished writing {0} from {1} ({2})", Path.GetFileName(destination), Path.GetFileName(file), Path.GetFileName(tacFilepath)); ++iNumOperations; } catch (Exception e) { Console.WriteLine("Oops! {0} failed!\nException: {1}", tacFilepath, e.ToString()); ++iNumFailedOperations; } } else { Console.WriteLine("ERROR: Could not find {0} in TAC {1}", file, Path.GetFileName(tacFilepath)); ++iNumFailedOperations; } return; }
/// <summary> /// Trys to find the fitting file type for the given file with the file signature. /// </summary> public static Type GetFileTypeFromSignature(Stream stream) { byte[] buffer = new byte[8]; stream.Read(buffer, 0, buffer.Length); //Archives if (AFS.IsValid(buffer)) { return(typeof(AFS)); } if (GZ.IsValid(buffer)) { return(typeof(GZ)); } if (IDX.IsValid(buffer)) { return(typeof(IDX)); } if (IPAC.IsValid(buffer)) { return(typeof(IPAC)); } if (PKF.IsValid(buffer)) { return(typeof(PKF)); } if (PKS.IsValid(buffer)) { return(typeof(PKS)); } //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension if (TAD.IsValid(buffer)) { return(typeof(TAD)); } //Textures/Images if (TEXN.IsValid(buffer)) { return(typeof(TEXN)); } if (PVRT.IsValid(buffer)) { return(typeof(PVRT)); } if (DDS.IsValid(buffer)) { return(typeof(DDS)); } //Models if (MT5.IsValid(buffer)) { return(typeof(MT5)); } if (MT7.IsValid(buffer)) { return(typeof(MT7)); } //Subtitles if (SUB.IsValid(buffer)) { return(typeof(SUB)); } return(null); }