Exemplo n.º 1
0
        public void SaveSettings(string section)
        {
            if (AddOpticalDiskDrives)
            {
                AddStaticShares(DriveType.DVD, "DVD");
            }

            using (Profile.Settings xmlwriter = new MPSettings())
            {
                string defaultShare = string.Empty;

                for (int index = 0; index < 128; index++)
                {
                    string shareName       = String.Format("sharename{0}", index);
                    string sharePath       = String.Format("sharepath{0}", index);
                    string sharePin        = String.Format("pincode{0}", index);
                    string shareType       = String.Format("sharetype{0}", index);
                    string shareServer     = String.Format("shareserver{0}", index);
                    string shareLogin      = String.Format("sharelogin{0}", index);
                    string sharePwd        = String.Format("sharepassword{0}", index);
                    string sharePort       = String.Format("shareport{0}", index);
                    string shareRemotePath = String.Format("shareremotepath{0}", index);
                    string shareViewPath   = String.Format("shareview{0}", index);

                    xmlwriter.RemoveEntry(section, shareName);
                    xmlwriter.RemoveEntry(section, sharePath);
                    xmlwriter.RemoveEntry(section, sharePin);
                    xmlwriter.RemoveEntry(section, shareType);
                    xmlwriter.RemoveEntry(section, shareServer);
                    xmlwriter.RemoveEntry(section, shareLogin);
                    xmlwriter.RemoveEntry(section, sharePwd);
                    xmlwriter.RemoveEntry(section, sharePort);
                    xmlwriter.RemoveEntry(section, shareRemotePath);
                    xmlwriter.RemoveEntry(section, shareViewPath);

                    if (section == "music" || section == "movies")
                    {
                        string shareScan = String.Format("sharescan{0}", index);
                        xmlwriter.RemoveEntry(section, shareScan);
                    }

                    if (section == "movies")
                    {
                        string thumbs = String.Format("videothumbscreate{0}", index);
                        xmlwriter.RemoveEntry(section, thumbs);

                        string movieFolder = String.Format("eachfolderismovie{0}", index);
                        xmlwriter.RemoveEntry(section, movieFolder);
                    }

                    string shareNameData       = string.Empty;
                    string sharePathData       = string.Empty;
                    string sharePinData        = string.Empty;
                    bool   shareTypeData       = false;
                    string shareServerData     = string.Empty;
                    string shareLoginData      = string.Empty;
                    string sharePwdData        = string.Empty;
                    int    sharePortData       = 21;
                    string shareRemotePathData = string.Empty;
                    int    shareLayout         = (int)MediaPortal.GUI.Library.GUIFacadeControl.Layout.List;
                    bool   shareScanData       = false;
                    //ThumbsCreate (default true)
                    bool thumbsCreate  = true;
                    bool folderIsMovie = false;

                    if (_shareListControl != null && _shareListControl.Count > index)
                    {
                        ShareData shareData = _shareListControl[index].AlbumInfoTag as ShareData;

                        if (shareData != null && !String.IsNullOrEmpty(shareData.Name))
                        {
                            shareNameData       = shareData.Name;
                            sharePathData       = shareData.Folder;
                            sharePinData        = shareData.PinCode;
                            shareTypeData       = shareData.IsRemote;
                            shareServerData     = shareData.Server;
                            shareLoginData      = shareData.LoginName;
                            sharePwdData        = shareData.PassWord;
                            sharePortData       = shareData.Port;
                            shareRemotePathData = shareData.RemoteFolder;
                            shareLayout         = (int)shareData.DefaultLayout;
                            shareScanData       = shareData.ScanShare;
                            // ThumbsCreate
                            thumbsCreate  = shareData.CreateThumbs;
                            folderIsMovie = shareData.EachFolderIsMovie;

                            if (shareNameData == _defaultShare)
                            {
                                defaultShare = shareNameData;
                            }

                            xmlwriter.SetValue(section, shareName, shareNameData);
                            xmlwriter.SetValue(section, sharePath, sharePathData);
                            xmlwriter.SetValue(section, sharePin, Util.Utils.EncryptPin(sharePinData));
                            xmlwriter.SetValueAsBool(section, shareType, shareTypeData);
                            xmlwriter.SetValue(section, shareServer, shareServerData);
                            xmlwriter.SetValue(section, shareLogin, shareLoginData);
                            xmlwriter.SetValue(section, sharePwd, sharePwdData);
                            xmlwriter.SetValue(section, sharePort, sharePortData.ToString());
                            xmlwriter.SetValue(section, shareRemotePath, shareRemotePathData);
                            xmlwriter.SetValue(section, shareViewPath, shareLayout);

                            if (section == "music" || section == "movies")
                            {
                                string shareScan = String.Format("sharescan{0}", index);
                                xmlwriter.SetValueAsBool(section, shareScan, shareScanData);
                            }

                            if (section == "movies")
                            {
                                string thumbs = String.Format("videothumbscreate{0}", index);
                                xmlwriter.SetValueAsBool(section, thumbs, thumbsCreate);

                                string folderMovie = String.Format("eachfolderismovie{0}", index);
                                xmlwriter.SetValueAsBool(section, folderMovie, folderIsMovie);
                            }
                        }
                    }
                }
                xmlwriter.SetValue(section, "default", defaultShare);
                xmlwriter.SetValueAsBool(section, "rememberlastfolder", RememberLastFolder);
                xmlwriter.SetValueAsBool(section, "AddOpticalDiskDrives", AddOpticalDiskDrives);
                xmlwriter.SetValueAsBool(section, "SwitchRemovableDrives", SwitchRemovableDrives);
            }
            // Set new shares for internal plugins
            switch (section)
            {
            case "movies":
                GUIVideoFiles.ResetShares();
                break;

            case "music":
                GUIMusicFiles.ResetShares();
                break;

            case "pictures":
                GUIPictures.ResetShares();
                break;
            }
        }