Пример #1
0
        /// <summary>
        /// Loads a file from disk
        /// </summary>
        /// <typeparam name="T">Type of the file</typeparam>
        /// <param name="fileName"> Name of the file</param>
        /// <param name="fileType">The file exstention Type</param>
        /// <param name="outputData">A ref for the file that will be loaded</param>
        /// <returns>if the loading was succesfull. Needed because a save file can be non existant</returns>
        public static bool Load <T>(string fileName, fileTypes fileType, ref T outputData)
        {
            string saveFile = SaveLocation(fileType);

            saveFile += GetFileType(fileName, fileType);
            bool returnval = false;


            if (!File.Exists(saveFile))
            {
                outputData = default(T);
                returnval  = false;
            }
            else
            {
                IFormatter formatter = new BinaryFormatter();
                FileStream stream    = new FileStream(saveFile, FileMode.Open);

                T data = (T)formatter.Deserialize(stream);
                outputData = data;
                returnval  = true;
                stream.Close();
            }
            return(returnval);
        }
Пример #2
0
        /// <summary>
        /// Save file to disk
        /// </summary>
        /// <typeparam name="T">Type of the file</typeparam>
        /// <param name="fileName">File name with out exstentions</param>
        /// <param name="fileType">The type of file</param>
        /// <param name="data">The actual data fo the file</param>
        public static void Save <T>(string fileName, fileTypes fileType, T data)
        {
            string saveFile = SaveLocation(fileType);

            saveFile += GetFileType(fileName, fileType);

            try
            {
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream(saveFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                formatter.Serialize(stream, data);
                stream.Close();
            }
            catch (Exception e)
            {
                PlatformSafeMessage("Failed to Save: " + e.Message);
            }


            if (Application.platform == RuntimePlatform.WebGLPlayer)
            {
                SyncFiles();
            }

            Debug.Log(System.DateTime.Now + " Saved file: " + saveFile);
        }
Пример #3
0
    /// <summary>
    /// Import XML data into this camera path overwriting the current data
    /// </summary>
    /// <param name="XMLPath">An XML file path</param>
    public void FromXML(string XMLPath)
    {
        Debug.Log("Import Track BuildR Track XML " + XMLPath);
        Clear();
        XmlDocument xml = new XmlDocument();

        using (StreamReader sr = new StreamReader(XMLPath))
        {
            xml.LoadXml(sr.ReadToEnd());
        }

        XmlNode trackNode = xml.SelectNodes("trackbuildr")[0];

        version = float.Parse(trackNode["version"].FirstChild.Value);

        if (trackNode["name"] != null)
        {
            name = trackNode["name"].FirstChild.Value;
        }

        if (trackNode["fileType"] != null)
        {
            fileType       = (fileTypes)System.Enum.Parse(typeof(fileTypes), trackNode["fileType"].FirstChild.Value);
            exportFilename = trackNode["exportFilename"].FirstChild.Value;
            copyTexturesIntoExportFolder = bool.Parse(trackNode["copyTexturesIntoExportFolder"].FirstChild.Value);
            exportCollider       = bool.Parse(trackNode["exportCollider"].FirstChild.Value);
            createPrefabOnExport = bool.Parse(trackNode["createPrefabOnExport"].FirstChild.Value);
        }
        //send data to track
        track.FromXML(trackNode.SelectSingleNode("track"));
    }
Пример #4
0
        public static void Save <T>(string fileName, fileTypes fileType, T token)
        {
            string saveFile = SaveLocation(fileType);

            saveFile += GetFileType(fileName, fileType);

            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream(saveFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);

            formatter.Serialize(stream, token);
            stream.Close();

            Debug.Log("Saved file: " + saveFile + " At " + System.DateTime.Now);
        }
Пример #5
0
    public bool SaveFile(fileTypes type, string applicationID, string id, byte[] fileContent, string SID, string hash)
    {
        EnsureValidHash(SID, hash);

        User user = NullSaveGetUser(SID);

        int appID = 0;

        if (int.TryParse(applicationID, out appID) == false)
        {
            return(false);
        }

        if (type == fileTypes.References)
        {
            int referenceID = 0;

            if (int.TryParse(id, out referenceID) == false)
            {
                return(false);
            }

            return(UploadReferences(referenceID, fileContent));
        }
        else if (type == fileTypes.Publications)
        {
            return(UploadPublications(appID, fileContent));
        }
        else if (type == fileTypes.Other)
        {
            int fileTypeID = 0;

            if (int.TryParse(id, out fileTypeID) == false)
            {
                return(false);
            }

            return(UploadFiles(appID, fileTypeID, fileContent));
        }
        else
        {
            return(false);
        }
    }
Пример #6
0
        public static string SaveLocation(fileTypes fileType)
        {
            string saveLocation;

            if (Application.isEditor)
            {
                saveLocation = Application.dataPath + "/" + saveFolderName + "/" + FileLocations[fileType] + "/";
            }
            else
            {
                saveLocation = Application.persistentDataPath + "/" + saveFolderName + "/" + FileLocations[fileType] + "/";
            }

            if (!Directory.Exists(saveLocation))
            {
                Directory.CreateDirectory(saveLocation);
            }
            return(saveLocation);
        }
Пример #7
0
        /// <summary>
        /// Generates a string for where the file is located
        /// </summary>
        /// <param name="fileType">The type of file can matter for directory</param>
        /// <returns></returns>
        private static string SaveLocation(fileTypes fileType)
        {
            string saveLocation = Application.dataPath;

            if (!Application.isEditor)
            {
                saveLocation += "/..";
            }
            if (Application.platform == RuntimePlatform.WebGLPlayer)
            {
                saveLocation = Application.persistentDataPath;
            }

            saveLocation += "/" + saveFolderName + "/" + FileLocations[fileType] + "/";
            if (!Directory.Exists(saveLocation))
            {
                Directory.CreateDirectory(saveLocation);
            }
            return(saveLocation);
        }
    protected void Page_PreRender(object sender, EventArgs e)
    {
        FileUploadHolder.Attributes["class"] = this.cssClass;
        Imageholder.Visible   = this.showImage;
        MyImage.AlternateText = this.alternativeText;
        if (this.imageUrl.Contains("http://"))
        {
            MyImage.ImageUrl = this.imageUrl;
        }
        else
        {
            if (imageUrl == "")
            {
                imageUrl = Value;
            }
            MyImage.ImageUrl = siteDefaults.SiteUrl + "/" + this.imageUrl.Replace("../", "");
        }
        MyTextBoxHolderClass.Visible = this.showTextBox;
        if (fileTypeList != "")
        {
            this.types = fileTypes.Other;
        }
        switch (this.types)
        {
        case fileTypes.Image:
            fileExt          = "*.jpg;*.gif;*.png";
            fileDesc         = "image files";
            SendedParameters = "'filetype':'image'";
            if (dimension != "")
            {
                SendedParameters += ",'dimension':'" + dimension + "'";
            }
            break;

        case fileTypes.Music:
            fileExt          = "*.mp3;*.wav";
            fileDesc         = "music files";
            SendedParameters = "'filetype':'music'";
            break;

        case fileTypes.Text:
            fileExt          = "*.pdf;*.doc";
            fileDesc         = "text files";
            SendedParameters = "'filetype':'text'";
            break;

        case fileTypes.Video:
            fileExt          = "*.flv";
            fileDesc         = "video files";
            SendedParameters = "'filetype':'video'";
            break;

        case fileTypes.ALL:
            fileExt          = "*.7z;*.aiff;*.asf;*.avi;*.bmp;*.csv;*.doc;*.docx;*.fla;*.flv;*.gif;*.gz;*.gzip;*.jpeg;*.jpg;*.mid;*.mov;*.mp3;*.mp4;*.mpc;*.mpeg;*.mpg;*.ods;*.odt;*.pdf;*.png;*.ppt;*.pptx;*.pxd;*.qt;*.ram;*.rar;*.rm;*.rmi;*.rmvb;*.rtf;*.sdc;*.sitd;*.swf;*.sxc;*.sxw;*.tar;*.tgz;*.tif;*.tiff;*.txt;*.vsd;*.wav;*.wma;*.wmv;*.xls;*.xlsx;*.zip";
            fileDesc         = "All files";
            SendedParameters = "'filetype':'all'";
            break;

        case fileTypes.Other:
        default:
            fileExt          = this.fileTypeList;
            fileDesc         = "user files";
            SendedParameters = "'filetype':'others'";
            break;
        }
        CropButton.Visible = hasCrop;
        if (HasCrop)
        {
            string _jscrop = "";
            _jscrop += "var jcrop_api;";
            _jscrop += "$(document).ready(function () { mycrop();});";
            _jscrop += "function mycrop(){";
            _jscrop += "$('#" + MyImage.ClientID + "').Jcrop({";
            _jscrop += "onSelect: updateCoords";
            _jscrop += "}";
            _jscrop += ",function(){";
            _jscrop += " jcrop_api = this;";
            _jscrop += " });";
            _jscrop += "};";
            _jscrop += "function updateCoords(c) {";
            _jscrop += "$('#" + X.ClientID + "').val(c.x);";
            _jscrop += " $('#" + Y.ClientID + "').val(c.y);";
            _jscrop += " $('#" + W.ClientID + "').val(c.w);";
            _jscrop += " $('#" + H.ClientID + "').val(c.h);";
            _jscrop += "};";
            Page.ClientScript.RegisterStartupScript(typeof(Page), "_jscrop" + W.ClientID, _jscrop, true);
        }
    }
Пример #9
0
 /// <summary>
 /// Returns file type with name attached
 /// </summary>
 /// <param name="fileName">The name of the file</param>
 /// <param name="fileType">The type of file</param>
 /// <returns>Name + Type </returns>
 private static string GetFileType(string fileName, fileTypes fileType)
 {
     return(fileName + fileExstentions[fileType]);
 }
    public bool SaveFile(fileTypes type, string applicationID, string id, byte[] fileContent, string SID, string hash)
    {
        EnsureValidHash(SID, hash);

        User user = NullSaveGetUser(SID);

        int appID = 0;

        if (int.TryParse(applicationID, out appID) == false)
            return false;

        if (type == fileTypes.References)
        {
            int referenceID = 0;

            if (int.TryParse(id, out referenceID) == false)
                return false;

            return UploadReferences(referenceID, fileContent);
        }
        else if (type == fileTypes.Publications)
        {
            return UploadPublications(appID, fileContent);
        }
        else if (type == fileTypes.Other)
        {
            int fileTypeID = 0;

            if (int.TryParse(id, out fileTypeID) == false)
                return false;

            return UploadFiles(appID, fileTypeID, fileContent);
        }
        else
        {
            return false;
        }
    }
Пример #11
0
    /// <summary>
    /// Import XML data into this camera path overwriting the current data
    /// </summary>
    /// <param name="XMLPath">An XML file path</param>
    public void FromXML(string XMLPath)
    {
        Debug.Log("Import Track BuildR Track XML " + XMLPath);
        Clear();
        XmlDocument xml = new XmlDocument();
        using (StreamReader sr = new StreamReader(XMLPath))
        {
            xml.LoadXml(sr.ReadToEnd());
        }
        
        XmlNode trackNode = xml.SelectNodes("trackbuildr")[0];
        version = float.Parse(trackNode["version"].FirstChild.Value);

        if (trackNode["name"] != null)
            name = trackNode["name"].FirstChild.Value;

        if(trackNode["fileType"] != null)
        {
            fileType = (fileTypes)System.Enum.Parse(typeof(fileTypes), trackNode["fileType"].FirstChild.Value);
            exportFilename = trackNode["exportFilename"].FirstChild.Value;
            copyTexturesIntoExportFolder = bool.Parse(trackNode["copyTexturesIntoExportFolder"].FirstChild.Value);
            exportCollider = bool.Parse(trackNode["exportCollider"].FirstChild.Value);
            createPrefabOnExport = bool.Parse(trackNode["createPrefabOnExport"].FirstChild.Value);
        }
        //send data to track
        track.FromXML(trackNode.SelectSingleNode("track"));
    }