AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Codeschnipsel von GO zu Delphi übersetzen.
Thema durchsuchen
Ansicht
Themen-Optionen

Codeschnipsel von GO zu Delphi übersetzen.

Ein Thema von Newa · begonnen am 20. Okt 2015 · letzter Beitrag vom 21. Okt 2015
 
Newa

Registriert seit: 10. Dez 2011
5 Beiträge
 
#1

Codeschnipsel von GO zu Delphi übersetzen.

  Alt 20. Okt 2015, 05:53
Hallo Werte Delphianer,
ich hab hier ein paar Zeilen Code die in GO geschrieben sind. Ich möchte dies in meinem Delphi XE3 nachbilden.
Mir fehlt das Verständnis für GO deswegen würde ich mich über Hilfe sehr freuen.

GO Code:
Adds non-Steam games that have been registered locally.
Code:
// This information is in the file config/shortcuts.vdf, in binary format.
// It contains the non-Steam games with names, target (exe location) and
// tags/categories. To create a grid image we must compute the Steam ID, which
// is just crc32(target + label) + "02000000", using IEEE standard polynomials.
func addNonSteamGames(user User, games map[string]*Game) {
   shortcutsVdf := filepath.Join(user.Dir, "config", "shortcuts.vdf")
   if _, err := os.Stat(shortcutsVdf); err != nil {
      return
   }
   shortcutBytes, err := ioutil.ReadFile(shortcutsVdf)
   if err != nil {
      return
   }

   // The actual binary format is known, but using regexes is way easier than
   // parsing the entire file. If I run into any problems I'll replace this.
   gamePattern := regexp.MustCompile("(?i)appname\x00(.+?)\x00\x01exe\x00(.+?)\x00\x01.+?\x00tags\x00(.*?)\x08\x08")
   tagsPattern := regexp.MustCompile("\\d\x00(.+?)\x00")
   for _, gameGroups := range gamePattern.FindAllSubmatch(shortcutBytes, -1) {
      gameName := gameGroups[1]
      target := gameGroups[2]
      uniqueName := bytes.Join([][]byte{target, gameName}, []byte(""))
      // Does IEEE CRC32 of target concatenated with gameName, then convert
      // to 64bit Steam ID. No idea why Steam chose this operation.
      top := uint64(crc32.ChecksumIEEE(uniqueName)) | 0x80000000
      gameId := strconv.FormatUint(top<<32|0x02000000, 10)
      game := Game{gameId, string(gameName), []string{}, "", nil}
      games[gameId] = &game

      tagsText := gameGroups[3]
      for _, tagGroups := range tagsPattern.FindAllSubmatch(tagsText, -1) {
         tag := tagGroups[1]
         game.Tags = append(game.Tags, string(tag))
      }
   }
}
Der Code ist Opensource und hat zum Ziel für die Plattform Steam einen Unique Hash aus Dateipfad und Name zu berechnen.

Ich bin die Sache so angegangen das ich einen string mit crc32 gehashed habe. Das Ergebnis ist ein DWord mit 10 stellen. Im oberen Code wird daraus ein 64 bit Unisgned Integer gemacht. Hier fehlen mir die Kenntnisse. Wie bilde ich das in Delphi ab? Im Grunde möchte ich also die gameid ermitteln.
Gruß

Geändert von TBx (20. Okt 2015 um 06:16 Uhr) Grund: Code-Tags eingefügt, bitte zukünftig selber machen. Danke! MfG TBx
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:29 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz