-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogparse.py
2951 lines (2685 loc) · 135 KB
/
logparse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# encoding: utf-8
# -*- coding: utf-8 -*-
'''
Copyright (C) 2010-2011 FFXIVBattle.com
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Log Parser"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
1. Redistributions of source code must retain the above copyright notice, this list of conditions,
and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution,
and in the same place and form as other copyright, license and disclaimer information.
3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment:
"This product includes software developed by FFXIVBattle.com (http://www.ffxivbattle.com/) and its contributors",
in the same place and form as other third-party acknowledgments. Alternately, this acknowledgment may appear in
the software itself, in the same form and location as other such third-party acknowledgments.
4. Except as contained in this notice, the name of FFXIVBattle.com shall not be used in advertising or otherwise
to promote the sale, use or other dealings in this Software without prior written authorization from FFXIVBattle.com.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL FFXIVBATTLE.COM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
import traceback
import hashlib
import ConfigParser
import wx
import wx.richtext
from threading import Thread
import pickle
import datetime
import gzip
import sys
import os
import glob
import copy
import time
import json
import urllib
import urllib2
import uuid
import shutil
import array
import struct
from subprocess import Popen
import wx.lib.agw.hyperlink as hl
# for installations that already have a config move the file to the config directory
try:
if os.path.exists('logparser.cfg'):
if os.path.exists('config/'):
shutil.move('logparser.cfg', 'config/logparser.cfg')
except:
pass
# check to see if the config subdir exists and if the root logparser.cfg does
# not exist. This is so when there is a problem moving the existing config it
# won't skip it.
if os.path.exists('config/') and not os.path.exists('logparser.cfg'):
configfile = 'config/logparser.cfg'
else:
configfile = 'logparser.cfg'
version = 4.8
charactername = ""
doloop = 0
app = None
autotranslatearray = None
currentlanguage = 'en'
# Store the last log parsed
lastlogparsed = 0
guithread = None
def nullstrip(s):
# Return a string truncated at the first null character.
try:
s = s[:s.index('\x00')]
except ValueError: # No nulls were found, which is okay.
pass
return s
class PasswordDialog(wx.Dialog):
def __init__(self, parent, id, title, defaultPassword, language):
wx.Dialog.__init__(self, parent, id, title, size=(285, 160))
if language == 'en':
wx.StaticText(self, -1, 'Enter Character Password (NOT your ffxiv password)\r\n* This is so only you can submit records for your character. If you don\'t have a password type in a new one to set it.', (5,3), (280, 60))
self.password = wx.TextCtrl(self, -1, defaultPassword, (5,65), (260, 22), style=wx.TE_PASSWORD)
self.checkbox = wx.CheckBox(self, -1, "Save Password", (5,95), (110, 22))
wx.Button(self, wx.ID_OK, 'Ok', (115, 95), (70, 30))
wx.Button(self, wx.ID_CANCEL, 'Cancel', (195, 95), (70, 30))
else:
wx.StaticText(self, -1, u'文字パスワード(はなく、あなたのFF14パスワード)を入力してください\r\n* このためだけでなく、あなたの文字の記録を提出することができますです。あなたはそれを設定するための新しいいずれかのパスワードタイプを持っていない場合。', (5,3), (280, 60))
self.password = wx.TextCtrl(self, -1, defaultPassword, (5,65), (260, 22), style=wx.TE_PASSWORD)
self.checkbox = wx.CheckBox(self, -1, u"パスワードを保存", (5,95), (110, 22))
wx.Button(self, wx.ID_OK, u'はい', (115, 95), (70, 30))
wx.Button(self, wx.ID_CANCEL, u'キャンセル', (195, 95), (70, 30))
def SetChecked(self, value):
self.checkbox.SetValue(value)
def SetValue(self, value):
self.password.SetValue(value)
def GetChecked(self):
return self.checkbox.GetValue()
def GetValue(self):
return self.password.GetValue()
class ChangeCharacterNameDialog(wx.Dialog):
def __init__(self, parent, id, title, language):
wx.Dialog.__init__(self, parent, id, title, size=(320, 200))
if language == 'en':
wx.StaticText(self, -1, 'Enter new character name:', (5,3), (305, 15))
else:
wx.StaticText(self, -1, u'新キャラクターの名前を入力してください:', (5,3), (305, 15))
self.newcharactername = wx.TextCtrl(self, -1, "", (5,20), (300, 22))
if language == 'en':
wx.StaticText(self, -1, 'Enter current password:', (5,47), (300, 15))
else:
wx.StaticText(self, -1, u'現在のパスワードを入力してください:', (5,47), (300, 15))
self.password = wx.TextCtrl(self, -1, "", (5,65), (300, 22), style=wx.TE_PASSWORD)
if language == 'en':
wx.StaticText(self, -1, 'This may take up to 1 hour to appear on the website.\nChanging your character name can only be performed once an hour so choose wisely.', (5,90), (305, 40))
else:
wx.StaticText(self, -1, u'これは、ウェブサイト上で表示されるように1時間かかることがあります。\n時間はとても賢明な選択一度文字の名前を変更するだけで行うことができます。', (5,90), (305, 40))
if language == 'en':
wx.Button(self, wx.ID_OK, 'Ok', (158, 135), (70, 30))
wx.Button(self, wx.ID_CANCEL, 'Cancel', (235, 135), (70, 30))
else:
wx.Button(self, wx.ID_OK, u'はい', (158, 135), (70, 30))
wx.Button(self, wx.ID_CANCEL, u'キャンセル', (235, 135), (70, 30))
def GetNewCharacterName(self):
return self.newcharactername.GetValue()
def GetPassword(self):
return self.password.GetValue()
class ReverseIterator:
def __init__(self, sequence):
self.sequence = sequence
def __iter__(self):
length = len(self.sequence)
i = length
while i > 0:
i = i - 1
yield self.sequence[i]
class LogWindowContext(wx.Menu):
def __init__(self, chatviewer, language):
wx.Menu.__init__(self)
self.chatviewer = chatviewer
if language == 'en':
copy = self.Append(wx.ID_COPY, 'Copy' )
else:
copy = self.Append(wx.ID_COPY, u'コピー' )
self.AppendSeparator()
if language == 'en':
selectall = self.Append(wx.ID_SELECTALL, 'Select All' )
else:
selectall = self.Append(wx.ID_SELECTALL, u'すべて選択' )
copy.Enable(True)
selectall.Enable(True)
self.Bind(wx.EVT_MENU, self.ExecEvent)
def ExecEvent(self, event):
if event.GetId() == wx.ID_COPY:
clipdata = wx.TextDataObject()
clipdata.SetText(self.chatviewer.logWindow.GetStringSelection())
wx.TheClipboard.Open()
wx.TheClipboard.SetData(clipdata)
wx.TheClipboard.Close()
elif event.GetId() == wx.ID_SELECTALL:
self.chatviewer.logWindow.SelectAll()
class ChatViewer(wx.Frame):
def __init__(self, language):
if language == 'en':
wx.Frame.__init__(self, wx.GetApp().TopWindow, title='Chat Viewer', size=(500,400))
else:
wx.Frame.__init__(self, wx.GetApp().TopWindow, title=u'チャットビューア', size=(500,400))
self.language = language
# this is cleanup from an earlier version. It will be removed after a few versions go by.
if os.path.exists(os.path.join('chatlogs', '--Everything--.chat')):
os.remove(os.path.join('chatlogs', '--Everything--.chat'))
self.currdates = []
self.chat_types = {
'01': self.WriteSay, # say
'02': self.WriteShout, # shout
'03': self.WriteTell, # sending tell
'04': self.WriteParty, # party
'05': self.WriteLinkshell, # linkshell
'06': self.WriteLinkshell, # linkshell
'07': self.WriteLinkshell, # linkshell
'08': self.WriteLinkshell, # linkshell
'09': self.WriteLinkshell, # linkshell
'0A': self.WriteLinkshell, # linkshell
'0B': self.WriteLinkshell, # linkshell
'0C': self.WriteLinkshell, # linkshell
'0D': self.WriteTell, # get tell
'0F': self.WriteLinkshell, # linkshell
'0E': self.WriteLinkshell, # linkshell
'0F': self.WriteLinkshell, # linkshell
'10': self.WriteLinkshell, # linkshell
'11': self.WriteLinkshell, # linkshell
'12': self.WriteLinkshell, # linkshell
'13': self.WriteLinkshell, # linkshell
'14': self.WriteLinkshell, # linkshell
'15': self.WriteLinkshell, # linkshell
'19': self.WriteEmote, # other emote
'1B': self.WriteEmote # emote
}
self.SetBackgroundColour((240,240,240))
try:
self.SetIcon(wx.Icon("icon.ico", wx.BITMAP_TYPE_ICO))
except Exception as e:
print e
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.sb = self.CreateStatusBar() # A Statusbar in the bottom of the window
panel = wx.Panel(self, -1)
if self.language == 'en':
static = wx.StaticText(panel, -1, 'Select a date/time to load the chat data.', (5,12), (210, 15))
wx.StaticText(panel, -1, 'Search', (220,12), (35, 15))
else:
static = wx.StaticText(panel, -1, u'選択して日付と時刻は、チャットデータをロードする.', (5,12), (210, 15))
wx.StaticText(panel, -1, u'検索', (220,12), (35, 15))
self.loadingMsg = wx.StaticText(panel, -1, '', (390,12), (30, 15))
self.searchbox = wx.TextCtrl(panel, -1, pos=(260, 9), size=(120, 19), style=wx.TE_PROCESS_ENTER)
self.searchbox.Bind(wx.EVT_TEXT_ENTER, self.DoSearch)
self.datelist = wx.ListBox(panel, -1, pos=(0, 40), size=(140, 300))
self.Bind(wx.EVT_LISTBOX, self.OnDateSelected, self.datelist)
self.logWindow = wx.richtext.RichTextCtrl(panel, -1, pos=(132,40), size=(250, 300), style=wx.TE_READONLY | wx.EXPAND | wx.TE_MULTILINE)
self.logWindow.Bind(wx.EVT_RIGHT_DOWN, self.CustomMenu)
self.logWindow.SetBackgroundColour((243, 246, 237))
self.LoadDates()
self.Bind(wx.EVT_SIZE, self.OnSize)
def CustomMenu(self, event):
pos = (event.GetPosition()[0]+self.logWindow.GetPosition()[0], event.GetPosition()[1]+self.logWindow.GetPosition()[1])
self.PopupMenu(LogWindowContext(self), pos, self.language)
def DoSearch(self, event):
if self.language == 'en':
self.loadingMsg.SetLabel("Searching...")
else:
self.loadingMsg.SetLabel(u"検索...")
self.logWindow.Clear()
self.datelist.SetSelection(-1)
searchval = self.searchbox.GetValue().lower()
idx = 0.0
ttllen = self.datelist.GetCount()
for index in ReverseIterator(range(ttllen - 1)):
idx = idx + 1
if self.language == 'en':
self.loadingMsg.SetLabel("Searching... %i%%" % ((idx / ttllen) * 100.0))
else:
self.loadingMsg.SetLabel(u"検索... %i%%" % ((idx / ttllen) * 100.0))
app.Yield()
filename = os.path.join('chatlogs', self.datelist.GetString(index + 1) + '.chat')
filesize = os.path.getsize(filename)
with open(filename, 'rb') as f:
chatdata = pickle.load(f)
for chatitem in chatdata:
if (chatitem[1].lower().find(searchval) > -1) or (chatitem[2].lower().find(searchval) > -1):
self.WriteDataToDisplay(chatitem, singlevalue=True)
self.loadingMsg.SetLabel("")
def WriteDataToDisplay(self, chatdata, singlevalue=False):
self.logWindow.BeginSuppressUndo()
if singlevalue:
try:
try:
self.chat_types[chatdata[0]](chatdata[1], chatdata[2])
self.logWindow.ShowPosition(self.logWindow.GetLastPosition())
except KeyError as e:
self.WriteSay(chatdata[1], chatdata[2])
except:
pass
else:
for chatitem in chatdata:
try:
try:
self.chat_types[chatitem[0]](chatitem[1], chatitem[2])
self.logWindow.ShowPosition(self.logWindow.GetLastPosition())
except KeyError as e:
self.WriteSay(chatitem[1], chatitem[2])
except:
pass
self.logWindow.EndSuppressUndo()
def RefreshDisplay(self):
#self.LoadDates()
#self.DoDateLoad(self.datelist.GetString(self.datelist.GetSelection()))
pass
def OnDateSelected(self, event):
self.DoDateLoad(event.GetString())
def DoDateLoad(self, datestring):
global app
if self.language == 'en':
self.loadingMsg.SetLabel("Loading...")
else:
self.loadingMsg.SetLabel(u"ロード...")
self.logWindow.Clear()
#self.logWindow.Freeze()
if datestring != "-- Last 20 Logs --" and datestring != u'-- 20最後にログ --':
filename = os.path.join('chatlogs', datestring + '.chat')
filesize = os.path.getsize(filename)
with open(filename, 'rb') as f:
chatdata = pickle.load(f)
self.WriteDataToDisplay(chatdata)
else:
idx = 0.0
ttllen = self.datelist.GetCount()
if ttllen > 20:
ttllen = 20
for index in ReverseIterator(range(ttllen - 1)):
idx = idx + 1
if self.language == 'en':
self.loadingMsg.SetLabel("Loading... %i%%" % ((idx / ttllen) * 100.0))
else:
self.loadingMsg.SetLabel(u"ロード... %i%%" % ((idx / ttllen) * 100.0))
app.Yield()
filename = os.path.join('chatlogs', self.datelist.GetString(index + 1) + '.chat')
filesize = os.path.getsize(filename)
with open(filename, 'rb') as f:
chatdata = pickle.load(f)
self.WriteDataToDisplay(chatdata)
#self.logWindow.Thaw()
self.loadingMsg.SetLabel("")
def OnSize(self, event):
event.Skip()
size = event.GetSize()
self.logWindow.SetSize((size[0] - 150, size[1] - 102))
self.datelist.SetSize((130, size[1] - 102))
def LoadDates(self):
# This loads all date files into the listbox.
chatdates = [(os.stat(i).st_mtime, i) for i in glob.glob(os.path.join('chatlogs', '*.chat'))]
chatdates.sort(reverse=True)
if len(self.currdates) == 0:
if self.language == 'en':
self.datelist.Append("-- Last 20 Logs --")
else:
self.datelist.Append(u"-- 20最後にログ --")
for date in chatdates:
filename = os.path.basename(os.path.splitext(date[1])[0])
self.currdates.append(filename)
self.datelist.Append(filename)
else:
diff = set(chatdates).difference( set(self.currdates) )
for date in diff:
filename = os.path.basename(os.path.splitext(date[1])[0])
self.currdates.append(filename)
self.datelist.Append(filename)
def WriteEmote(self, charname, text):
self.logWindow.BeginTextColour((80, 50, 50))
self.logWindow.WriteText("%s\r" % (text))
self.logWindow.EndTextColour()
def WriteParty(self, charname, text):
self.logWindow.BeginTextColour((70, 70, 170))
self.logWindow.WriteText("<%s> %s\r" % (charname, text))
self.logWindow.EndTextColour()
def WriteTell(self, charname, text):
self.logWindow.BeginTextColour((190, 70, 70))
if self.language == 'en':
self.logWindow.WriteText("%s whispers %s\r" % (charname, text))
else:
self.logWindow.WriteText(u"%s >> %s\r" % (charname, text))
self.logWindow.EndTextColour()
def WriteShout(self, charname, text):
self.logWindow.BeginTextColour((140, 50, 50))
if self.language == 'en':
self.logWindow.WriteText("%s shouts %s\r" % (charname, text))
else:
self.logWindow.WriteText(u"%s コメント %s\r" % (charname, text))
self.logWindow.EndTextColour()
def WriteLinkshell(self, charname, text):
self.logWindow.BeginTextColour((50, 140, 50))
self.logWindow.BeginBold()
self.logWindow.WriteText("<" + charname + "> ")
self.logWindow.EndBold()
self.logWindow.WriteText(text + "\r")
self.logWindow.EndTextColour()
def WriteSay(self, charname, text):
if self.language == 'en':
self.logWindow.WriteText("%s says %s\r" % (charname, text))
else:
self.logWindow.WriteText(u"%s 言う %s\r" % (charname, text))
def OnClose(self, e):
self.Destroy();
class MainFrame(wx.Frame):
def SaveLanguageSetting(self, lang):
global configfile, currentlanguage
config = ConfigParser.ConfigParser()
try:
config.add_section('Config')
except ConfigParser.DuplicateSectionError:
pass
config.read(configfile)
self.language = lang
currentlanguage = lang
config.set('Config', 'language', lang)
with open(configfile, 'wb') as openconfigfile:
config.write(openconfigfile)
def SetEnglish(self, event):
self.SetTitle("FFXIV Log Parser")
self.filemenu.SetLabel(1, "&Start")
self.filemenu.SetHelpString(1, " Start Processing Logs")
#self.filemenu.SetLabel(4, "&Parse All Logs")
#self.filemenu.SetHelpString(4, " Start Processing All Logs")
self.filemenu.SetLabel(wx.ID_ABOUT, "&About")
self.filemenu.SetHelpString(wx.ID_ABOUT, " Information about this program")
self.filemenu.SetLabel(2, "&Check for New Version")
self.filemenu.SetHelpString(2, " Check for an update to the program")
self.filemenu.SetLabel(wx.ID_EXIT, "E&xit")
self.filemenu.SetHelpString(wx.ID_EXIT, " Terminate the program")
self.chatmenu.SetLabel(13, 'Chat &Viewer')
self.chatmenu.SetHelpString(13, "Opens the chat viewer window.")
self.menuBar.SetLabelTop(0, "&File")
self.menuBar.SetLabelTop(1, "&Language")
self.menuBar.SetLabelTop(2, "&Chat")
self.st.SetLabel("Select Log Path")
self.st2.SetLabel("Enter Your Character Name (default is unique id to hide your name)")
if self.btnCharChange:
self.btnCharChange.SetLabel("Change")
self.btnStart.SetLabel("Start")
self.lblLogWindow.SetLabel("Activity Log")
self.charlink.SetLabel("test")
self.charlink.SetLabel("FFXIVBattle.com Character Page")
self.charlink.SetURL("http://ffxivbattle.com/character.php?charactername=%s&lang=en" % (self.charname.GetValue()))
self.SaveLanguageSetting('en')
def SetJapanese(self, event):
self.SetTitle(u"FFXIVのログパーサー")
self.filemenu.SetLabel(1, u"開始")
self.filemenu.SetHelpString(1, u"スタート処理のログ")
#self.filemenu.SetLabel(4, u"再解析のログ")
#self.filemenu.SetHelpString(4, u" 再解析のログ")
self.filemenu.SetLabel(wx.ID_ABOUT, u"について")
self.filemenu.SetHelpString(wx.ID_ABOUT, u"このプログラムについての情報")
self.filemenu.SetLabel(2, u"新しいバージョンの確認")
self.filemenu.SetHelpString(2, u"プログラムの更新をチェックする")
self.filemenu.SetLabel(wx.ID_EXIT, u"終了")
self.filemenu.SetHelpString(wx.ID_EXIT, u"終了プログラム")
self.chatmenu.SetLabel(13, u'チャットビューア')
self.chatmenu.SetHelpString(13, u"が表示されますビューアチャットウィンドウ。")
self.menuBar.SetLabelTop(0, u"ファイル")
self.menuBar.SetLabelTop(1, u"言語")
self.menuBar.SetLabelTop(2, u"チャット")
self.st.SetLabel(u"選択してログのパス")
self.st2.SetLabel(u"文字型の名前 (デフォルトでは、名前を非表示にする一意のIDです)")
if self.btnCharChange:
self.btnCharChange.SetLabel(u"変更")
self.btnStart.SetLabel(u"開始")
self.lblLogWindow.SetLabel(u"アクティビティログ")
self.charlink.SetLabel(u"FFXIVBattle.com文字ページ")
self.charlink.SetURL("http://ffxivbattle.com/character.php?charactername=%s&lang=jp" % (self.charname.GetValue()))
self.SaveLanguageSetting('jp')
def OpenChatViewer(self, event):
self.chatviewer = ChatViewer(self.language)
self.chatviewer.Show()
def __init__(self, parent, title):
global configfile, autotranslatearray, currentlanguage
wx.Frame.__init__(self, parent, title=title, size=(400,314))
try:
self.SetIcon(wx.Icon("icon.ico", wx.BITMAP_TYPE_ICO))
except Exception as e:
print e
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.sb = self.CreateStatusBar() # A Statusbar in the bottom of the window
self.salt = None
# Setting up the menu.
self.filemenu= wx.Menu()
# wx.ID_ABOUT and wx.ID_EXIT are standard IDs provided by wxWidgets.
self.filemenu.Append(1, "&Start"," Start Processing Logs")
#self.filemenu.Append(4, "&Parse All Logs"," Start Processing All Logs")
self.filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
self.filemenu.AppendSeparator()
self.filemenu.Append(2, "&Check for New Version"," Check for an update to the program")
self.filemenu.AppendSeparator()
self.filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
self.Bind(wx.EVT_MENU, self.OnStartCollectingAll, id=1)
#self.Bind(wx.EVT_MENU, self.OnStartCollectingAll, id=4)
self.Bind(wx.EVT_MENU, self.OnCheckVersion, id=2)
self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
self.Bind(wx.EVT_MENU, self.OnAbout, id=wx.ID_ABOUT)#menuItem)
# Setup language menu
self.languagemenu= wx.Menu()
self.englishMenu = self.languagemenu.Append(11, "&English","Set application to english display", kind=wx.ITEM_RADIO)
self.japaneseMenu = self.languagemenu.Append(12, u"日本語", u"日本語表示", kind=wx.ITEM_RADIO)
self.Bind(wx.EVT_MENU, self.SetEnglish, id=11)
self.Bind(wx.EVT_MENU, self.SetJapanese, id=12)
# Setup chat menu
self.chatmenu= wx.Menu()
self.chatviewerMenu = self.chatmenu.Append(13, "Chat &Viewer","Opens the chat viewer window")
self.Bind(wx.EVT_MENU, self.OpenChatViewer, id=13)
# Creating the menubar.
self.menuBar = wx.MenuBar()
self.menuBar.Append(self.filemenu,"&File") # Adding the "filemenu" to the MenuBar
self.menuBar.Append(self.languagemenu,"&Language") # Adding the "filemenu" to the MenuBar
self.menuBar.Append(self.chatmenu,"&Chat") # Adding the "filemenu" to the MenuBar
self.SetMenuBar(self.menuBar) # Adding the MenuBar to the Frame content.
panel = wx.Panel(self, -1)
logpath = ""
charactername = hex(uuid.getnode())
charinconfig = False
# read defaults
config = ConfigParser.ConfigParser()
try:
config.read(configfile)
logpath = config.get('Config', 'logpath')
charactername = config.get('Config', 'charactername')
charinconfig = True
except:
logpath = ""
pass
if logpath == "":
userdir = os.path.expanduser('~')
logpath = os.path.join(userdir, "Documents\\My Games\\FINAL FANTASY XIV\\user\\")
userdirs = os.listdir(logpath)
newestdate = None
try:
for dir in userdirs:
l = [(os.stat(i).st_mtime, i) for i in glob.glob(os.path.join(logpath, dir, 'log', '*.log'))]
l.sort()
if len(l) > 0:
if newestdate != None:
if l[0][0] > newestdate:
newestdate = l[0][0];
logpath = os.path.join(logpath, dir, 'log')
else:
newestdate = l[0][0];
logpath = os.path.join(logpath, dir, 'log')
except:
logpath = os.path.join(userdir, "Documents\\My Games\\FINAL FANTASY XIV\\user\\")
self.st = wx.StaticText(panel, -1, 'Select Log Path', (5,3))
self.control = wx.TextCtrl(panel, -1, logpath, (5,21), (345, 22))
self.btnDialog = wx.Button(panel, 102, "...", (350,20), (28, 24))
self.Bind(wx.EVT_BUTTON, self.OnLogSelect, id=102)
if charinconfig:
self.st2 = wx.StaticText(panel, -1, 'Enter Your Character Name (default is unique id to hide your name)', (5,53))
self.charname = wx.TextCtrl(panel, -1, charactername, (5,70), (310, 22))
self.charname.Disable()
self.btnCharChange = wx.Button(panel, 150, "Change", (320,69), (55, 24))
self.Bind(wx.EVT_BUTTON, self.OnChangeCharacter, id=150)
else:
self.btnCharChange = None
self.st2 = wx.StaticText(panel, -1, 'Enter Your Character Name (default is unique id to hide your name)', (5,53))
self.charname = wx.TextCtrl(panel, -1, charactername, (5,70), (370, 22))
self.btnStart = wx.Button(panel, 103, "Start", (150,100))
self.Bind(wx.EVT_BUTTON, self.OnStartCollecting, id=103)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.lblLogWindow = wx.StaticText( panel, -1, "Activity Log", (5,120))
self.logWindow = wx.TextCtrl(panel, -1, "", (5,136), (370, 80), style=wx.TE_MULTILINE)
self.logLayout = wx.BoxSizer( wx.HORIZONTAL )
self.logLayout.Add( self.lblLogWindow, 0, wx.EXPAND )
self.logLayout.Add( self.logWindow, 1, wx.EXPAND | wx.BOTTOM | wx.RIGHT )
redir=RedirectText(self.logWindow)
self.charlink = hl.HyperLinkCtrl(panel, -1, "FFXIVBattle.com Character Page", (5,216), (22, 80))
self.charlink.SetURL("http://ffxivbattle.com/character.php?charactername=" + charactername)
self.language = 'en'
try:
configlang = config.get('Config', 'language')
if configlang == 'jp':
self.languagemenu.Check(12, True)
self.SetJapanese(None)
self.language = 'jp'
currentlanguage = 'jp'
except:
pass
sys.stdout=redir
self.Show(True)
'''
if os.path.exists('autotranslate.gz'):
print "Opening autotranslate file..."
f = gzip.open('autotranslate.gz', 'rb')
autotranslatearray = json.loads(f.read())
f.close()
print "Autotranslate loaded."
'''
def OnChangeCharacter(self, event):
global configfile
if self.language == 'en':
changecharnamedlg = ChangeCharacterNameDialog(self, -1, "Enter New Character Name", self.language)
else:
changecharnamedlg = ChangeCharacterNameDialog(self, -1, u"新キャラクター名を入力してください", self.language)
if changecharnamedlg.ShowModal() == wx.ID_OK:
if not self.salt:
# extract salt from the dir
dirparts = self.control.GetValue().split("\\")
# set the salt to the users directory name for the character. Not 100% but good enough to salt with.
self.salt = ""
if dirparts[len(dirparts)-1] == "":
self.salt = dirparts[len(dirparts) - 3]
else:
self.salt = dirparts[len(dirparts) - 2]
hash = hashlib.md5( self.salt + changecharnamedlg.GetPassword() ).hexdigest()
results = self.ChangeCharacterName(self.charname.GetValue(), changecharnamedlg.GetNewCharacterName(), hash)
if results:
if results["code"] < 0:
if self.language == 'en':
dlg = wx.MessageDialog( self, results["text"], "Error Changing Character Name", wx.OK)
else:
dlg = wx.MessageDialog( self, results["text"], u"文字の名前の変更中にエラー", wx.OK)
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
else:
self.charname.SetValue(changecharnamedlg.GetNewCharacterName())
config = ConfigParser.ConfigParser()
try:
config.add_section('Config')
except ConfigParser.DuplicateSectionError:
pass
config.read(configfile)
config.set('Config', 'charactername', self.charname.GetValue())
with open(configfile, 'wb') as openconfigfile:
config.write(openconfigfile)
if self.language == 'en':
dlg = wx.MessageDialog( self, results["text"], "Success", wx.OK)
else:
dlg = wx.MessageDialog( self, results["text"], u"成功", wx.OK)
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
else:
if self.language == 'en':
dlg = wx.MessageDialog( self, "Did not understand server response.", "Try Again Later", wx.OK)
else:
dlg = wx.MessageDialog( self, u"サーバの応答を解釈しませんでした。", u"てみてください後でもう一度", wx.OK)
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
else:
if self.language == 'en':
print "Character name change cancelled."
else:
print u"キャラクター名の変更がキャンセルされました。"
def ChangeCharacterName(self, charactername, newcharactername, hashed_password):
# call out to verify the password
response = None
try:
encodedname = urllib.urlencode({"oldcharname": charactername.encode("utf-8")})
newencodedname = urllib.urlencode({"newcharname": newcharactername.encode("utf-8")})
response = urllib2.urlopen('http://ffxivbattle.com/updatecharactername.php?%s&%s&password=%s' % (encodedname, newencodedname, hashed_password))
responsetext = response.read()
#print responsetext
return json.loads(responsetext)
except Exception as e:
# The result was garbage so skip it.
print type(e)
print e
print "Did not understand the response from the server for the character name change."
return False
def OnSize(self, event):
event.Skip()
size = event.GetSize()
self.logWindow.SetSize((size[0] - 30, size[1] - 240))
self.charlink.SetPosition((5, size[1] - 100))
def CheckPassword(self, charactername, salt, hashed_password):
# call out to verify the password
response = None
try:
encodedname = urllib.urlencode({"charactername": charactername.encode("utf-8")})
response = urllib2.urlopen('http://ffxivbattle.com/passwordcheck.php?%s&salt=%s&password=%s' % (encodedname, salt, hashed_password))
return json.loads(response.read())["result"] == True
except Exception, e:
# The result was garbage so skip it.
print e
print "Did not understand the response from the server for the password check."
return False
def GetPassword(self, config, salt):
pass_stored = ""
try:
if self.language == 'en':
passwordentry = PasswordDialog(self, -1, "Enter password", pass_stored, self.language)
else:
passwordentry = PasswordDialog(self, -1, u"パスワードを入力してください", pass_stored, self.language)
try:
pass_stored = config.get('Config', 'password')
passwordentry.SetChecked(True)
passwordentry.SetValue(pass_stored)
except ConfigParser.NoOptionError:
pass
if passwordentry.ShowModal() == wx.ID_OK:
if pass_stored != "":
if pass_stored != passwordentry.GetValue():
password = passwordentry.GetValue()
if password != "":
hash = hashlib.md5( salt + password ).hexdigest()
return hash, passwordentry.GetChecked()
else:
return pass_stored, passwordentry.GetChecked()
else:
password = passwordentry.GetValue()
if password != "":
hash = hashlib.md5( salt + password ).hexdigest()
return hash, passwordentry.GetChecked()
else:
return "", False
else:
return "", passwordentry.GetChecked()
finally:
passwordentry.Destroy()
def OnIdle( self, evt ):
if self.process is not None:
stream = self.process.GetInputStream()
if stream.CanRead():
text = stream.read()
self.logWindow.AppendText( text )
def OnLogSelect(self, e):
if self.japaneseMenu.IsChecked():
dlg = wx.DirDialog(self, u"ログディレクトリを選択してください:", self.control.GetValue(), style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
else:
dlg = wx.DirDialog(self, "Choose the Log Directory:", self.control.GetValue(), style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
if dlg.ShowModal() == wx.ID_OK:
self.control.SetValue(dlg.GetPath())
dlg.Destroy()
def OnAbout(self,e):
global version
license = '''Copyright (C) 2010-2011 FFXIVBattle.com All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Log Parser"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution, and in the same place and form as other copyright, license and disclaimer information.
3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by FFXIVBattle.com (http://www.ffxivbattle.com/) and its contributors", in the same place and form as other third-party acknowledgments. Alternately, this acknowledgment may appear in the software itself, in the same form and location as other such third-party acknowledgments.
4. Except as contained in this notice, the name of FFXIVBattle.com shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from FFXIVBattle.com.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FFXIVBATTLE.COM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
info = wx.AboutDialogInfo()
info.SetName('FFXIV Log Parser')
info.SetVersion(str(version))
if self.japaneseMenu.IsChecked():
info.SetDescription(u"ファイナルファンタジーXIVのログパーサー。")
info.AddTranslator(u'H3lls ([email protected]) ご了承ください、私は翻訳の間違いをしたなら、私に知らせてください。')
else:
info.SetDescription("A log parser for Final Fantasy XIV.")
info.AddTranslator('H3lls ([email protected]) PLEASE let me know if I have made any mistakes in translation.')
info.SetIcon(wx.Icon('icon.ico',wx.BITMAP_TYPE_ICO))
info.SetCopyright('(C) 2011 ffxivbattle.com')
info.SetWebSite('http://www.ffxivbattle.com')
info.SetLicence(license)
info.AddDeveloper('H3lls ([email protected])')
wx.AboutBox(info)
def OnCheckVersion(self, e):
if self.japaneseMenu.IsChecked():
lang = "JP"
else:
lang = "EN"
if versioncheck(status=1, language=lang):
Popen("setup.exe", shell=False) # start reloader
self.OnExit(None)
return
def OnStartCollectingAll(self, e):
global lastlogparsed
lastlogparsed = 0
self.OnStartCollecting(e)
def OnStartCollecting(self, e):
global guithread, configfile
self.filemenu.Enable(1, False)
#self.filemenu.Enable(4, False)
self.btnStart.Disable()
#try:
config = ConfigParser.ConfigParser()
try:
config.add_section('Config')
except ConfigParser.DuplicateSectionError:
pass
config.read(configfile)
# extract salt from the dir
dirparts = self.control.GetValue().split("\\")
# set the salt to the users directory name for the character. Not 100% but good enough to salt with.
self.salt = ""
if dirparts[len(dirparts)-1] == "":
self.salt = dirparts[len(dirparts) - 3]
else:
self.salt = dirparts[len(dirparts) - 2]
password, savepass = self.GetPassword(config, self.salt)
if self.CheckPassword(self.charname.GetValue(), self.salt, password):
if savepass:
config.set('Config', 'password', password)
else:
try:
config.remove_option('Config', 'password')
except ConfigParser.NoSectionError:
pass
else:
if self.language == 'en':
dlg = wx.MessageDialog( self, "The password provided does not match.", "Invalid Password", wx.OK)
else:
dlg = wx.MessageDialog( self, u"提供されたパスワードが一致しません。", u"無効なパスワード", wx.OK)
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
self.filemenu.Enable(1, True)
#self.filemenu.Enable(4, True)
self.btnStart.Enable()
return
config.set('Config', 'logpath', self.control.GetValue())
config.set('Config', 'charactername', self.charname.GetValue())
with open(configfile, 'wb') as openconfigfile:
config.write(openconfigfile)
#except (Exception, e):
# print e
try:
self.charlink.SetURL("http://ffxivbattle.com/character.php?charactername=" + self.charname.GetValue())
guithread.updatevalues(self.control.GetValue(), self.charname.GetValue(), self.OnStatus, completecallback=self.threadcallback, password=password)
guithread.daemon = False
guithread.start()
except:
pass
def threadcallback(self):
if self:
if self.filemenu:
self.filemenu.Enable(1, True)
if self.btnStart:
self.btnStart.Enable()
def OnClose(self, e):
self.Destroy();
def OnExit(self,e):
self.Close(True) # Close the frame.
def OnStatus(self, message):
try:
self.sb.PushStatusText(message, 0)
except:
pass
class RedirectText(object):
def __init__(self,aWxTextCtrl):
self.out=aWxTextCtrl
def write(self,string):
try:
self.out.AppendText(string)
except:
pass
class GUIThread(Thread):
def __init__(self, logpath, charactername, status):
self.stopped = 1
self.logpath = logpath
self.charactername = charactername
self.status = status
self.exitready = 0
Thread.__init__(self)
def updatevalues(self, logpath, charactername, status, completecallback=None, password=""):
self.stopped = 0
self.logpath = logpath
self.charactername = charactername
self.status = status
self.completecallback = completecallback
self.password = password
def exit(self):
self.stopped = 1
def exitcomplete(self):
return self.exitready
def is_running(self):
if self.stopped:
return 0
else:
return 1
def run(self):
try:
en_parser = english_parser()
jp_parser = japanese_parser()
en_parser.characterdata["charactername"] = self.charactername
jp_parser.characterdata["charactername"] = self.charactername
parsers = [en_parser, jp_parser]
self.exitready = 0
self.stopped = 0
prev = []
while not self.stopped:
l = [(os.stat(i).st_mtime, i) for i in glob.glob(os.path.join(self.logpath, '*.log'))]
l.sort()
diff = set(l).difference( set(prev) )
if len(diff) > 0:
self.status("Found " + str(len(l)) + " new logs.")
prev = l
if len(diff) == len(l):
files = [i[1] for i in l]
else:
files = [i[1] for i in l[len(l)-len(diff):]]
readLogFile(files, self.charactername, isrunning=self.is_running, password=self.password, parsers=parsers)
start = datetime.datetime.now()
self.status("Waiting for new log data...")
while (datetime.datetime.now() - start).seconds < 5:
time.sleep(1)
if self.stopped:
return
finally:
self.exitready = 1
self.stopped = 1
if self.completecallback:
self.completecallback()
def main():
#try:
global doloop, guithread, configfile, lastlogparsed, app, autotranslatearray
args = sys.argv[1:]
config = ConfigParser.ConfigParser()
try:
config.read(configfile)
lastlogparsed = float(config.get('Config', 'lastlogparsed'))
except:
pass
if len(args) < 1:
try: