Skip to content

Commit

Permalink
BuildID只影响类型,表内容可以修改
Browse files Browse the repository at this point in the history
  • Loading branch information
davyxu committed Nov 7, 2018
1 parent 46e25fc commit 860aa29
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion v2/printer/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (self *binaryPrinter) Run(g *Globals) *Stream {
fileStresam := NewStream()
fileStresam.WriteString("TABTOY")
fileStresam.WriteInt32(combineFileVersion)
fileStresam.WriteString(BinaryBuildID())
fileStresam.WriteString(g.BuildID)

for index, tab := range g.Tables {

Expand Down
21 changes: 13 additions & 8 deletions v2/printer/csharp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"fmt"
"text/template"

"bytes"
"crypto/md5"
"github.com/davyxu/tabtoy/v2/i18n"
"github.com/davyxu/tabtoy/v2/model"
"strings"
"time"
)

const csharpTemplate = `// Generated by github.com/davyxu/tabtoy
Expand Down Expand Up @@ -364,14 +365,8 @@ type csharpFileModel struct {
VerticalFields []csharpField

GenSerializeCode bool
}

func (self *csharpFileModel) BuildID() string {
return BinaryBuildID()
}

func BinaryBuildID() string {
return time.Now().Format("2006-01-02 15:04:05")
BuildID string
}

type csharpPrinter struct {
Expand Down Expand Up @@ -467,6 +462,16 @@ func (self *csharpPrinter) Run(g *Globals) *Stream {

bf := NewStream()

var md5Buffer bytes.Buffer
err = tpl.Execute(&md5Buffer, &m)
if err != nil {
log.Errorln(err)
return nil
}

m.BuildID = fmt.Sprintf("%x", md5.Sum(bf.Buffer().Bytes()))
g.BuildID = m.BuildID

err = tpl.Execute(bf.Buffer(), &m)
if err != nil {
log.Errorln(err)
Expand Down
1 change: 1 addition & 0 deletions v2/printer/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Globals struct {
GlobalIndexes []TableIndex // 类型信息.全局索引
CombineStruct *model.Descriptor // 类型信息.Combine结构体

BuildID string
}

func (self *Globals) PreExport() bool {
Expand Down

0 comments on commit 860aa29

Please sign in to comment.