Esempio n. 1
0
        public bool IsValidFilename(string filename, bool save, out string message)
        {
            if (filename == null)
            {
                message = "Invalid filename supplied - null"; return(false);
            }

            if (filename.Length == 0)
            {
                message = "Invalid filename supplied - zero length"; return(false);
            }

            try
            {
                string full = Path.GetFullPath(filename);
            }
            catch (Exception e)
            {
                message = "There was a serious problem trying to access the file.\n\n" + e.ToString();
                return(false);
            }

            if (!save)
            {
                try
                {
                    Model test = new Model();
                    test.Open(filename);

                    int numSTBLs = test.Count;

                    test.Close();

                    if (numSTBLs == 0)
                    {
                        message = "The selected package contains no String Table Sets.";
                        return(false);
                    }
                }
                catch (InvalidDataException e)
                {
                    message = "The selected file did not appear to be a valid Sims3 package.\n" +
                              "This could be because it is a protected file ('DBPP'),\n" +
                              "because it is a Sims2 or Spore package (major version below '2')\n" +
                              "or because the package is corrupt.\n\n" + e.Message;
                    return(false);
                }
                catch (Exception e)
                {
                    message = "There was a serious problem trying to read the file.\n\n" + e.ToString();
                    return(false);
                }
            }

            message = "";
            return(true);
        }