コード例 #1
0
        public static SavedOptions Load(string path)
        {
            SavedOptions result = null;

            XmlSerializer x = new XmlSerializer(typeof(SavedOptions));

            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Open))
                {
                    if (fs.Length == 0)
                    {
                        // nothing inside
                        return(null);
                    }
                    XmlReader reader = new XmlTextReader(fs);
                    result = (SavedOptions)x.Deserialize(reader);
                    fs.Close();
                }
            }
            catch (Exception e)
            {
                Debug.LogFormat("Build Report Tool: Error found upon loading options XML file in {0}\nWill create a new options file instead.\n\nError: {1}", path, e);
                return(new SavedOptions());
            }

            //Debug.LogFormat("Build Report Tool: Loaded options from: {0}", path);
            return(result);
        }
コード例 #2
0
        public static void Save(string savePath, SavedOptions optionsToSave)
        {
            optionsToSave.OnBeforeSave();

            XmlSerializer x      = new XmlSerializer(typeof(SavedOptions));
            TextWriter    writer = new StreamWriter(savePath);

            x.Serialize(writer, optionsToSave);
            writer.Close();

            //Debug.LogFormat("Build Report Tool: Saved options to: {0}", savePath);
        }
コード例 #3
0
        static void SaveOptions()
        {
            if (string.IsNullOrEmpty(_foundPathForSavedOptions))
            {
                return;
            }
            if (_savedOptions == null || !File.Exists(_foundPathForSavedOptions))
            {
                _foundPathForSavedOptions = string.Empty;
                return;
            }

            SavedOptions.Save(_foundPathForSavedOptions, _savedOptions);
        }
コード例 #4
0
        public static SavedOptions Load(string path)
        {
            SavedOptions result = null;

            XmlSerializer x = new XmlSerializer(typeof(SavedOptions));

            using (FileStream fs = new FileStream(path, FileMode.Open))
            {
                if (fs.Length == 0)
                {
                    // nothing inside
                    return(null);
                }
                XmlReader reader = new XmlTextReader(fs);
                result = (SavedOptions)x.Deserialize(reader);
                fs.Close();
            }

            //Debug.LogFormat("Build Report Tool: Loaded options from: {0}", path);
            return(result);
        }
コード例 #5
0
        static void InitializeOptionsIfNeeded()
        {
            if (_savedOptions == null)
            {
                _foundPathForSavedOptions = string.Empty;
            }

            if (string.IsNullOrEmpty(_foundPathForSavedOptions))
            {
                // look for the file in this order:
                // 1. inside the BuildReport folder
                // 2. at the very topmost Assets folder
                // 3. outside the Assets folder
                // 4. in the ProjectSettings folder
                // 5. in the User's My Documents folder


                // ---------------------------------------------------
                // look in /Assets/BuildReport/
                var optionsInBuildReportFolder = DefaultOptionsPath;
                if (File.Exists(optionsInBuildReportFolder))
                {
                    _savedOptions             = BuildReportTool.SavedOptions.Load(optionsInBuildReportFolder);
                    _foundPathForSavedOptions = optionsInBuildReportFolder;
                    return;
                }

                // ---------------------------------------------------
                // look in /Assets/Plugins/BuildReport/
                var optionsInPluginsBuildReport = string.Format("{0}/Plugins/BuildReport/{1}", Application.dataPath, SAVED_OPTIONS_FILENAME);
                if (File.Exists(optionsInPluginsBuildReport))
                {
                    _savedOptions             = BuildReportTool.SavedOptions.Load(optionsInPluginsBuildReport);
                    _foundPathForSavedOptions = optionsInPluginsBuildReport;
                    return;
                }

                // ---------------------------------------------------
                // search for "BuildReport" folder and look in there
                if (!IsBuildReportInRegularPaths)
                {
                    string customBuildReportFolder = BuildReportTool.Util.FindAssetFolder(Application.dataPath, BUILD_REPORT_TOOL_DEFAULT_FOLDER_NAME);
                    if (!string.IsNullOrEmpty(customBuildReportFolder))
                    {
                        var optionsInCustomBuildReportFolder = string.Format("{0}/{1}", customBuildReportFolder, SAVED_OPTIONS_FILENAME);
                        if (File.Exists(optionsInCustomBuildReportFolder))
                        {
                            _savedOptions             = BuildReportTool.SavedOptions.Load(optionsInCustomBuildReportFolder);
                            _foundPathForSavedOptions = optionsInCustomBuildReportFolder;
                            return;
                        }
                    }
                }

                // ---------------------------------------------------
                // look in /Assets/
                var optionsInTopmostAssets = string.Format("{0}/{1}", Application.dataPath, SAVED_OPTIONS_FILENAME);
                if (File.Exists(optionsInTopmostAssets))
                {
                    _savedOptions             = BuildReportTool.SavedOptions.Load(optionsInTopmostAssets);
                    _foundPathForSavedOptions = optionsInTopmostAssets;
                    return;
                }

                // ---------------------------------------------------
                // look in Unity project folder (where Assets, Library, and ProjectSettings folder are)
                var outsideAssets        = BuildReportTool.Util.GetProjectPath(Application.dataPath);
                var optionsOutsideAssets = string.Format("{0}{1}", outsideAssets, SAVED_OPTIONS_FILENAME);
                if (File.Exists(optionsOutsideAssets))
                {
                    _savedOptions             = BuildReportTool.SavedOptions.Load(optionsOutsideAssets);
                    _foundPathForSavedOptions = optionsOutsideAssets;
                    return;
                }

                // ---------------------------------------------------
                // look inside ProjectSettings folder
                var optionsInProjectSettings = string.Format("{0}ProjectSettings/{1}", outsideAssets, SAVED_OPTIONS_FILENAME);
                //Debug.LogFormat("Looking in {0}", optionsInProjectSettings);
                if (File.Exists(optionsInProjectSettings))
                {
                    _savedOptions             = BuildReportTool.SavedOptions.Load(optionsInProjectSettings);
                    _foundPathForSavedOptions = optionsInProjectSettings;
                    return;
                }

                // ---------------------------------------------------
                // look in /My Documents/UnityBuildReports/
                var optionsInMyDocs = string.Format("{0}/{1}/{2}", BuildReportTool.Util.GetUserHomeFolder(), BUILD_REPORTS_DEFAULT_FOLDER_NAME, SAVED_OPTIONS_FILENAME);
                //Debug.LogFormat("Looking in {0}", optionsInMyDocs);
                if (File.Exists(optionsInMyDocs))
                {
                    _savedOptions             = BuildReportTool.SavedOptions.Load(optionsInMyDocs);
                    _foundPathForSavedOptions = optionsInMyDocs;
                    return;
                }

                // ---------------------------------------------------
            }

            // if the options file failed to load
            // one last try
            //
            if (_savedOptions == null)
            {
                if (!string.IsNullOrEmpty(_foundPathForSavedOptions) && File.Exists(_foundPathForSavedOptions))
                {
                    // there's a valid options file already
                    // just load that one
                    _savedOptions = BuildReportTool.SavedOptions.Load(_foundPathForSavedOptions);
                }
            }

            // could not load the file, or there isn't one yet (at least, not in any recognized valid paths).
            // so create a new one at the default path
            if (_savedOptions == null)
            {
                _savedOptions             = new BuildReportTool.SavedOptions();
                _foundPathForSavedOptions = DefaultOptionsPath;

                var defaultFolder = Path.GetDirectoryName(_foundPathForSavedOptions);
                if (!string.IsNullOrEmpty(defaultFolder) && !Directory.Exists(defaultFolder))
                {
                    Directory.CreateDirectory(defaultFolder);
                }

                SavedOptions.Save(_foundPathForSavedOptions, _savedOptions);
                Debug.LogFormat("Build Report Tool: Created a new options file at: {0}", _foundPathForSavedOptions);
            }
        }