GetMd5() public static method

public static GetMd5 ( String path ) : string
path String
return string
        public string GetPackageMd5(string Package)
        {
            string file = s3getToTemp("osz2/" + Package);
            string md5  = CryptoHelper.GetMd5(file);

            return(md5);
        }
        private static void initializePrivate()
        {
            string adapters = string.Empty;

            try
            {
                if (OsuMain.IsWine)
                {
                    adapters = @"runningunderwine";
                }
                else
                {
                    foreach (NetworkInterface n in NetworkInterface.GetAllNetworkInterfaces())
                    {
                        adapters += n.GetPhysicalAddress() + @".";
                    }
                }
            }
            catch
            {
                adapters = string.Empty;
            }

            GameBase.CreateUniqueId();
            GameBase.ClientHash = CryptoHelper.GetMd5(OsuMain.FullPath) + @":" + adapters + @":" + CryptoHelper.GetMd5String(adapters) + @":" + CryptoHelper.GetMd5String(GameBase.UniqueId) + @":" + CryptoHelper.GetMd5String(GameBase.UniqueId2) + @":";
        }
Ejemplo n.º 3
0
 internal static string ExeHash(string filename, bool useCache = true)
 {
     if (useCache && ConfigManager.Configuration.ContainsKey(@"h_" + filename))
     {
         return(ConfigManager.Configuration[@"h_" + filename].ToString());
     }
     return((ConfigManager.Configuration[@"h_" + filename] = CryptoHelper.GetMd5(filename)).ToString());
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 密码加密
        /// </summary>
        private static string GetEncryptedPassword(string unencryptedPassword)
        {
            if (string.IsNullOrWhiteSpace(unencryptedPassword))
            {
                throw new HangerdException("密码不可为空");
            }

            return(CryptoHelper.GetMd5(unencryptedPassword));
        }
Ejemplo n.º 5
0
        public static string Create <TEntity>(string subject)
            where TEntity : EntityBase
        {
            if (string.IsNullOrWhiteSpace(subject))
            {
                throw new HangerdException("ID生成所依赖主体不可为空");
            }

            return(CryptoHelper.GetMd5(string.Format("{0}_{1}", typeof(TEntity).FullName, subject.ToLower())));
        }
Ejemplo n.º 6
0
        internal static string GetMd5(string filename)
        {
            string md5;

            if (Md5Dictionary.TryGetValue(filename, out md5))
            {
                return(md5);
            }

            md5 = CryptoHelper.GetMd5(filename);
            Md5Dictionary[filename] = md5;
            return(md5);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called when dialog window opens. Does preliminary checks in background.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void submission_InitialRequest(object sender, DoWorkEventArgs e)
        {
            string osz2Hash     = string.Empty;
            string osz2FileHash = string.Empty;

            if (BeatmapManager.Current.Creator != GameBase.User.Name && (GameBase.User.Permission & Permissions.BAT) == 0)
            {
                error = LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_OwnershipError);
                return;
            }

            string lastUpload = lastUploadFilename;

            if (lastUpload != null && File.Exists(lastUpload))
            {
                try
                {
                    packagePreviousUpload = new MapPackage(lastUpload);
                    osz2Hash = (BitConverter.ToString(packagePreviousUpload.hash_body) +
                                BitConverter.ToString(packagePreviousUpload.hash_meta)).Replace("-", "");
                }
                catch
                {
                }

                osz2FileHash = CryptoHelper.GetMd5(lastUpload);
            }

            int    beatmapSetID = getBeatmapSetID();
            string beatmapIDs   = getBeatmapIdList();

            string url =
                string.Format(Urls.OSZ2_SUBMIT_GET_ID,
                              ConfigManager.sUsername, ConfigManager.sPassword, beatmapSetID, beatmapIDs, osz2FileHash);

            string result = String.Empty;

            try
            {
                activeWebRequest = new pWebRequest(url);
                activeWebRequest.BlockingPerform();
                result = activeWebRequest.ResponseString;
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
                //something has gone wrong, but we handle this in the next few lines.
            }

            if (checkCancel(e))
            {
                return;
            }

            if (string.IsNullOrEmpty(result))
            {
                error = LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_BSSConnectFailed) +
                        LocalisationManager.GetString(OsuString.BeatmapSubmissionSystem_CheckConnection);
                return;
            }

            string[] resultSplit = result.Split('\n');

            if (handleErrorCode(resultSplit, 6))
            {
                return;
            }

            newBeatmapSetID = System.Convert.ToInt32(resultSplit[1]);
            newBeatmapIDs   = Array.ConvertAll <string, int>(resultSplit[2].Split(','), (s) => System.Convert.ToInt32(s));
            fullSubmit      = resultSplit[3] == "1" || packagePreviousUpload == null;
            Int32.TryParse(resultSplit[4], out submissionQuotaRemaining);
            bubblePop = resultSplit.Length > 5 && resultSplit[5] == "1";
            approved  = resultSplit.Length > 6 ? Int32.Parse(resultSplit[6]) : -1;
        }
Ejemplo n.º 8
0
        internal static void ProcessHeaders(Beatmap b)
        {
            b.TimingPoints.Clear();
            b.PreviewTime = -1;
            b.AudioLeadIn = 0;

            b.ObjectCount = 0;
            b.DrainLength = 0;

            b.countSlider    = 0;
            b.countNormal    = 0;
            b.countSpinner   = 0;
            b.BeatmapVersion = 4;

            b.VersionOffset = 0;

            b.StackLeniency = 0.7f;

            b.Countdown = Countdown.Normal;

            b.CustomColours = false;

            b.Mode = 0;

            b.DefaultSampleSet        = SampleSet.Normal;
            AudioEngine.CustomSamples = false;

            b.IncorrectChecksum = false;

            b.BeatmapPresent = File.Exists(b.Filename);
            if (!b.BeatmapPresent)
            {
                return;
            }

            b.BeatmapChecksum = CryptoHelper.GetMd5(b.Filename);

            StreamReader r = File.OpenText(b.Filename);

            b.DateModified = File.GetLastWriteTimeUtc(b.Filename);

            FileSection currentSection = FileSection.Unknown;

            int    firstTime   = -1;
            int    lastTime    = -1;
            string lastTimeStr = "";
            int    breakTime   = 0;

            string[] split;

            char[] sep = new[] { ',' };

            try
            {
                if (!r.EndOfStream)
                {
                    string headerInfo = r.ReadLine();
                    if (headerInfo.Contains("osu file format"))
                    {
                        b.BeatmapVersion          = Int32.Parse(headerInfo.Remove(0, headerInfo.LastIndexOf('v') + 1));
                        AudioEngine.CustomSamples = b.BeatmapVersion < 4;
                        b.VersionOffset           = b.BeatmapVersion < 5 && GameBase.Mode == Modes.Edit ? 24 : 0;
                    }
                }

                while (!r.EndOfStream)
                {
                    string line = r.ReadLine().Trim();

                    if (line.Length == 0)
                    {
                        continue;
                    }

                    string left  = "";
                    string right = "";

                    if (currentSection != FileSection.HitObjects)
                    {
                        int index = line.IndexOf(':');

                        if (index >= 0)
                        {
                            left  = line.Remove(index).Trim();
                            right = line.Remove(0, index + 1).Trim();
                        }
                        else if (line[0] == '[')
                        {
                            try
                            {
                                currentSection =
                                    (FileSection)Enum.Parse(typeof(FileSection), line.Trim(new[] { '[', ']' }));
                            }
                            catch
                            {
                            }
                            continue;
                        }
                    }

                    switch (currentSection)
                    {
                    case FileSection.TimingPoints:
                        split = line.Split(sep);
                        if (split.Length > 2)
                        {
                            b.TimingPoints.Add(
                                new TimingPoint(Double.Parse(split[0].Trim(), GameBase.nfi) + b.VersionOffset,
                                                Double.Parse(split[1].Trim(), GameBase.nfi),
                                                (TimeSignatures)Int32.Parse(split[2]),
                                                (SampleSet)Int32.Parse(split[3]),
                                                split.Length > 4 && split[4][0] == '1',
                                                split.Length > 5 ? Int32.Parse(split[5]) : b.SampleVolume));
                        }
                        else if (split.Length == 2)
                        {
                            b.TimingPoints.Add(
                                new TimingPoint(Double.Parse(split[0].Trim(), GameBase.nfi) + b.VersionOffset,
                                                Double.Parse(split[1].Trim(), GameBase.nfi),
                                                TimeSignatures.SimpleQuadruple,
                                                b.DefaultSampleSet,
                                                AudioEngine.CustomSamples,
                                                100));
                        }
                        break;

                    case FileSection.General:
                        switch (left)
                        {
                        case "SampleSet":
                            b.DefaultSampleSet           = (SampleSet)Enum.Parse(typeof(SampleSet), right);
                            AudioEngine.CurrentSampleSet = b.DefaultSampleSet;
                            break;

                        case "CustomSamples":
                            AudioEngine.CustomSamples = right[0] == '1';
                            break;

                        case "Countdown":
                            b.Countdown = (Countdown)Int32.Parse(right);
                            break;

                        case "AudioFilename":
                            if (right.Length > 0)
                            {
                                b.AudioFilename = string.Format("{0}\\{1}", b.ContainingFolder, right);
                            }
                            break;

                        case "AudioHash":
                            b.AudioExpectedMd5 = right;
                            break;

                        case "AudioLeadIn":
                            b.AudioLeadIn = Int32.Parse(right);
                            break;

                        case "PreviewTime":
                            b.PreviewTime = Int32.Parse(right);
                            break;

                        case "SampleVolume":
                            b.SampleVolume = Int32.Parse(right);
                            break;

                        case "StackLeniency":
                            b.StackLeniency = Math.Max(0, Math.Min(1, float.Parse(right, GameBase.nfi)));
                            break;

                        case "Mode":
                            b.Mode = Int32.Parse(right);
                            break;
                        }
                        break;

                    case FileSection.Metadata:
                        switch (left)
                        {
                        case "Artist":
                            b.Artist = right;
                            break;

                        case "Title":
                            b.Title = right;
                            break;

                        case "Creator":
                            b.Creator = right;
                            break;

                        case "Version":
                            b.Version = right;
                            break;
                        }
                        break;

                    case FileSection.Difficulty:
                        switch (left)
                        {
                        case "HPDrainRate":
                            b.DifficultyHpDrainRate = byte.Parse(right);
                            break;

                        case "CircleSize":
                            b.DifficultyCircleSize = byte.Parse(right);
                            break;

                        case "OverallDifficulty":
                            b.DifficultyOverall = byte.Parse(right);
                            break;

                        case "SliderMultiplier":
                            b.DifficultySliderMultiplier =
                                Math.Max(0.4, Math.Min(2.6, Double.Parse(right, GameBase.nfi)));
                            break;

                        case "SliderTickRate":
                            b.DifficultySliderTickRate =
                                Math.Max(0.5, Math.Min(8, Double.Parse(right, GameBase.nfi)));
                            break;
                        }
                        break;

                    case FileSection.Events:
                        if (line[0] == '2')
                        {
                            int rs;
                            split = line.Split(',');
                            if (Int32.TryParse(split[0], out rs) && rs == (int)EventTypes.Break)
                            {
                                breakTime += (Int32.Parse(split[2]) - Int32.Parse(split[1]));
                            }
                        }
                        break;

                    case FileSection.HitObjects:
                        split = line.Split(sep, 5);

                        if (firstTime == -1)
                        {
                            firstTime = Int32.Parse(split[2]);
                        }

                        /*
                         *     internal enum HitObjectType
                         *      {
                         *          Normal = 1,
                         *          Slider = 2,
                         *          NewCombo = 4,
                         *          NormalNewCombo = 5,
                         *          SliderNewCombo = 6,
                         *          Spinner = 8
                         *      } ;
                         *
                         * */

                        if (split[3][0] == '8' || split[3].Length > 1)
                        {
                            b.countSpinner++;
                        }
                        else if (split[3][0] == '1' || split[3][0] == '5')
                        {
                            b.countNormal++;
                        }
                        else if (split[3][0] == '2' || split[3][0] == '6')
                        {
                            b.countSlider++;
                        }

                        lastTimeStr = split[2];
                        b.ObjectCount++;
                        break;

                    case FileSection.Colours:
                        b.CustomColours = true;
                        break;
                    }
                }
                r.Close();
            }
            catch (Exception)
            {
                if (DialogResult.Yes ==
                    MessageBox.Show(
                        "Error loading beatmap file " + Path.GetFileName(b.Filename) + "\nDelete this file?", "error'd",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1))
                {
                    r.Close();
                    File.Delete(b.Filename);
                }
            }

            b.PopulateTitleStatics();

            if (lastTimeStr.Length > 0)
            {
                lastTime = Int32.Parse(lastTimeStr);
            }

            b.DrainLength = (lastTime - firstTime - breakTime) / 1000;
            b.TotalLength = lastTime;
        }