示例#1
0
 /// <summary>
 /// Tries to get an <see cref="SAV3GCMemoryCard"/> object from the input parameters.
 /// </summary>
 /// <param name="data">Binary data</param>
 /// <param name="memcard">Output result</param>
 /// <returns>True if file object reference is valid, false if none found.</returns>
 public static bool TryGetMemoryCard(byte[] data, [NotNullWhen(true)] out SAV3GCMemoryCard?memcard)
 {
     if (!SAV3GCMemoryCard.IsMemoryCardSize(data))
     {
         memcard = null;
         return(false);
     }
     memcard = new SAV3GCMemoryCard(data);
     return(true);
 }
示例#2
0
 /// <summary>
 /// Checks if the length is too big to be a detectable file.
 /// </summary>
 /// <param name="length">File size</param>
 public static bool IsFileTooBig(long length)
 {
     if (length <= 0x10_0000) // 1 MB
     {
         return(false);
     }
     if (length > int.MaxValue)
     {
         return(true);
     }
     if (SaveUtil.IsSizeValid((int)length))
     {
         return(false);
     }
     if (SAV3GCMemoryCard.IsMemoryCardSize(length))
     {
         return(false); // pbr/GC have size > 1MB
     }
     return(true);
 }
示例#3
0
        // Main Menu Subfunctions
        private void openQuick(string path, bool force = false)
        {
            // detect if it is a folder (load into boxes or not)
            if (Directory.Exists(path))
            {
                C_SAV.LoadBoxes(out string _, path); return;
            }

            string   ext = Path.GetExtension(path);
            FileInfo fi  = new FileInfo(path);

            if (!fi.Exists)
            {
                return;
            }
            if (fi.Length > 0x10009C && fi.Length != 0x380000 && !SAV3GCMemoryCard.IsMemoryCardSize(fi.Length))
            {
                WinFormsUtil.Error("Input file is too large." + Environment.NewLine + $"Size: {fi.Length} bytes", path);
            }
            else if (fi.Length < 32)
            {
                WinFormsUtil.Error("Input file is too small." + Environment.NewLine + $"Size: {fi.Length} bytes", path);
            }
            else
            {
                byte[] input; try { input = File.ReadAllBytes(path); }
                catch (Exception e) { WinFormsUtil.Error("Unable to load file.  It could be in use by another program.\nPath: " + path, e); return; }

#if DEBUG
                OpenFile(input, path, ext, C_SAV.SAV);
#else
                try { OpenFile(input, path, ext, C_SAV.SAV); }
                catch (Exception e) { WinFormsUtil.Error("Unable to load file.\nPath: " + path, e); }
#endif
            }
        }