Esempio n. 1
0
        public CString(string str, CEncoding env = CEncoding.Ascii)
        {
            Enc = env.ToEncoding();
            Str = str;

            var data = Enc.GetBytes(str + '\0');

            Size = data.Length;
            Alloc(Size);
            Marshal.Copy(data, 0, Ptr, Size);
        }
Esempio n. 2
0
 public static Encoding ToEncoding(this CEncoding self)
 {
     return(self switch
     {
         CEncoding.Ascii => Encoding.ASCII,
         CEncoding.Wide => Environment.OSVersion.Platform == PlatformID.Unix ||
         Environment.OSVersion.Platform == PlatformID.MacOSX
             ? System.Text.Encoding.UTF32
             : System.Text.Encoding.Unicode, // UTF-16
         CEncoding.UTF8 => Encoding.UTF8,
         CEncoding.UTF16 => Encoding.Unicode,
         CEncoding.UTF32 => Encoding.UTF32, // UTF-16
         _ => Encoding.ASCII
     });
Esempio n. 3
0
        //----------------------------------------------------------------------
        private void CFormOptionsCSV1_Load(object sender, System.EventArgs e)
        {
            if (m_parametre == null)
            {
                return;
            }

            // Lance la traduction du formulaire
            CWin32Traducteur.Translate(this);

            switch (m_parametre.Separateur)
            {
            case '\t':
                m_chkTabulation.Checked = true;
                break;

            case ',':
                m_chkVirgule.Checked = true;
                break;

            case ';':
                m_chkPointVirgule.Checked = true;
                break;

            case ' ':
                m_chkEspace.Checked = true;
                break;

            default:
                m_chkAutre.Checked = true;
                m_txtAutreSep.Text = m_parametre.Separateur + "";
                break;
            }

            m_cmbEncoding.DataSource    = CEncoding.GetValeursEnumPossibleInEnumALibelle(typeof(CEncoding));
            m_cmbEncoding.DisplayMember = "Libelle";
            m_cmbEncoding.ValueMember   = "Code";
            m_cmbEncoding.SelectedValue = m_parametre.Encodage;

            m_chkNomChampsSurPremiereLigne.Checked = m_parametre.NomChampsSurPremiereLigne;

            if (m_parametre.IndicateurTexte != "")
            {
                m_chkIndicateurTexte.Checked = true;
                m_cmbIndicateurTexte.Text    = m_parametre.IndicateurTexte;
            }

            UpdateTexteExemple();
        }
Esempio n. 4
0
        /// <summary>
        /// 字节流解码。
        /// </summary>
        public static string ToString(byte[] buffer, int startIndex, int length, CEncoding encoding)
        {
            switch (encoding)
            {
            case CEncoding.GBK:
                return(System.Text.UnicodeEncoding.GetEncoding("gb2312").GetString(buffer, startIndex, length));

            case CEncoding.ASCII:
                return(System.Text.Encoding.ASCII.GetString(buffer, startIndex, length));

            case CEncoding.UCS2:
                return(System.Text.Encoding.BigEndianUnicode.GetString(buffer, startIndex, length));

            default:
                return("");
            }
        }
Esempio n. 5
0
        public bool ReadTXTHeader(string FilePath)
        {
            if (!File.Exists(FilePath))
            {
                return(false);
            }

            this.Folder = Path.GetDirectoryName(FilePath);

            foreach (string folder in CConfig.SongFolder)
            {
                if (this.Folder.Contains(folder))
                {
                    if (this.Folder.Length == folder.Length)
                    {
                        this.FolderName = "Songs";
                    }
                    else
                    {
                        this.FolderName = this.Folder.Substring(folder.Length + 1, this.Folder.Length - folder.Length - 1);

                        string str = this.FolderName;
                        try
                        {
                            str = this.FolderName.Substring(0, this.FolderName.IndexOf("\\"));
                        }
                        catch (Exception)
                        {
                        }
                        this.FolderName = str;
                    }
                }
            }

            this.FileName = Path.GetFileName(FilePath);

            EHeaderFlags HeaderFlags = new EHeaderFlags();
            StreamReader sr;

            try
            {
                sr = new StreamReader(FilePath, Encoding.Default, true);

                string line = sr.ReadLine();
                if (line.Length == 0)
                {
                    return(false);
                }

                int    pos        = -1;
                string Identifier = String.Empty;
                string Value      = String.Empty;

                while ((line.Length == 0) || (line[0].ToString().Equals("#")))
                {
                    pos = line.IndexOf(":");

                    if (pos > 0)
                    {
                        Identifier = line.Substring(1, pos - 1).Trim().ToUpper();
                        Value      = line.Substring(pos + 1, line.Length - pos - 1).Trim();

                        if (Value.Length > 0)
                        {
                            switch (Identifier)
                            {
                            case "ENCODING":
                                this.Encoding = CEncoding.GetEncoding(Value);
                                sr            = new StreamReader(FilePath, this.Encoding);
                                Identifier    = String.Empty;
                                line          = sr.ReadLine();

                                while ((line.Length == 0) || (line[0].ToString().Equals("#")) && (Identifier != "ENCODING"))
                                {
                                    pos = line.IndexOf(":");

                                    if (pos > 0)
                                    {
                                        Identifier = line.Substring(1, pos - 1).Trim().ToUpper();
                                        Value      = line.Substring(pos + 1, line.Length - pos - 1).Trim();
                                    }

                                    if (!sr.EndOfStream)
                                    {
                                        if (Identifier == "ENCODING")
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            line = sr.ReadLine();
                                        }
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }
                                break;

                            case "TITLE":
                                if (Value != String.Empty)
                                {
                                    this.Title   = Value;
                                    HeaderFlags |= EHeaderFlags.Title;
                                }
                                break;

                            case "ARTIST":
                                if (Value != String.Empty)
                                {
                                    this.Artist  = Value;
                                    HeaderFlags |= EHeaderFlags.Artist;
                                }
                                break;

                            case "TITLE-ON-SORTING":
                                if (Value != String.Empty)
                                {
                                    this.TitleSorting = Value;
                                }
                                break;

                            case "ARTIST-ON-SORTING":
                                if (Value != String.Empty)
                                {
                                    this.ArtistSorting = Value;
                                }
                                break;

                            case "P1":
                                if (Value != String.Empty)
                                {
                                    this.DuetPart1 = Value;
                                }
                                break;

                            case "P2":
                                if (Value != String.Empty)
                                {
                                    this.DuetPart2 = Value;
                                }
                                break;

                            case "MP3":
                                if (File.Exists(Path.Combine(this.Folder, Value)))
                                {
                                    this.MP3FileName = Value;
                                    HeaderFlags     |= EHeaderFlags.MP3;
                                }
                                else
                                {
                                    CLog.LogError("Can't find audio file: " + Path.Combine(this.Folder, Value));
                                    return(false);
                                }
                                break;

                            case "BPM":
                                if (CHelper.TryParse(Value, out this.BPM))
                                {
                                    this.BPM    *= 4;
                                    HeaderFlags |= EHeaderFlags.BPM;
                                }
                                break;

                            case "EDITION":
                                if (Value.Length > 1)
                                {
                                    this.Edition.Add(Value);
                                }
                                break;

                            case "GENRE":
                                if (Value.Length > 1)
                                {
                                    this.Genre.Add(Value);
                                }
                                break;

                            case "YEAR":
                                int num = 0;
                                if (Value.Length == 4 && int.TryParse(Value, out num))
                                {
                                    this.Year = Value;
                                }
                                break;

                            case "LANGUAGE":
                                if (Value.Length > 1)
                                {
                                    this.Language.Add(Value);
                                }
                                break;

                            case "COMMENT":
                                if (Value.Length > 1)
                                {
                                    this.Comment.Add(Value);
                                }
                                break;

                            case "GAP":
                                if (CHelper.TryParse(Value, out this.Gap))
                                {
                                    this.Gap /= 1000f;
                                }
                                break;

                            case "COVER":
                                if (File.Exists(Path.Combine(this.Folder, Value)))
                                {
                                    this.CoverFileName = Value;
                                }
                                break;

                            case "BACKGROUND":
                                if (File.Exists(Path.Combine(this.Folder, Value)))
                                {
                                    this.BackgroundFileName = Value;
                                }
                                break;

                            case "VIDEO":
                                if (File.Exists(Path.Combine(this.Folder, Value)))
                                {
                                    this.VideoFileName = Value;
                                }
                                else
                                {
                                    CLog.LogError("Can't find video file: " + Path.Combine(this.Folder, Value));
                                }

                                break;

                            case "VIDEOGAP":
                                CHelper.TryParse(Value, out this.VideoGap);
                                break;

                            case "VIDEOASPECT":
                                CHelper.TryParse <EAspect>(Value, out this.VideoAspect, true);
                                break;

                            case "START":
                                CHelper.TryParse(Value, out this.Start);
                                break;

                            case "END":
                                if (CHelper.TryParse(Value, out this.Finish))
                                {
                                    this.Finish /= 1000f;
                                }
                                break;

                            case "PREVIEWSTART":
                                if (CHelper.TryParse(Value, out this.PreviewStart))
                                {
                                    if (this.PreviewStart < 0f)
                                    {
                                        this.PreviewStart = 0f;
                                    }
                                    else
                                    {
                                        HeaderFlags |= EHeaderFlags.PreviewStart;
                                    }
                                }
                                break;

                            case "MEDLEYSTARTBEAT":
                                if (int.TryParse(Value, out this.Medley.StartBeat))
                                {
                                    HeaderFlags |= EHeaderFlags.MedleyStartBeat;
                                }
                                break;

                            case "MEDLEYENDBEAT":
                                if (int.TryParse(Value, out this.Medley.EndBeat))
                                {
                                    HeaderFlags |= EHeaderFlags.MedleyEndBeat;
                                }
                                break;

                            case "CALCMEDLEY":
                                if (Value.ToUpper() == "OFF")
                                {
                                    this.CalculateMedley = false;
                                }
                                break;

                            case "RELATIVE":
                                if (Value.ToUpper() == "YES" && Value.ToUpper() != "NO")
                                {
                                    this.Relative = EOffOn.TR_CONFIG_ON;
                                }
                                break;

                            default:
                                ;
                                break;
                            }
                        }
                    }

                    if (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                    }
                    else
                    {
                        return(false);
                    }
                } //end of while

                if ((HeaderFlags & EHeaderFlags.Title) == 0)
                {
                    CLog.LogError("Title tag missing: " + FilePath);
                    return(false);
                }

                if ((HeaderFlags & EHeaderFlags.Artist) == 0)
                {
                    CLog.LogError("Artist tag missing: " + FilePath);
                    return(false);
                }

                if ((HeaderFlags & EHeaderFlags.MP3) == 0)
                {
                    CLog.LogError("MP3 tag missing: " + FilePath);
                    return(false);
                }

                if ((HeaderFlags & EHeaderFlags.BPM) == 0)
                {
                    CLog.LogError("BPM tag missing: " + FilePath);
                    return(false);
                }

                if (this.Relative == EOffOn.TR_CONFIG_ON)
                {
                    CLog.LogError("Relative songs are not supported by Vocaluxe (perhaps later)! (" + FilePath + ")");
                    return(false);
                }

                #region check medley tags
                if ((HeaderFlags & EHeaderFlags.MedleyStartBeat) != 0 && (HeaderFlags & EHeaderFlags.MedleyEndBeat) != 0)
                {
                    if (this.Medley.StartBeat > this.Medley.EndBeat)
                    {
                        CLog.LogError("MedleyStartBeat is bigger than MedleyEndBeat in file: " + FilePath);
                        HeaderFlags = HeaderFlags - EHeaderFlags.MedleyStartBeat - EHeaderFlags.MedleyEndBeat;
                    }
                }

                if ((HeaderFlags & EHeaderFlags.PreviewStart) == 0 || this.PreviewStart == 0f)
                {
                    //PreviewStart is not set or <=0
                    if ((HeaderFlags & EHeaderFlags.MedleyStartBeat) != 0)
                    {
                        //fallback to MedleyStart
                        this.PreviewStart = CGame.GetTimeFromBeats(this.Medley.StartBeat, this.BPM);
                    }
                    else
                    {
                        //else set to 0, it will be set in FindRefrainStart
                        this.PreviewStart = 0f;
                    }
                }

                if ((HeaderFlags & EHeaderFlags.MedleyStartBeat) != 0 && (HeaderFlags & EHeaderFlags.MedleyEndBeat) != 0)
                {
                    this.Medley.Source      = EMedleySource.Tag;
                    this.Medley.FadeInTime  = CSettings.DefaultMedleyFadeInTime;
                    this.Medley.FadeOutTime = CSettings.DefaultMedleyFadeOutTime;
                }
                #endregion check medley tags

                this.Encoding = sr.CurrentEncoding;
            }
            catch (Exception e)
            {
                CLog.LogError("Error reading txt header in file \"" + FilePath + "\": " + e.Message);
                return(false);
            }

            CheckFiles();

            //Before saving this tags to .txt: Check, if ArtistSorting and Artist are equal, then don't save this tag.
            if (this.ArtistSorting == String.Empty)
            {
                this.ArtistSorting = this.Artist;
            }

            if (this.TitleSorting == String.Empty)
            {
                this.TitleSorting = this.Title;
            }

            return(true);
        }
Esempio n. 6
0
 public static int GetStride(this CEncoding self) => self.ToEncoding().GetStride();
Esempio n. 7
0
        public bool ReadTXTHeader(string FilePath)
        {
            if (!File.Exists(FilePath))
            {
                return(false);
            }

            this.Folder = Path.GetDirectoryName(FilePath);

            foreach (string folder in CConfig.SongFolder)
            {
                if (this.Folder.Contains(folder))
                {
                    if (this.Folder.Length == folder.Length)
                    {
                        this.FolderName = "Songs";
                    }
                    else
                    {
                        this.FolderName = this.Folder.Substring(folder.Length + 1, this.Folder.Length - folder.Length - 1);

                        string str = this.FolderName;
                        try
                        {
                            str = this.FolderName.Substring(0, this.FolderName.IndexOf("\\"));
                        }
                        catch (Exception)
                        {
                        }
                        this.FolderName = str;
                    }
                }
            }

            this.FileName = Path.GetFileName(FilePath);

            EHeaderFlags HeaderFlags = new EHeaderFlags();
            StreamReader sr;

            try
            {
                sr = new StreamReader(FilePath, Encoding.Default, true);

                string line = sr.ReadLine();
                if (line.Length == 0)
                {
                    return(false);
                }

                int    pos        = -1;
                string Identifier = String.Empty;
                string Value      = String.Empty;

                while ((line.Length == 0) || (line[0].ToString().Equals("#")))
                {
                    pos = line.IndexOf(":");

                    if (pos > 0)
                    {
                        Identifier = line.Substring(1, pos - 1).Trim().ToUpper();
                        Value      = line.Substring(pos + 1, line.Length - pos - 1).Trim();

                        if (Value.Length > 0)
                        {
                            switch (Identifier)
                            {
                            case "ENCODING":
                                this.Encoding = CEncoding.GetEncoding(Value);
                                sr            = new StreamReader(FilePath, this.Encoding);
                                Identifier    = String.Empty;
                                line          = sr.ReadLine();

                                while ((line.Length == 0) || (line[0].ToString().Equals("#")) && (Identifier != "ENCODING"))
                                {
                                    pos = line.IndexOf(":");

                                    if (pos > 0)
                                    {
                                        Identifier = line.Substring(1, pos - 1).Trim().ToUpper();
                                        Value      = line.Substring(pos + 1, line.Length - pos - 1).Trim();
                                    }

                                    if (!sr.EndOfStream)
                                    {
                                        if (Identifier == "ENCODING")
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            line = sr.ReadLine();
                                        }
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }
                                break;

                            case "TITLE":
                                if (Value != String.Empty)
                                {
                                    this.Title   = Value;
                                    HeaderFlags |= EHeaderFlags.Title;
                                }
                                break;

                            case "ARTIST":
                                if (Value != String.Empty)
                                {
                                    this.Artist  = Value;
                                    HeaderFlags |= EHeaderFlags.Artist;
                                }
                                break;

                            case "MP3":
                                if (File.Exists(Path.Combine(this.Folder, Value)))
                                {
                                    this.MP3FileName = Value;
                                    HeaderFlags     |= EHeaderFlags.MP3;
                                }
                                else
                                {
                                    CLog.LogError("Can't find audio file: " + Path.Combine(this.Folder, Value));
                                    return(false);
                                }
                                break;

                            case "BPM":
                                if (CHelper.TryParse(Value, out this.BPM))
                                {
                                    this.BPM    *= 4;
                                    HeaderFlags |= EHeaderFlags.BPM;
                                }
                                break;

                            case "EDITION":
                                if (Value.Length > 1)
                                {
                                    this.Edition.Add(Value);
                                }
                                break;

                            case "GENRE":
                                if (Value.Length > 1)
                                {
                                    this.Genre.Add(Value);
                                }
                                break;

                            case "YEAR":
                                int num = 0;
                                if (Value.Length == 4 && int.TryParse(Value, out num))
                                {
                                    this.Year = Value;
                                }
                                break;

                            case "LANGUAGE":
                                if (Value.Length > 1)
                                {
                                    this.Language.Add(Value);
                                }
                                break;

                            case "COMMENT":
                                if (Value.Length > 1)
                                {
                                    this.Comment.Add(Value);
                                }
                                break;

                            case "GAP":
                                if (CHelper.TryParse(Value, out this.Gap))
                                {
                                    this.Gap /= 1000f;
                                }
                                break;

                            case "COVER":
                                if (File.Exists(Path.Combine(this.Folder, Value)))
                                {
                                    this.CoverFileName = Value;
                                }
                                break;

                            case "BACKGROUND":
                                if (File.Exists(Path.Combine(this.Folder, Value)))
                                {
                                    this.BackgroundFileName = Value;
                                }
                                break;

                            case "VIDEO":
                                if (File.Exists(Path.Combine(this.Folder, Value)))
                                {
                                    this.VideoFileName = Value;
                                }
                                else
                                {
                                    CLog.LogError("Can't find video file: " + Path.Combine(this.Folder, Value));
                                }

                                break;

                            case "VIDEOGAP":
                                CHelper.TryParse(Value, out this.VideoGap);
                                break;

                            case "VIDEOASPECT":
                                CHelper.TryParse <EAspect>(Value, out this.VideoAspect, true);
                                break;

                            case "START":
                                CHelper.TryParse(Value, out this.Start);
                                break;

                            case "END":
                                if (CHelper.TryParse(Value, out this.Finish))
                                {
                                    this.Finish /= 1000f;
                                }
                                break;

                            default:
                                ;
                                break;
                            }
                        }
                    }

                    if (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                    }
                    else
                    {
                        return(false);
                    }
                } //end of while

                if (HeaderFlags != (EHeaderFlags.Title | EHeaderFlags.Artist | EHeaderFlags.MP3 | EHeaderFlags.BPM))
                {
                    return(false);
                }

                this.Encoding = sr.CurrentEncoding;
            }
            catch (Exception)
            {
                return(false);
            }

            CheckFiles();

            return(true);
        }