-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.cpp
4377 lines (3878 loc) · 129 KB
/
gui.cpp
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
/*
* Mutated into DGIndex. Modifications Copyright (C) 2004-2008, Donald Graft
*
* Copyright (C) Chia-chen Kuo - April 2001
*
* This file is part of DVD2AVI, a free MPEG-2 decoder
*
* DVD2AVI is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* DVD2AVI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#define _WIN32_WINNT 0x0501 // Needed for WM_MOUSEWHEEL
#include <windows.h>
#include "resource.h"
#include "Shlwapi.h"
#include <lm.h>
#define GLOBAL
#include "global.h"
static char Version[] = "DGIndex 2.0.0.5";
#define TRACK_HEIGHT 32
#define INIT_WIDTH 480
#define INIT_HEIGHT 270
#define MIN_WIDTH 160
#define MIN_HEIGHT 32
#define MASKCOLOR RGB(0, 6, 0)
#define SAVE_D2V 1
#define SAVE_WAV 2
#define OPEN_D2V 3
#define OPEN_VOB 4
#define OPEN_WAV 5
#define SAVE_BMP 6
#define OPEN_AVS 7
#define OPEN_TXT 8
#define PRIORITY_HIGH 1
#define PRIORITY_NORMAL 2
#define PRIORITY_LOW 3
bool PopFileDlg(PTSTR, HWND, int);
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK SelectProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Info(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK VideoList(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Cropping(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Luminance(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Speed(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Normalization(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK SelectTracks(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK SelectDelayTrack(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK SetPids(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK AVSTemplate(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK BMPPath(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK DetectPids(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
static void ShowInfo(bool);
static void SaveBMP(void);
static void CopyBMP(void);
static void OpenVideoFile(HWND);
static void OpenAudioFile(HWND);
void OutputProgress(int);
static void StartupEnables(void);
static void FileLoadedEnables(void);
static void RunningEnables(void);
static int INIT_X, INIT_Y, Priority_Flag, Edge_Width, Edge_Height;
static FILE *INIFile;
static char szPath[DG_MAX_PATH], szTemp[DG_MAX_PATH], szWindowClass[DG_MAX_PATH];
static HINSTANCE hInst;
static HANDLE hProcess, hThread;
static HWND hLeftButton, hLeftArrow, hRightArrow, hRightButton;
static DWORD threadId;
static RECT wrect, crect, info_wrect;
static int SoundDelay[MAX_FILE_NUMBER];
static char Outfilename[MAX_FILE_NUMBER][DG_MAX_PATH];
extern int fix_d2v(HWND hWnd, char *path, int test_only);
extern int parse_d2v(HWND hWnd, char *path);
extern int analyze_sync(HWND hWnd, char *path, int track);
extern unsigned char *Rdbfr;
bool GetWindowsVersion(DWORD& major, DWORD& minor)
{
LPBYTE pinfoRawData;
if (NERR_Success == NetWkstaGetInfo(NULL, 100, &pinfoRawData))
{
WKSTA_INFO_100 * pworkstationInfo = (WKSTA_INFO_100 *)pinfoRawData;
major = pworkstationInfo->wki100_ver_major;
minor = pworkstationInfo->wki100_ver_minor;
::NetApiBufferFree(pinfoRawData);
return true;
}
return false;
}
int MessageBoxTimeout(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType, WORD wLanguageId, DWORD dwMilliseconds)
{
typedef int(__stdcall* MSGBOXAAPI)(IN HWND hWnd, IN LPCSTR lpText, IN LPCSTR lpCaption, IN UINT uType, IN WORD wLanguageId, IN DWORD dwMilliseconds);
static MSGBOXAAPI MsgBoxTOA = NULL;
if (!MsgBoxTOA)
{
HMODULE hUser32 = GetModuleHandle("user32.dll");
if (hUser32)
{
MsgBoxTOA = (MSGBOXAAPI)GetProcAddress(hUser32, "MessageBoxTimeoutA");
//fall through to 'if (MsgBoxTOA)...'
}
else
{
//Stuff happened, add code to handle it here (possibly just call MessageBox())
return 0;
}
}
if (MsgBoxTOA)
{
return MsgBoxTOA(hWnd, lpText, lpCaption, uType, wLanguageId, dwMilliseconds);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HACCEL hAccel;
int i;
char *ptr;
char ucCmdLine[4096];
char prog[DG_MAX_PATH];
char cwd[DG_MAX_PATH];
DWORD major, minor;
if (GetWindowsVersion(major, minor))
bIsWindowsXPorLater = (major > 5) || ((major == 5) && (minor >= 1));
if(bIsWindowsXPorLater)
{
// Prepare status output (console/file).
if (GetStdHandle(STD_OUTPUT_HANDLE) == (HANDLE)0)
{
// No output handle. We'll try to attach a console.
AttachConsole( ATTACH_PARENT_PROCESS );
}
else
{
if (FlushFileBuffers(GetStdHandle(STD_OUTPUT_HANDLE)))
{
// Flush succeeded -> We are NOT writing to console (output redirected to file, etc.). No action required.
}
else
{
// Flush failed -> We are writing to console. AttachConsole to enable it.
AttachConsole( ATTACH_PARENT_PROCESS );
}
}
}
// Get the path to the DGIndex executable.
GetModuleFileName(NULL, ExePath, DG_MAX_PATH);
// Find first char after last backslash.
if ((ptr = strrchr(ExePath,'\\')) != 0) ptr++;
else ptr = ExePath;
*ptr = 0;
// Load INI
strcpy(prog, ExePath);
strcat(prog, "DGIndex.ini");
if ((INIFile = fopen(prog, "r")) == NULL)
{
NEW_VERSION:
INIT_X = INIT_Y = 100;
info_wrect.left = info_wrect.top = 100;
iDCT_Flag = IDCT_SKAL;
Scale_Flag = true;
setRGBValues();
FO_Flag = FO_NONE;
Method_Flag = AUDIO_DEMUXALL;
strcpy(Track_List, "");
DRC_Flag = DRC_NORMAL;
DSDown_Flag = false;
SRC_Flag = SRC_NONE;
Norm_Ratio = 100;
Priority_Flag = PRIORITY_NORMAL;
PlaybackSpeed = SPEED_NORMAL;
ForceOpenGops = 0;
// Default the AVS template path.
// Get the path to the DGIndex executable.
GetModuleFileName(NULL, AVSTemplatePath, 255);
// Find first char after last backslash.
if ((ptr = strrchr(AVSTemplatePath,'\\')) != 0) ptr++;
else ptr = AVSTemplatePath;
*ptr = 0;
strcat(AVSTemplatePath, "template.avs");
FullPathInFiles = 1;
LoopPlayback = 0;
FusionAudio = 0;
HDDisplay = HD_DISPLAY_SHRINK_BY_HALF;
for (i = 0; i < 4; i++)
mMRUList[i][0] = 0;
InfoLog_Flag = 1;
BMPPathString[0] = 0;
UseMPAExtensions = 0;
NotifyWhenDone = 0;
}
else
{
char line[DG_MAX_PATH], *p;
unsigned int audio_id;
fgets(line, DG_MAX_PATH - 1, INIFile);
line[strlen(line)-1] = 0;
p = line;
while (*p != '=' && *p != 0) p++;
if (*p == 0 || strcmp(++p, Version))
{
fclose(INIFile);
goto NEW_VERSION;
}
fscanf(INIFile, "Window_Position=%d,%d\n", &INIT_X, &INIT_Y);
fscanf(INIFile, "Info_Window_Position=%d,%d\n", &info_wrect.left, &info_wrect.top);
fscanf(INIFile, "iDCT_Algorithm=%d\n", &iDCT_Flag);
fscanf(INIFile, "YUVRGB_Scale=%d\n", &Scale_Flag);
setRGBValues();
fscanf(INIFile, "Field_Operation=%d\n", &FO_Flag);
fscanf(INIFile, "Output_Method=%d\n", &Method_Flag);
fgets(line, DG_MAX_PATH - 1, INIFile);
line[strlen(line)-1] = 0;
p = line;
while (*p++ != '=');
strcpy (Track_List, p);
for (i = 0; i < 0xc8; i++)
audio[i].selected_for_demux = false;
while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') || (*p >= 'A' && *p <= 'F'))
{
sscanf(p, "%x", &audio_id);
if (audio_id > 0xc7)
break;
audio[audio_id].selected_for_demux = true;
while (*p != ',' && *p != 0) p++;
if (*p == 0)
break;
p++;
}
fscanf(INIFile, "DR_Control=%d\n", &DRC_Flag);
fscanf(INIFile, "DS_Downmix=%d\n", &DSDown_Flag);
fscanf(INIFile, "SRC_Precision=%d\n", &SRC_Flag);
fscanf(INIFile, "Norm_Ratio=%d\n", &Norm_Ratio);
fscanf(INIFile, "Process_Priority=%d\n", &Priority_Flag);
fscanf(INIFile, "Playback_Speed=%d\n", &PlaybackSpeed);
fscanf(INIFile, "Force_Open_Gops=%d\n", &ForceOpenGops);
fgets(line, DG_MAX_PATH - 1, INIFile);
line[strlen(line)-1] = 0;
p = line;
while (*p++ != '=');
strcpy (AVSTemplatePath, p);
fscanf(INIFile, "Full_Path_In_Files=%d\n", &FullPathInFiles);
fscanf(INIFile, "Fusion_Audio=%d\n", &FusionAudio);
fscanf(INIFile, "Loop_Playback=%d\n", &LoopPlayback);
fscanf(INIFile, "HD_Display=%d\n", &HDDisplay);
for (i = 0; i < 4; i++)
{
fgets(line, DG_MAX_PATH - 1, INIFile);
line[strlen(line)-1] = 0;
p = line;
while (*p++ != '=');
strcpy(mMRUList[i], p);
}
fscanf(INIFile, "Enable_Info_Log=%d\n", &InfoLog_Flag);
fgets(line, DG_MAX_PATH - 1, INIFile);
line[strlen(line)-1] = 0;
p = line;
while (*p++ != '=');
strcpy(BMPPathString, p);
fscanf(INIFile, "Use_MPA_Extensions=%d\n", &UseMPAExtensions);
fscanf(INIFile, "Notify_When_Done=%d\n", &NotifyWhenDone);
fclose(INIFile);
}
// Allocate stream buffer.
Rdbfr = (unsigned char *) malloc(BUFFER_SIZE);
if (Rdbfr == NULL)
{
MessageBox(hWnd, "Couldn't allocate stream buffer using configured size.\nTrying default size.", NULL, MB_OK | MB_ICONERROR);
Rdbfr = (unsigned char *) malloc(32 * SECTOR_SIZE);
if (Rdbfr == NULL)
{
MessageBox(hWnd, "Couldn't allocate stream buffer using default size.\nExiting.", NULL, MB_OK | MB_ICONERROR);
exit(0);
}
}
// Perform application initialization
hInst = hInstance;
// Load accelerators
hAccel = LoadAccelerators(hInst, (LPCTSTR)IDR_ACCELERATOR);
// Initialize global strings
LoadString(hInst, IDC_GUI, szWindowClass, DG_MAX_PATH);
MyRegisterClass(hInst);
hWnd = CreateWindow(szWindowClass, "DGIndex", WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME|WS_MAXIMIZEBOX),
CW_USEDEFAULT, 0, INIT_WIDTH, INIT_HEIGHT, NULL, NULL, hInst, NULL);
// Test CPU
__asm
{
mov eax, 1
cpuid
test edx, 0x00800000 // STD MMX
jz TEST_SSE
mov [cpu.mmx], 1
TEST_SSE:
test edx, 0x02000000 // STD SSE
jz TEST_SSE2
mov [cpu.ssemmx], 1
mov [cpu.ssefpu], 1
TEST_SSE2:
test edx, 0x04000000 // SSE2
jz TEST_3DNOW
mov [cpu.sse2], 1
TEST_3DNOW:
mov eax, 0x80000001
cpuid
test edx, 0x80000000 // 3D NOW
jz TEST_SSEMMX
mov [cpu._3dnow], 1
TEST_SSEMMX:
test edx, 0x00400000 // SSE MMX
jz TEST_END
mov [cpu.ssemmx], 1
TEST_END:
}
if (!cpu.sse2)
{
DeleteMenu(hMenu, IDM_IDCT_SSE2MMX, 0);
}
if (!cpu.ssemmx)
{
DeleteMenu(hMenu, IDM_IDCT_SSEMMX, 0);
DeleteMenu(hMenu, IDM_IDCT_SKAL, 0);
}
if (cpu.mmx)
CheckMenuItem(hMenu, IDM_MMX, MF_CHECKED);
else
DestroyWindow(hWnd);
if (cpu.ssemmx)
CheckMenuItem(hMenu, IDM_SSEMMX, MF_CHECKED);
if (cpu.sse2)
CheckMenuItem(hMenu, IDM_SSE2, MF_CHECKED);
if (cpu._3dnow)
CheckMenuItem(hMenu, IDM_3DNOW, MF_CHECKED);
if (cpu.ssefpu)
CheckMenuItem(hMenu, IDM_SSEFPU, MF_CHECKED);
// Create control
hTrack = CreateWindow(TRACKBAR_CLASS, NULL,
WS_CHILD | WS_VISIBLE | WS_DISABLED | TBS_NOTICKS | TBS_TOP,
0, INIT_HEIGHT, INIT_WIDTH-4*TRACK_HEIGHT, TRACK_HEIGHT, hWnd, (HMENU) ID_TRACKBAR, hInst, NULL);
SendMessage(hTrack, TBM_SETRANGE, (WPARAM) true, (LPARAM) MAKELONG(0, TRACK_PITCH));
hLeftButton = CreateWindow("BUTTON", "[",
WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_DISABLED,
INIT_WIDTH-4*TRACK_HEIGHT, INIT_HEIGHT,
TRACK_HEIGHT, TRACK_HEIGHT, hWnd, (HMENU) ID_LEFT_BUTTON, hInst, NULL);
hLeftArrow = CreateWindow("BUTTON", "<",
WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_DISABLED,
INIT_WIDTH-3*TRACK_HEIGHT, INIT_HEIGHT,
TRACK_HEIGHT, TRACK_HEIGHT, hWnd, (HMENU) ID_LEFT_ARROW, hInst, NULL);
hRightArrow = CreateWindow("BUTTON", ">",
WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_DISABLED,
INIT_WIDTH-2*TRACK_HEIGHT, INIT_HEIGHT,
TRACK_HEIGHT, TRACK_HEIGHT, hWnd, (HMENU) ID_RIGHT_ARROW, hInst, NULL);
hRightButton = CreateWindow("BUTTON", "]",
WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_DISABLED,
INIT_WIDTH-TRACK_HEIGHT, INIT_HEIGHT,
TRACK_HEIGHT, TRACK_HEIGHT, hWnd, (HMENU) ID_RIGHT_BUTTON, hInst, NULL);
ResizeWindow(INIT_WIDTH, INIT_HEIGHT);
MoveWindow(hWnd, INIT_X, INIT_Y, INIT_WIDTH+Edge_Width, INIT_HEIGHT+Edge_Height+TRACK_HEIGHT+TRACK_HEIGHT/3, true);
MPEG2_Transport_VideoPID = 2;
MPEG2_Transport_AudioPID = 2;
MPEG2_Transport_PCRPID = 2;
// Command line init.
strcpy(ucCmdLine, lpCmdLine);
_strupr(ucCmdLine);
// Show window normal, minimized, or hidden as appropriate.
if (*lpCmdLine == 0)
WindowMode = SW_SHOW;
else
{
if (strstr(ucCmdLine,"-MINIMIZE"))
WindowMode = SW_MINIMIZE;
else if (strstr(ucCmdLine,"-HIDE"))
WindowMode = SW_HIDE;
else
WindowMode = SW_SHOW;
}
ShowWindow(hWnd, WindowMode);
StartupEnables();
CheckFlag();
CLIActive = 0;
// First check whether we have "Open With" invocation.
if (*lpCmdLine != 0)
{
#define OUT_OF_FILE 0
#define IN_FILE_QUOTED 1
#define IN_FILE_BARE 2
#define MAX_CMD 2048
int n, i, j, k;
FILE* tmp;
int state, ndx;
char *swp;
// MessageBox(hWnd, lpCmdLine, NULL, MB_OK);
ptr = lpCmdLine;
// Look at the first non-white-space character.
// If it is a '-' we have CLI invocation, else
// we have "Open With" invocation.
while (*ptr == ' ' && *ptr == '\t') ptr++;
if (*ptr != '-')
{
// "Open With" invocation.
NumLoadedFiles = 0;
// Pick up all the filenames.
// The command line will look like this (with the quotes!):
// "c:\my dir\file1.vob" c:\dir\file2.vob ...
// The paths with spaces have quotes; those without do not.
// This is tricky to parse, so use a state machine.
state = OUT_OF_FILE;
for (k = 0; k < MAX_CMD; k++)
{
if (state == OUT_OF_FILE)
{
if (*ptr == 0)
{
break;
}
else if (*ptr == ' ')
{
}
else if (*ptr == '"')
{
state = IN_FILE_QUOTED;
ndx = 0;
}
else
{
state = IN_FILE_BARE;
ndx = 0;
cwd[ndx++] = *ptr;
}
}
else if (state == IN_FILE_QUOTED)
{
if (*ptr == '"')
{
cwd[ndx] = 0;
if ((tmp = fopen(cwd, "rb")) != NULL)
{
// MessageBox(hWnd, "Open OK", NULL, MB_OK);
strcpy(Infilename[NumLoadedFiles], cwd);
Infile[NumLoadedFiles] = tmp;
NumLoadedFiles++;
}
state = OUT_OF_FILE;
}
else
{
cwd[ndx++] = *ptr;
}
}
else if (state == IN_FILE_BARE)
{
if (*ptr == 0)
{
cwd[ndx] = 0;
if ((tmp = fopen(cwd, "rb")) != NULL)
{
// MessageBox(hWnd, "Open OK", NULL, MB_OK);
strcpy(Infilename[NumLoadedFiles], cwd);
Infile[NumLoadedFiles] = tmp;
NumLoadedFiles++;
}
break;
}
else if (*ptr == ' ')
{
cwd[ndx] = 0;
if ((tmp = fopen(cwd, "rb")) != NULL)
{
// MessageBox(hWnd, "Open OK", NULL, MB_OK);
strcpy(Infilename[NumLoadedFiles], cwd);
Infile[NumLoadedFiles] = tmp;
NumLoadedFiles++;
}
state = OUT_OF_FILE;
}
else
{
cwd[ndx++] = *ptr;
}
}
ptr++;
}
// Sort the filenames.
n = NumLoadedFiles;
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < n - 1 - i; j++)
{
if (strverscmp(Infilename[j+1], Infilename[j]) < 0)
{
swp = Infilename[j];
Infilename[j] = Infilename[j+1];
Infilename[j+1] = swp;
tmp = Infile[j];
Infile[j] = Infile[j+1];
Infile[j+1] = tmp;
}
}
}
// Start everything up with these files.
Recovery();
RefreshWindow(true);
// Force the following CLI processing to be skipped.
*lpCmdLine = 0;
if (NumLoadedFiles)
{
// Start a LOCATE_INIT thread. When it kills itself, it will start a
// LOCATE_RIP thread by sending a WM_USER message to the main window.
process.rightfile = NumLoadedFiles-1;
process.rightlba = (int)(Infilelength[NumLoadedFiles-1]/SECTOR_SIZE);
process.end = Infiletotal - SECTOR_SIZE;
process.endfile = NumLoadedFiles - 1;
process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1)*SECTOR_SIZE;
process.locate = LOCATE_INIT;
if (!threadId || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0)
hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId);
}
}
}
if (*lpCmdLine)
{
// CLI invocation.
if (parse_cli(lpCmdLine, ucCmdLine) != 0)
exit(EXIT_FAILURE);
if (NumLoadedFiles)
{
// Start a LOCATE_INIT thread. When it kills itself, it will start a
// LOCATE_RIP thread by sending a WM_USER message to the main window.
PlaybackSpeed = SPEED_MAXIMUM;
// If the project range wasn't set with the RG option, set it to the entire timeline.
if (!hadRGoption)
{
process.rightfile = NumLoadedFiles-1;
process.rightlba = (int)(Infilelength[NumLoadedFiles-1]/SECTOR_SIZE);
process.end = Infiletotal - SECTOR_SIZE;
process.endfile = NumLoadedFiles - 1;
process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1)*SECTOR_SIZE;
}
process.locate = LOCATE_INIT;
if (!threadId || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0)
hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId);
}
}
UpdateMRUList();
// Main message loop
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(hWnd, hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
HBITMAP splash = NULL;
// Processes messages for the main window
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
DWORD wmId, wmEvent;
HDC hdc;
PAINTSTRUCT ps;
char prog[DG_MAX_PATH];
char path[DG_MAX_PATH];
char avsfile[DG_MAX_PATH];
LPTSTR path_p, prog_p;
FILE *tplate, *avs;
int i, j;
WNDCLASS rwc = {0};
switch (message)
{
case CLI_RIP_MESSAGE:
// The CLI-invoked LOCATE_INIT thread is finished.
// Kick off a LOCATE_RIP thread.
if (CLIPreview)
goto preview;
else
goto proceed;
case CLI_PREVIEW_DONE_MESSAGE:
// Destroy the Info dialog to generate the info log file.
DestroyWindow(hDlg);
if (ExitOnEnd)
exit(0);
break;
case D2V_DONE_MESSAGE:
// Make an AVS file if it doesn't already exist and a template exists.
strcpy(avsfile, D2VFilePath);
path_p = strrchr(avsfile, '.');
if (strstr(AVSTemplatePath, ".vpy") != NULL)
strcpy(++path_p, "vpy");
else
strcpy(++path_p, "avs");
if (*AVSTemplatePath && !fopen(avsfile, "r") && (tplate = fopen(AVSTemplatePath, "r")))
{
avs = fopen(avsfile, "w");
if (avs)
{
while (fgets(path, 1023, tplate))
{
path_p = path;
prog_p = prog;
while (1)
{
if (*path_p == 0)
{
*prog_p = 0;
break;
}
else if (path_p[0] == '_' && path_p[1] == '_' && path_p[2] == 'v' &&
path_p[3] == 'i' && path_p[4] == 'd' && path_p[5] == '_' && path_p[6] == '_')
{
// Replace __vid__ macro.
*prog_p = 0;
if (FullPathInFiles)
{
strcat(prog_p, D2VFilePath);
prog_p = &prog[strlen(prog)];
path_p += 7;
}
else
{
char *p;
if ((p = strrchr(D2VFilePath,'\\')) != 0) p++;
else p = D2VFilePath;
strcat(prog_p, p);
prog_p = &prog[strlen(prog)];
path_p += 7;
}
}
else if (path_p[0] == '_' && path_p[1] == '_' && path_p[2] == 'a' &&
path_p[3] == 'u' && path_p[4] == 'd' && path_p[5] == '_' && path_p[6] == '_')
{
// Replace __aud__ macro.
*prog_p = 0;
if (FullPathInFiles)
{
strcat(prog_p, AudioFilePath);
prog_p = &prog[strlen(prog)];
path_p += 7;
}
else
{
char *p;
if ((p = strrchr(AudioFilePath,'\\')) != 0) p++;
else p = AudioFilePath;
strcat(prog_p, p);
prog_p = &prog[strlen(prog)];
path_p += 7;
}
}
else if (AudioFilePath && path_p[0] == '_' && path_p[1] == '_' && path_p[2] == 'd' &&
path_p[3] == 'e' && path_p[4] == 'l' && path_p[5] == '_' && path_p[6] == '_')
{
// Replace __del__ macro.
char *d = &AudioFilePath[strlen(AudioFilePath)-3];
int delay;
float fdelay;
char fdelay_str[32];
while (d > AudioFilePath)
{
if (d[0] == 'm' && d[1] == 's' && d[2] == '.')
break;
d--;
}
if (d > AudioFilePath)
{
while ((d > AudioFilePath) && d[0] != ' ') d--;
if (d[0] == ' ')
{
sscanf(d, "%d", &delay);
fdelay = (float) 0.001 * delay;
sprintf(fdelay_str, "%.3f", fdelay);
*prog_p = 0;
strcat(prog_p, fdelay_str);
prog_p = &prog[strlen(prog)];
path_p += 7;
}
else
*prog_p++ = *path_p++;
}
else
*prog_p++ = *path_p++;
}
else
{
*prog_p++ = *path_p++;
}
}
fputs(prog, avs);
}
fclose(tplate);
fclose(avs);
}
}
if (ExitOnEnd)
{
if (Info_Flag)
DestroyWindow(hDlg);
exit(0);
}
else CLIActive = 0;
break;
case PROGRESS_MESSAGE:
OutputProgress(wParam);
break;
case WM_CREATE:
PreScale_Ratio = 1.0;
process.trackleft = 0;
process.trackright = TRACK_PITCH;
rwc.lpszClassName = TEXT("SelectControl");
rwc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
rwc.style = CS_HREDRAW;
rwc.lpfnWndProc = SelectProc;
RegisterClass(&rwc);
hwndSelect = CreateWindowEx(0, TEXT("SelectControl"), NULL,
WS_CHILD | WS_VISIBLE, 12, 108, 370, TRACK_HEIGHT/3, hWnd, NULL, NULL, NULL);
hDC = GetDC(hWnd);
hMenu = GetMenu(hWnd);
hProcess = GetCurrentProcess();
// Load the splash screen from the file dgindex.bmp if it exists.
strcpy(prog, ExePath);
strcat(prog, "dgindex.bmp");
splash = (HBITMAP) ::LoadImage (0, prog, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
// if (splash == 0)
// {
// // No splash file. Use the built-in default splash screen.
// splash = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_SPLASH));
// }
for (i=0; i<MAX_FILE_NUMBER; i++)
Infilename[i] = (char*)malloc(DG_MAX_PATH);
for (i=0; i<8; i++)
block[i] = (short *)_aligned_malloc(sizeof(short)*64, 64);
Initialize_FPU_IDCT();
// register VFAPI
HKEY key; DWORD trash;
if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\VFPlugin", 0, "",
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &trash) == ERROR_SUCCESS)
{
if (_getcwd(szBuffer, DG_MAX_PATH)!=NULL)
{
if (szBuffer[strlen(szBuffer)-1] != '\\')
strcat(szBuffer, "\\");
strcpy(szPath, szBuffer);
struct _finddata_t vfpfile;
if (_findfirst("DGVfapi.vfp", &vfpfile) != -1L)
{
strcat(szBuffer, "DGVfapi.vfp");
RegSetValueEx(key, "DGIndex", 0, REG_SZ, (LPBYTE)szBuffer, strlen(szBuffer));
CheckMenuItem(hMenu, IDM_VFAPI, MF_CHECKED);
}
RegCloseKey(key);
}
}
case WM_COMMAND:
{
int show_info;
show_info = true;
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// parse the menu selections
switch (wmId)
{
case ID_MRU_FILE0:
case ID_MRU_FILE1:
case ID_MRU_FILE2:
case ID_MRU_FILE3:
{
FILE *tmp;
NumLoadedFiles = 0;
if ((tmp = fopen(mMRUList[wmId - ID_MRU_FILE0], "rb")) != NULL)
{
strcpy(Infilename[NumLoadedFiles], mMRUList[wmId - ID_MRU_FILE0]);
Infile[NumLoadedFiles] = tmp;
NumLoadedFiles = 1;
Recovery();
MPEG2_Transport_VideoPID = 2;
MPEG2_Transport_AudioPID = 2;
MPEG2_Transport_PCRPID = 2;
RefreshWindow(true);
// Start a LOCATE_INIT thread. When it kills itself, it will start a
// LOCATE_RIP thread by sending a WM_USER message to the main window.
process.rightfile = NumLoadedFiles-1;
process.rightlba = (int)(Infilelength[NumLoadedFiles-1]/SECTOR_SIZE);
process.end = Infiletotal - SECTOR_SIZE;
process.endfile = NumLoadedFiles - 1;
process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1)*SECTOR_SIZE;
process.locate = LOCATE_INIT;
if (!threadId || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0)
hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId);
}
else
{
MessageBox(hWnd, "Cannot open the specified file", "Open file error", MB_OK | MB_ICONERROR);
DeleteMRUList(wmId - ID_MRU_FILE0);
}
break;
}
case IDM_OPEN:
if (Info_Flag)
{
DestroyWindow(hDlg);
Info_Flag = false;
}
DialogBox(hInst, (LPCTSTR)IDD_FILELIST, hWnd, (DLGPROC)VideoList);
break;
case IDM_CLOSE:
if (Info_Flag)
{
DestroyWindow(hDlg);
Info_Flag = false;
}
while (NumLoadedFiles)
{
NumLoadedFiles--;
fclose(Infile[NumLoadedFiles]);
}
Recovery();
MPEG2_Transport_VideoPID = 2;
MPEG2_Transport_AudioPID = 2;
MPEG2_Transport_PCRPID = 2;
break;
case IDM_PREVIEW_NO_INFO:
show_info = false;
wmId = IDM_PREVIEW;
goto skip;
preview:
show_info = true;
wmId = IDM_PREVIEW;
skip:
case IDM_PREVIEW:
case IDM_PLAY:
if (!Check_Flag)
{
MessageBox(hWnd, "No data. Check your PIDS.", "Preview/Play", MB_OK | MB_ICONWARNING);
}
else if (IsWindowEnabled(hTrack))
{
RunningEnables();
Display_Flag = true;
// Initialize for single stepping.
RightArrowHit = false;
if (show_info == true)
ShowInfo(true);
if (SystemStream_Flag == TRANSPORT_STREAM)
{
MPEG2_Transport_AudioType =
pat_parser.GetAudioType(Infilename[0], MPEG2_Transport_AudioPID);
}
if (wmId == IDM_PREVIEW)
process.locate = LOCATE_RIP;
else
process.locate = LOCATE_PLAY;
if (CLIPreview || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0)
hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId);
}
break;
case IDM_DEMUX_AUDIO:
if (Method_Flag == AUDIO_NONE)
{
MessageBox(hWnd, "Audio demuxing is disabled.\nEnable it first in the Audio/Output Method menu.", NULL, MB_OK | MB_ICONERROR);
break;
}
process.locate = LOCATE_DEMUX_AUDIO;
RunningEnables();
ShowInfo(true);
if (CLIActive || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0)
{
hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId);
}
break;
case IDM_SAVE_D2V_AND_DEMUX:
MuxFile = (FILE *) 0;
goto proceed;
case IDM_SAVE_D2V:
// No video demux.
MuxFile = (FILE *) 0xffffffff;
proceed:
if (!Check_Flag)
{
MessageBox(hWnd, "No data. Check your PIDS.", "Save Project", MB_OK | MB_ICONWARNING);
break;
}
if (!CLIActive && (FO_Flag == FO_FILM) && ((mpeg_type == IS_MPEG1) || ((int) (frame_rate * 1000) != 29970)))
{
char buf[255];
sprintf(buf, "It is almost always wrong to run Force Film on an MPEG1 stream,\n"
"or a stream with a frame rate other than 29.970.\n"
"Your stream is %s and has a frame rate of %.3f.\n"
"Do you want to do it anyway?",
mpeg_type == IS_MPEG1 ? "MPEG1" : "MPEG2", frame_rate);
if (MessageBox(hWnd, buf, "Force Film Warning", MB_YESNO | MB_ICONWARNING) != IDYES)
break;
}