public static string GetSystemPath(string strSysFolder, string strSysSubFolder = "")
        {
            string strPath = "";

            RscStore store = new RscStore();

            strPath = strPath + "A:\\System";
            if (!store.FolderExists(strPath))
            {
                store.CreateFolder(strPath);
            }
            strPath = strPath + "\\";

            strPath = strPath + strSysFolder;
            if (!store.FolderExists(strPath))
            {
                store.CreateFolder(strPath);
            }
            //strPath = strPath + "\\";

            if (strSysSubFolder.Length > 0)
            {
                strPath = strPath + "\\";

                strPath = strPath + strSysSubFolder;
                if (!store.FolderExists(strPath))
                {
                    store.CreateFolder(strPath);
                }
                //strPath = strPath + "\\";
            }

            return(strPath);
        }
        public static string GetMediaPath(string strSysFolder, string strSysSubFolder = "", bool bCreate = true)
        {
            string strPath = "";

            RscStore store = new RscStore();

            strPath = strPath + "A:\\Media";
            if (!store.FolderExists(strPath))
            {
                if (bCreate)
                {
                    store.CreateFolder(strPath);
                }
            }
            strPath = strPath + "\\";

            strPath = strPath + strSysFolder;
            if (!store.FolderExists(strPath))
            {
                if (bCreate)
                {
                    store.CreateFolder(strPath);
                }
            }
            //strPath = strPath + "\\";

            if (strSysSubFolder.Length > 0)
            {
                strPath = strPath + "\\";

                strPath = strPath + strSysSubFolder;
                if (!store.FolderExists(strPath))
                {
                    if (bCreate)
                    {
                        store.CreateFolder(strPath);
                    }
                }
                //strPath = strPath + "\\";
            }

            return(strPath);
        }
Exemple #3
0
        private void m_btnDownloadFile_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (m_sLastFile.Length == 0)
            {
                return;
            }

            if (m_bLastFileIsFolder)
            {
                return;
            }

            if (m_lLastFileSize < 0)
            {
                return;
            }

            if (m_ftpc.WorkingDirectory.Length == 0)
            {
                return;
            }

            string sPath = m_ftpc.WorkingDirectory;

            sPath += m_sLastFile;

            RscStore store = new RscStore();

            string sLocalPath = "A:\\FTP";

            if (!store.FolderExists(sLocalPath))
            {
                store.CreateFolder(sLocalPath);
            }
            sLocalPath += "\\" + m_sLastFile;
            if (store.FileExists(sLocalPath))
            {
                store.DeleteFile(sLocalPath);
            }
            System.IO.Stream stream = store.CreateFile(sLocalPath);

            RscFtpClientCommand cmd = RscFtpClientCommand.DownloadBin(sPath, m_lLastFileSize, "", null, stream);

            _SendAutoPASV(cmd);
        }
Exemple #4
0
        private void m_ftpc_ServerDataReceivedSYNC(object sender, Ressive.FTP.RscFtpCommandEventArgs e)
        {
            if (!e.ServerData.ParseOk)
            {
                _Log("20", "<DATA ERROR> " + e.ClientCommand.ToString( ), false);
            }
            else
            {
                switch (e.ClientCommand.Command)
                {
                case "LIST":
                {
                    prsBarData.Visibility = Rsc.Collapsed;

                    int iCount;
                    RscFtpServerDataItemFileInfo fi;

                    iCount = e.ServerData.Count;

                    if (iCount == 0)
                    {
                        _Log("20", e.ClientCommand.Command + " returned 0 item.", false, true);
                    }
                    else
                    {
                        for (int i = 0; i < iCount; i++)
                        {
                            fi = (RscFtpServerDataItemFileInfo)e.ServerData.GetItem(i);

                            _Log("20", fi.GetItemTitle( ), false, true, fi);
                        }
                    }

                    break;
                }

                case "RETR":
                {
                    prsBarData.Visibility = Rsc.Collapsed;

                    _Log("20", e.ClientCommand.Command + " returned " +
                         e.ClientCommand.DataSize.ToString() + " bytes.", false, true);

                    if (e.ClientCommand.HasMemStream)
                    {
                        string sPath = e.ClientCommand.Arg1;
                        int    iPos  = sPath.LastIndexOf(m_ftpc.BackSlashInPath);
                        string sFn   = sPath;
                        if (iPos >= 0)
                        {
                            sFn = sPath.Substring(iPos + m_ftpc.BackSlashInPath.Length);
                        }

                        _Log("20", e.ClientCommand.Command + " saving local file '" +
                             sFn + "'.", false, true);

                        RscStore store = new RscStore();

                        string sLocalPath = "A:\\FTP";
                        if (!store.FolderExists(sLocalPath))
                        {
                            store.CreateFolder(sLocalPath);
                        }
                        sLocalPath += "\\" + sFn;
                        if (store.FileExists(sLocalPath))
                        {
                            store.DeleteFile(sLocalPath);
                        }

                        System.IO.Stream stream = store.CreateFile(sLocalPath);
                        e.ServerData.MemStream.WriteTo(stream);
                        e.ServerData.MemStream.Close();
                        stream.Close();
                    }

                    break;
                }
                }
            }
        }
        private void SaveImage(string sIndiciesToItem, bool bThumbnail)
        {
            RscStore store = new RscStore();

            //string sFolder = RscKnownFolders.GetMediaPath("Zune");
            string sFolder = RscKnownFolders.GetMediaPath("Media Library");

            // //
            //

            PictureAlbum pa  = m_media.RootPictureAlbum;
            Picture      pic = null;

            string [] asInd = sIndiciesToItem.Split('|');
            int       iCnt  = asInd.Length;

            for (int i = 0; i < iCnt; i++)
            {
                if (i == iCnt - 1)
                {
                    sFolder += "\\" + pa.Name;
                    if (!store.FolderExists(sFolder))
                    {
                        store.CreateFolder(sFolder);
                    }

                    pic = pa.Pictures[Int32.Parse(asInd[i])];
                }
                else
                {
                    sFolder += "\\" + pa.Name;
                    if (!store.FolderExists(sFolder))
                    {
                        store.CreateFolder(sFolder);
                    }

                    pa = pa.Albums[Int32.Parse(asInd[i])];
                }
            }

            if (bThumbnail)
            {
                sFolder += "\\" + "tn";
                if (!store.FolderExists(sFolder))
                {
                    store.CreateFolder(sFolder);
                }
            }

            //
            // //

            string sPreExt = "";

            if (bThumbnail)
            {
                sPreExt = ".tn";
            }

            string sFName = pic.Name;
            string sFExt  = "";
            int    iPos   = sFName.LastIndexOf('.');

            if (iPos >= 0)
            {
                sFExt  = sFName.Substring(iPos);
                sFName = sFName.Substring(0, iPos);
            }

            string sPath = sFolder + "\\" + sFName + sPreExt + sFExt;

            iCnt = 0;
            for (;;)
            {
                if (!store.FileExists(sPath))
                {
                    break;
                }
                iCnt++;
                sPath = sFolder + "\\" + sFName + "_" + iCnt.ToString() + sPreExt + sFExt;
            }

            System.IO.Stream strmSrc;
            if (bThumbnail)
            {
                strmSrc = pic.GetThumbnail();
            }
            else
            {
                strmSrc = pic.GetImage();
            }

            System.IO.Stream stream = store.CreateFile(sPath);
            // Initialize the buffer for 4KB disk pages.
            byte[] readBuffer = new byte[4096];
            int    bytesRead  = -1;

            // Copy the image/thumbnail to the local folder.
            while ((bytesRead = strmSrc.Read(readBuffer, 0, readBuffer.Length)) > 0)
            {
                stream.Write(readBuffer, 0, bytesRead);
            }
            stream.Close();

            strmSrc.Close();
        }
        private void m_AppFrame_OnTimer_Sub1(object sender, RscAppFrameTimerEventArgs e)
        {
            switch (e.Reason)
            {
            case "copy move files_Cancel":
            {
                m_AppFrame.SetStatusText("User canceled operation!", StatusColoring.Error);
                break;
            }

            case "copy move files":
            {
                int iRootLen = m_txtRootFldr.Text.Length;

                if (e.Pos == 0)
                {
                    foreach (RscFileItemDesc itFldr in m_folders)
                    {
                        string sPart = itFldr.Path.Substring(iRootLen);
                        if (sPart.Length > 0)
                        {
                            string sNewFolder = m_sCopyMoveDest;
                            if (iRootLen == 0)
                            {
                                sNewFolder += "\\";
                            }
                            sNewFolder += sPart;

                            try
                            {
                                RscStore store = new RscStore();
                                store.CreateFolder(sNewFolder);
                            }
                            catch (Exception /*exc*/)
                            {
                                m_AppFrame.SetStatusText("ERR: Unable to copy folder stru near: " + sNewFolder, StatusColoring.Error);
                                e.Completed = true;
                                return;
                            }
                        }
                    }

                    e.Max = 1;
                }
                else
                {
                    RscFileItemDesc it = m_files[e.Pos - 1];

                    string sErr = "";
                    try
                    {
                        string sCopyMoveTo = m_sCopyMoveDest;
                        if (iRootLen == 0)
                        {
                            sCopyMoveTo += "\\";
                        }
                        sCopyMoveTo += it.Path.Substring(iRootLen);

                        RscStore store = new RscStore();

                        if (m_sCopyMove == "move")
                        {
                            store.MoveFileForce(it.Path, sCopyMoveTo);
                        }
                        else
                        {
                            store.CopyFileForce(it.Path, sCopyMoveTo);
                        }
                    }
                    catch (Exception exc)
                    {
                        sErr = "Unable to " + m_sCopyMove + " file.\r\n" + exc.Message;
                    }

                    if (sErr.Length == 0)
                    {
                        m_files.RemoveAt(e.Pos - 1);

                        if ((e.Pos - 1) < m_files.Count)
                        {
                            int iPos = e.Pos;
                            e.Pos = iPos;                                     //Denie subsys to increment...
                        }
                        else
                        {
                            e.Completed = true;
                        }
                    }
                    else
                    {
                        it.LastError = sErr;

                        //ReQuery...
                        lbFiles.ItemsSource = null;
                        lbFiles.ItemsSource = m_files;

                        if ((e.Pos - 1) < (m_files.Count - 1))
                        {
                            e.Max++;
                        }
                        else
                        {
                            e.Completed = true;
                        }
                    }

                    if (e.Completed)
                    {
                        if (m_sCopyMove == "move")
                        {
                            if (m_files.Count == 0)                                      //Otherwise error occured...
                            {
                                if (chbRecurse.IsChecked.Value)                          //Otherwise no sub-tree deletion...
                                {
                                    int iIdx = (m_folders.Count - 1) + 1;
                                    for (;;)
                                    {
                                        iIdx--;
                                        if (iIdx < 0)
                                        {
                                            break;
                                        }

                                        try
                                        {
                                            if (m_folders[iIdx].Path.Substring(iRootLen).Length > 0)
                                            {
                                                RscStore store = new RscStore();
                                                store.DeleteFolder(m_folders[iIdx].Path);
                                            }

                                            m_folders.RemoveAt(iIdx);
                                        }
                                        catch (Exception /*exc*/)
                                        {
                                        }
                                    }
                                }
                            }

                            if (m_files.Count == 0)
                            {
                                m_AppFrame.SetStatusText("Move succeeded!", StatusColoring.Success);
                            }
                            else
                            {
                                m_AppFrame.SetStatusText("Move failed for some item(s)!", StatusColoring.Error);
                            }
                        }
                        else
                        {
                            if (m_files.Count == 0)
                            {
                                m_AppFrame.SetStatusText("Copy succeeded!", StatusColoring.Success);
                            }
                            else
                            {
                                m_AppFrame.SetStatusText("Copy failed for some item(s)!", StatusColoring.Error);
                            }
                        }

                        //Causes exception...
                        //ListFiles();

                        ActionPanel.Visibility = Rsc.Collapsed;
                    }
                }

                break;
            }

            case "delete files_Cancel":
            {
                m_AppFrame.SetStatusText("User canceled operation!", StatusColoring.Error);
                break;
            }

            case "delete files":
            {
                if (e.Pos >= m_files.Count)
                {
                    e.Completed = true;
                }
                else
                {
                    RscFileItemDesc it = m_files[e.Pos];

                    string sErr = "";
                    try
                    {
                        RscStore store = new RscStore();
                        store.DeleteFile(it.Path);
                    }
                    catch (Exception exc)
                    {
                        sErr = "Unable to delete file.\r\n" + exc.Message;
                    }

                    if (sErr.Length == 0)
                    {
                        m_files.RemoveAt(e.Pos);

                        if (e.Pos < m_files.Count)
                        {
                            int iPos = e.Pos;
                            e.Pos = iPos;                                     //Denie subsys to increment...
                        }
                        else
                        {
                            e.Completed = true;
                        }
                    }
                    else
                    {
                        it.LastError = sErr;

                        //ReQuery...
                        lbFiles.ItemsSource = null;
                        lbFiles.ItemsSource = m_files;

                        if (e.Pos < (m_files.Count - 1))
                        {
                            e.Max++;
                        }
                        else
                        {
                            e.Completed = true;
                        }
                    }
                }

                if (e.Completed)
                {
                    if (m_files.Count == 0)                              //Otherwise error occured...
                    {
                        if (chbRecurse.IsChecked.Value)                  //Otherwise no sub-tree deletion...
                        {
                            int iIdx = (m_folders.Count - 1) + 1;
                            for (;;)
                            {
                                iIdx--;
                                if (iIdx < 0)
                                {
                                    break;
                                }

                                try
                                {
                                    if (m_folders[iIdx].Path.Length > 0)
                                    {
                                        RscStore store = new RscStore();
                                        store.DeleteFolder(m_folders[iIdx].Path);
                                    }

                                    m_folders.RemoveAt(iIdx);
                                }
                                catch (Exception /*exc*/)
                                {
                                }
                            }
                        }
                    }

                    if (m_files.Count == 0)
                    {
                        m_AppFrame.SetStatusText("Delete succeeded!", StatusColoring.Success);

                        // //
                        //

                        if (m_sAutoOperation.Length > 0)
                        {
                            if (m_iAutoOpPath + 1 < m_asAutoOpPathes.Length)
                            {
                                m_iAutoOpPath++;
                                m_txtRootFldr.Text = m_asAutoOpPathes[m_iAutoOpPath];
                                m_AppFrame.AutoClick(m_btnCycle, new System.Windows.RoutedEventHandler(m_btnCycle_Click));
                            }
                            else
                            {
                                PrepareExit();
                                NavigationService.GoBack();
                            }
                        }

                        //
                        // //
                    }
                    else
                    {
                        m_AppFrame.SetStatusText("Delete failed for some item(s)!", StatusColoring.Error);
                    }

                    //Causes exception...
                    //ListFiles();

                    ActionPanel.Visibility = Rsc.Collapsed;
                }

                break;
            }
            }
        }
        private void SaveImage(bool bThumbnail)
        {
            RscStore store = new RscStore();

            string sFolder = m_sAppFolder;

            if (bThumbnail)
            {
                sFolder += "\\" + "tn";
                if (!store.FolderExists(sFolder))
                {
                    store.CreateFolder(sFolder);
                }
            }

            string sPreExt = "";

            if (bThumbnail)
            {
                sPreExt = ".tn";
            }

            string sFName = m_sPicFileName;
            string sFExt  = "";
            int    iPos   = sFName.LastIndexOf('.');

            if (iPos >= 0)
            {
                sFExt  = sFName.Substring(iPos);
                sFName = sFName.Substring(0, iPos);
            }

            string sPath = sFolder + "\\" + sFName + sPreExt + sFExt;

            /*
             * iCnt = 0;
             * for(;;)
             * {
             *      if( !store.FileExists(sPath) ) break;
             *      iCnt++;
             *      sPath = sFolder + "\\" + sFName + "_" + iCnt.ToString() + sPreExt + sFExt;
             * }
             */

            System.IO.Stream strmSrc;

            if (bThumbnail)
            {
                strmSrc = m_pic.GetThumbnail();
            }
            else
            {
                strmSrc = m_pic.GetImage();
            }

            if (store.FileExists(sPath))
            {
                store.DeleteFile(sPath);
            }

            System.IO.Stream stream = store.CreateFile(sPath);
            // Initialize the buffer for 4KB disk pages.
            byte[] readBuffer = new byte[4096];
            int    bytesRead  = -1;

            // Copy the image/thumbnail to the local folder.
            while ((bytesRead = strmSrc.Read(readBuffer, 0, readBuffer.Length)) > 0)
            {
                stream.Write(readBuffer, 0, bytesRead);
            }
            stream.Close();

            strmSrc.Close();

            if (!bThumbnail)
            {
                store.WriteTextFile(sFolder + "\\" + sFName + sPreExt + sFExt + ".inf", m_sInf, true);
            }
        }
        private string GetImagePath(string sIndiciesToItem, bool bThumbnail, out Picture pic, bool bForceCreateFolderPath = false)
        {
            RscStore store = new RscStore();

            //string sFolder = RscFs.GetRscMediaFolderPath("Zune");
            string sFolder = RscKnownFolders.GetMediaPath("Media Library", "", false);

            // //
            //

            PictureAlbum pa = m_media.RootPictureAlbum;

            pic = null;
            string [] asInd = sIndiciesToItem.Split('|');
            int       iCnt  = asInd.Length;

            for (int i = 0; i < iCnt; i++)
            {
                if (i == iCnt - 1)
                {
                    sFolder += "\\" + pa.Name;
                    if (!store.FolderExists(sFolder))
                    {
                        if (!bForceCreateFolderPath)
                        {
                            return("");
                        }
                        store.CreateFolder(sFolder);
                    }

                    pic = pa.Pictures[Int32.Parse(asInd[i])];
                }
                else
                {
                    sFolder += "\\" + pa.Name;
                    if (!store.FolderExists(sFolder))
                    {
                        if (!bForceCreateFolderPath)
                        {
                            return("");
                        }
                        store.CreateFolder(sFolder);
                    }

                    pa = pa.Albums[Int32.Parse(asInd[i])];
                }
            }

            if (bThumbnail)
            {
                sFolder += "\\" + "tn";
                if (!store.FolderExists(sFolder))
                {
                    if (!bForceCreateFolderPath)
                    {
                        return("");
                    }
                    store.CreateFolder(sFolder);
                }
            }

            //
            // //

            string sPreExt = "";

            if (bThumbnail)
            {
                sPreExt = ".tn";
            }

            string sFName = pic.Name;
            string sFExt  = "";
            int    iPos   = sFName.LastIndexOf('.');

            if (iPos >= 0)
            {
                sFExt  = sFName.Substring(iPos);
                sFName = sFName.Substring(0, iPos);
            }

            string sPath = sFolder + "\\" + sFName + sPreExt + sFExt;

            //ROLLBACK...

            /*
             * iCnt = 0;
             * for(;;)
             * {
             *      if( !store.FileExists(sPath) ) break;
             *      iCnt++;
             *      sPath = sFolder + "\\" + sFName + "_" + iCnt.ToString() + sPreExt + sFExt;
             * }
             */

            if (!bForceCreateFolderPath)
            {
                if (!store.FileExists(sPath))
                {
                    return("");
                }
            }

            return(sPath);
        }