Ejemplo n.º 1
0
        static public eErrorType sendFile(XboxConsole console, string localName, string remoteName, bool createDir, bool onlyIfNewer)
        {
            if (console == null)
            {
                return(eErrorType.cNotConnected);
            }

            eErrorType res = eErrorType.c*K;

            try
            {
                if (createDir)
                {
                    string path = remoteName;
                    int    i    = path.LastIndexOf('\\');
                    if (i >= 0)
                    {
                        path = path.Substring(0, i);
                    }
                    createDirectory(console, path);
                }

                bool     gotLocalDateTime = false;
                DateTime localDateTime    = DateTime.Now;
                try
                {
                    localDateTime    = File.GetLastWriteTime(localName);
                    gotLocalDateTime = true;
                }
                catch { }

                if (onlyIfNewer && gotLocalDateTime)
                {
                    IXboxFile fileObject = null;
                    try
                    {
                        fileObject = console.GetFileObject(remoteName);
                    }
                    catch { }
                    if (fileObject != null)
                    {
                        DateTime remoteDateTime = (DateTime)fileObject.ChangeTime;
                        if (localDateTime <= remoteDateTime)
                        {
                            return(res);
                        }
                    }
                }

                console.SendFile(localName, remoteName);
            }
            catch (Exception e)
            {
                res = errorCatch(e);
            }
            return(res);
        }
Ejemplo n.º 2
0
        public void UploadLocalFile()
        {
            try
            {
                string type = GridViewLocalFiles.GetRowCellValue(GridViewLocalFiles.FocusedRowHandle, "Type").ToString();
                string name = GridViewLocalFiles.GetRowCellValue(GridViewLocalFiles.FocusedRowHandle, "Name").ToString();

                if (type.Equals("file"))
                {
                    string localPath   = TextBoxLocalPath.Text + name;
                    string consolePath = TextBoxConsolePath.Text + name;

                    if (File.Exists(localPath))
                    {
                        SetLocalStatus($"Uploading file to {consolePath}...");

                        if (ConsoleType == ConsoleTypePrefix.PS3)
                        {
                            FtpExtensions.UploadFile(localPath, consolePath);
                        }
                        else
                        {
                            XboxConsole.SendFile(localPath, consolePath);
                        }

                        SetLocalStatus($"Successfully uploaded file: {Path.GetFileName(localPath)}");
                        LoadConsoleDirectory(DirectoryPathConsole);
                    }
                    else
                    {
                        SetLocalStatus("Unable to upload file as it doesn't exist on your computer.");
                    }
                }
                else if (type.Equals("folder"))
                {
                    string localPath   = TextBoxLocalPath.Text + name + @"\";
                    string consolePath = TextBoxConsolePath.Text + name;

                    SetLocalStatus($"Uploading folder to {consolePath}...");
                    //FtpClient.UploadDirectory(localPath, consolePath, FtpFolderSyncMode.Update, FtpRemoteExists.Overwrite);
                    SetLocalStatus($"Successfully uploaded folder: {localPath}");
                    LoadConsoleDirectory(DirectoryPathConsole);
                }
            }
            catch (Exception ex)
            {
                SetLocalStatus($"Unable to upload to console. Error: {ex.Message}", ex);
            }
        }