-
Notifications
You must be signed in to change notification settings - Fork 79
/
DLCPackageCreator.cs
2459 lines (2158 loc) · 102 KB
/
DLCPackageCreator.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using Ookii.Dialogs;
using RocksmithToolkitGUI.DDC;
using RocksmithToolkitLib.DLCPackage.Manifest.Functions;
using RocksmithToolkitLib.DLCPackage.Manifest2014.Tone;
using RocksmithToolkitLib.XmlRepository;
using X360.STFS;
using RocksmithToolkitLib;
using RocksmithToolkitLib.DLCPackage;
using RocksmithToolkitLib.DLCPackage.Manifest.Tone;
using RocksmithToolkitLib.Extensions;
using RocksmithToolkitLib.Ogg;
using RocksmithToolkitLib.Sng;
using RocksmithToolkitLib.Xml;
using Control = System.Windows.Forms.Control;
using ProgressBarStyle = System.Windows.Forms.ProgressBarStyle;
using RocksmithToolkitGUI.Config;
namespace RocksmithToolkitGUI.DLCPackageCreator
{
public partial class DLCPackageCreator : UserControl
{
public static readonly string MESSAGEBOX_CAPTION = "CDLC Package Creator";
private const string TKI_REMASTER = "(Remastered by CDLC Creator)";
private const string TKI_ARRID = "(Arrangement ID by CDLC Creator)";
private const string TKI_DDC = "(DDC by CDLC Creator)";
private BackgroundWorker bwGenerate = new BackgroundWorker();
private StringBuilder errorsFound;
private string dlcSavePath;
private bool userChangedInputControls;
// prevents multiple tool tip appearance and gives better action
private ToolTip tt = new ToolTip();
private string dlcKeyOrg; // used to preserve original
#region Properties
public GameVersion CurrentGameVersion
{
get
{
if (rbRs2014.Checked)
return GameVersion.RS2014;
if (rbRs2012.Checked)
return GameVersion.RS2012;
if (rbConvert.Checked)
return GameVersion.None;
throw new InvalidDataException("Game version is missing or is not selected.");
}
set
{
switch (value)
{
case GameVersion.RS2014:
rbRs2014.Checked = true;
break;
case GameVersion.RS2012:
rbRs2012.Checked = true;
break;
case GameVersion.None:
rbConvert.Checked = true;
break;
}
}
}
private string CurrentOFDAudioFileFilter
{
get
{
switch (CurrentGameVersion)
{
case GameVersion.None:
case GameVersion.RS2014:
// TODO: Test WEM generations with non-PC Platforms
if (platformMAC.Checked == platformPS3.Checked == platformXBox360.Checked == false)
return "All Supported Files|*.wem;*.ogg;*.wav|Wwise 2013 audio files (*.wem)|*.wem|Ogg Vorbis audio files (*.ogg)|*.ogg|Wave audio files (*.wav)|*.wav";
return "Wwise 2013 audio files (*.wem)|*.wem";
default:
return "Wwise 2010 audio files (*.ogg)|*.ogg";
}
}
}
private string CurrentOFDToneImportFilter
{
get
{
var filter = CurrentOFDPackageFilter + "|";
filter += CurrentRocksmithTitle + " Song Manifest (*.json)|*.json";
if (rbRs2012.Checked)
filter += "|Rocksmith 2012 Game Save Profile (*_profile)|*_profile";
else
filter += "|Rocksmith 2014 Game Save Profile (*_prfldb)|*_prfldb";
return filter;
}
}
public string CurrentOFDPackageFilter
{
get
{
string filter;
switch (CurrentGameVersion)
{
// case GameVersion.None:
case GameVersion.RS2014:
filter = CurrentRocksmithTitle + " PC/Mac Package (*.psarc)|*.psarc|";
filter += CurrentRocksmithTitle + " XBox360 Package (*.*)|*.*|";
filter += CurrentRocksmithTitle + " PS3 Package (*.edat)|*.edat";
break;
default:
filter = CurrentRocksmithTitle + " PC/Mac Package (*.dat)|*.dat|";
filter += CurrentRocksmithTitle + " XBox360 Package (*.*)|*.*";
break;
}
return filter;
}
}
private string CurrentRocksmithTitle
{
get
{
switch (CurrentGameVersion)
{
case GameVersion.None:
case GameVersion.RS2014:
return "Rocksmith 2014";
default:
return "Rocksmith";
}
}
}
//Song Information
public string DLCKey // appears to be interchageble with SongKey
{
get { return DlcKeyTB.Text; }
set { DlcKeyTB.Text = value.GetValidKey(); }
}
public string SongTitle
{
get { return SongDisplayNameTB.Text; }
set { SongDisplayNameTB.Text = value.GetValidAtaSpaceName(); }
}
public string SongTitleSort
{
get { return SongDisplayNameSortTB.Text; }
set { SongDisplayNameSortTB.Text = String.IsNullOrEmpty(value) ? SongTitle.GetValidSortableName() : value.GetValidSortableName(); }
}
public string Album
{
get { return AlbumTB.Text; }
set { AlbumTB.Text = value.GetValidAtaSpaceName(); }
}
public string AlbumSort
{
get { return AlbumSortTB.Text; }
set { AlbumSortTB.Text = String.IsNullOrEmpty(value) ? Album.GetValidSortableName() : value.GetValidSortableName(); }
}
public string Artist
{
get { return ArtistTB.Text; }
set { ArtistTB.Text = value.GetValidAtaSpaceName(); }
}
public string ArtistSort
{
get { return ArtistSortTB.Text; }
set { ArtistSortTB.Text = String.IsNullOrEmpty(value) ? Artist.GetValidSortableName() : value.GetValidSortableName(); }
}
public string AlbumYear
{
get { return YearTB.Text; }
set { YearTB.Text = value.GetValidYear(); }
}
public string AppId
{
get { return AppIdTB.Text; }
set { AppIdTB.Text = value.GetValidAppIdSixDigits(); }
}
public string AverageTempo
{
get { return AverageTempoTB.Text; }
set
{ AverageTempoTB.Text = value.GetValidTempo(); }
}
public string PackageVersion
{
get { return packageVersionTB.Text; }
set { packageVersionTB.Text = String.IsNullOrEmpty(value) ? "1" : value.GetValidVersion(); }
}
private string packageComment;
public string PackageComment
{
get
{
// add any ToolkitInfo comment here
if (String.IsNullOrEmpty(packageComment))
return TKI_REMASTER;
if (!packageComment.Contains("Remastered"))
return packageComment + " " + TKI_REMASTER;
return packageComment;
}
set { packageComment = value; }
}
//Tones
private IEnumerable<string> GetToneNames()
{
if (CurrentGameVersion != GameVersion.RS2012)
return tonesLB.Items.OfType<Tone2014>().Select(t => t.Name);
return tonesLB.Items.OfType<Tone>().Select(t => t.Name);
}
//Files
private string AlbumArtPath // 512 (RS1)
{
get { return albumArtPathTB.Text; }
set { albumArtPathTB.Text = value; }
}
private string AudioPath
{
get { return audioPathTB.Text; }
set { audioPathTB.Text = value; }
}
public string LyricArtPath { get; set; }
public bool JavaBool { get; set; }
#endregion
public DLCPackageCreator()
{
InitializeComponent();
#if (!DEBUG)
chkShowlights.Visible = false;
btnDevUseOnly.Visible = false;
#endif
arrangementLB.AllowDrop = true;
//FIXME: new tooltips pls!
//audioQualityBox.MouseEnter += audioQualityBox_MouseEnter;
rbConvert.MouseEnter += rbConvert_MouseEnter;
songVolumeBox.MouseEnter += songVolumeBox_MouseEnter;
previewVolumeBox.MouseEnter += songVolumeBox_MouseEnter;
rbRs2012.MouseUp += GameVersion_MouseUp;
rbRs2014.MouseUp += GameVersion_MouseUp;
rbConvert.MouseUp += GameVersion_MouseUp;
AddValidationEventHandlers();
try
{
// this sequence gets done everytime config changes
SetDefaultFromConfig();
PopulateAppIdCombo();
PopulateTonesLB();
}
catch
{
/*For mono compatibility*/
}
// Generate package worker
bwGenerate.DoWork += GeneratePackage;
bwGenerate.ProgressChanged += ProgressChanged;
bwGenerate.RunWorkerCompleted += ProcessCompleted;
bwGenerate.WorkerReportsProgress = true;
}
private void SetDefaultFromConfig()
{
// read from RocksmithToolkitLib.Config.xml
try
{
Globals.DefaultProjectDir = ConfigRepository.Instance()["creator_defaultproject"];
Globals.DefaultToneFile = ConfigRepository.Instance()["creator_defaulttone"];
CurrentGameVersion = (GameVersion)Enum.Parse(typeof(GameVersion), ConfigRepository.Instance()["general_defaultgameversion"]);
var defaultPlatform = (GamePlatform)Enum.Parse(typeof(GamePlatform), ConfigRepository.Instance()["general_defaultplatform"]);
switch (defaultPlatform)
{
case GamePlatform.Pc:
platformPC.Checked = true;
break;
case GamePlatform.Mac:
platformMAC.Checked = true;
break;
case GamePlatform.XBox360:
platformXBox360.Checked = true;
break;
case GamePlatform.PS3:
platformPS3.Checked = true;
break;
}
}
catch (Exception)
{
throw new FileLoadException("RocksmithToolkitLib.Config.xml is corrupt. Please reload fresh installation.");
}
}
public dynamic CreateNewTone(string toneName = "Default")
{
var name = GetUniqueToneName(toneName);
if (CurrentGameVersion != GameVersion.RS2012)
return new Tone2014() { Name = name, Key = name };
return new Tone { Name = name, Key = name };
}
private string GetUniqueToneName(string toneName)
{
var uniqueName = toneName;
bool isUnique = false;
int ind = 1;
do
{
switch (CurrentGameVersion)
{
case GameVersion.RS2012:
isUnique = tonesLB.Items.OfType<Tone>().All(n => n.Name != uniqueName);
break;
case GameVersion.None:
case GameVersion.RS2014:
isUnique = tonesLB.Items.OfType<Tone2014>().All(n => n.Name != uniqueName);
break;
}
if (!isUnique)
{
uniqueName = toneName + (++ind);
}
} while (!isUnique);
return uniqueName;
}
private void ArrangementLB_MouseDoubleClick(object sender, MouseEventArgs e)
{
arrangementEditButton_Click(sender, e);
}
private void arrangementEditButton_Click(object sender, EventArgs e)
{
if (arrangementLB.SelectedItem != null)
{
var arrangement = (Arrangement)arrangementLB.SelectedItem;
using (var form = new ArrangementForm(arrangement, this, CurrentGameVersion) { Text = "Edit Arrangement" })
{
form.EditMode = true;
if (DialogResult.OK != form.ShowDialog())
{
return;
}
}
arrangementLB.Items[arrangementLB.SelectedIndex] = arrangement;
}
}
public void arrangementAddButton_Click(object sender = null, EventArgs e = null)
{
Arrangement arrangement = null;
using (var form = new ArrangementForm(this, CurrentGameVersion))
{
form.EditMode = false;
if (DialogResult.OK == form.ShowDialog())
arrangement = form.Arrangement;
}
if (arrangement == null)
return;
arrangementLB.Items.Add(arrangement);
}
private void arrangementRemoveButton_Click(object sender, EventArgs e)
{
if (arrangementLB.SelectedItem == null)
return;
if (MessageBox.Show("Are you sure to delete the selected arrangement?", MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
return;
//FIXME: bad thing happens here.
/*/ regenerate new showlights arrangement
if (arrangementLB.SelectedItem.ToString().ToLower().Contains("showlight"))
{
var packageData = GetPackageData();
foreach (var arr in packageData.Arrangements)
if (arr.ArrangementType == ArrangementType.ShowLight)
{
File.Delete(arr.SongXml.File);
arr.SongXml.File = null; // forces regeneration of shl
}
}*/
arrangementLB.Items.Remove(arrangementLB.SelectedItem);
}
//TODO: allow to choose audio for each arrangement separately. #Lessons, #Multitracks
private void openAudioButton_Click(object sender, EventArgs e)
{
using (var ofd = new OpenFileDialog())
{
ofd.Filter = CurrentOFDAudioFileFilter;
if (ofd.ShowDialog() == DialogResult.OK)
AudioPath = ofd.FileName;
}
}
public void dlcGenerateButton_Click(object sender = null, EventArgs e = null)
{
var packageData = GetPackageData();
if (packageData == null || String.IsNullOrEmpty(DlcKeyTB.Text))
{
MessageBox.Show("One or more fields are missing information.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var playableArrCount = packageData.Arrangements.Count(arr => arr.ArrangementType == ArrangementType.Guitar || arr.ArrangementType == ArrangementType.Bass);
if (playableArrCount > 5) // may crash RS14R
{
var errMsg = "This CDLC will likely crash if it is played in Rocksmith 2014 Remastered." + Environment.NewLine + "The combined number of guitar and bass arrangements" + Environment.NewLine + "(including bonus arrangements) is " + playableArrCount + ", which exceeds the limit of 5." + Environment.NewLine + Environment.NewLine + "Do you still want to package this CDLC?";
if (MessageBox.Show(errMsg, MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No)
return;
}
// check if ANY arrangment has pre existing DD
var isDD = false;
foreach (var arr in packageData.Arrangements)
{
// skip vocal and showlight arrangements
if (arr.ArrangementType == ArrangementType.Vocal || arr.ArrangementType == ArrangementType.ShowLight)
continue;
var songXml = Song2014.LoadFromFile(arr.SongXml.File);
var mf = new ManifestFunctions(GameVersion.RS2014);
if (mf.GetMaxDifficulty(songXml) != 0)
{
isDD = true;
break;
}
}
using (var sfd = new SaveFileDialog())
{
var versionPrefix = String.Empty;
switch (CurrentGameVersion)
{
case GameVersion.RS2012:
versionPrefix = "r"; // RS2012 CDLC
break;
case GameVersion.None:
versionPrefix = "c"; // Converted RS1 CDLC
break;
default:
versionPrefix = "v"; // RS2014 CDLC
break;
}
var packageVersion = String.Format("{0}{1}", versionPrefix, PackageVersion.Replace(".", "_"));
var ddAcronym = ConfigRepository.Instance().GetBoolean("ddc_autogen") || isDD ? "DD" : "NDD";
var fileName = String.Format("{0}_{1}", StringExtensions.GetValidShortFileName(ArtistSort, SongTitleSort, packageVersion, ConfigRepository.Instance().GetBoolean("creator_useacronyms")), ddAcronym);
sfd.FileName = fileName.GetValidFileName();
sfd.Filter = CurrentRocksmithTitle + " CDLC (*.*)|*.*";
if (sfd.ShowDialog(this) != DialogResult.OK) // 'this' ensures sfd is topmost
return;
dlcSavePath = sfd.FileName;
}
// showlights cause in game hanging for some RS1-RS2 conversions
// can be disabled here by devs if required
packageData.Showlights = chkShowlights.Checked;
//Generate metronome arrangements here
var mArr = new List<Arrangement>();
foreach (var arr in packageData.Arrangements)
{
if (arr.Metronome == Metronome.Generate)
mArr.Add(GenMetronomeArr(arr));
}
packageData.Arrangements.AddRange(mArr);
// Update XML arrangements song info
bool updateArrangmentID = false;
if (userChangedInputControls)
{
if (MessageBox.Show(@"The song information has been changed." + Environment.NewLine + @"Do you want to update the 'Arrangement Identification'? " + Environment.NewLine + @"Answering 'Yes' will reduce the risk of CDLC" + Environment.NewLine + @"in game hanging and song stats will be reset.", MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
updateArrangmentID = true;
// add TKI_ARRID comment
var arrIdComment = packageData.ToolkitInfo.PackageComment;
if (String.IsNullOrEmpty(arrIdComment))
arrIdComment = TKI_ARRID;
else if (!arrIdComment.Contains(TKI_ARRID))
arrIdComment = arrIdComment + " " + TKI_ARRID;
packageData.ToolkitInfo.PackageComment = arrIdComment;
}
else
// maintain use of original DLCKey, as well as, PID
packageData.Name = dlcKeyOrg;
}
// fire up a fake progress bar to show app is alive and well
var step = (int)Math.Round(1.0 / playableArrCount * 100, 0);
var progress = 0;
pbUpdateProgress.Visible = true;
lblCurrentOperation.Visible = true;
dlcGenerateButton.Enabled = false;
pbUpdateProgress.Style = ProgressBarStyle.Continuous;
progress += step;
pbUpdateProgress.Value = (progress > 100 ? 100 : progress);
ShowCurrentOperation("Updating package data ...");
if (ConfigRepository.Instance().GetBoolean("ddc_autogen"))
{
// add TKI_DDC comment
var ddcComment = packageData.ToolkitInfo.PackageComment;
if (String.IsNullOrEmpty(ddcComment))
ddcComment = TKI_DDC;
else if (!ddcComment.Contains(TKI_DDC))
ddcComment = ddcComment + " " + TKI_DDC;
packageData.ToolkitInfo.PackageComment = ddcComment;
}
// add TKI_REMASTER comment
var remasterComment = packageData.ToolkitInfo.PackageComment;
if (String.IsNullOrEmpty(remasterComment))
remasterComment = TKI_REMASTER;
else if (!remasterComment.Contains(TKI_REMASTER))
remasterComment = remasterComment + " " + TKI_REMASTER;
packageData.ToolkitInfo.PackageComment = remasterComment;
// declare one time for DDC generation
var consoleOutput = String.Empty;
SettingsDDC.Instance.LoadConfigXml();
var phraseLen = SettingsDDC.Instance.PhraseLen;
// removeSus may be depricated in latest DDC but left here for comptiblity
var removeSus = SettingsDDC.Instance.RemoveSus;
var rampPath = SettingsDDC.Instance.RampPath;
var cfgPath = SettingsDDC.Instance.CfgPath;
foreach (var arr in packageData.Arrangements)
{
if (updateArrangmentID)
{
// generate new AggregateGraph
arr.SongFile = new RocksmithToolkitLib.DLCPackage.AggregateGraph.SongFile() { File = "" };
// generate new Arrangement IDs
arr.Id = IdGenerator.Guid();
arr.MasterId = RandomGenerator.NextInt();
}
// skip vocal and showlight arrangements
if (arr.ArrangementType == ArrangementType.Vocal || arr.ArrangementType == ArrangementType.ShowLight)
continue;
progress += step;
pbUpdateProgress.Value = (progress > 100 ? 100 : progress);
if (userChangedInputControls)
UpdateSongXml(arr, packageData);
// restore arrangement comments
Song2014.WriteXmlComments(arr.SongXml.File, arr.XmlComments);
// add DDC to arrangement
if (ConfigRepository.Instance().GetBoolean("ddc_autogen"))
{
// Important ... don't overwrite author's DD if it is already present in any arragement
if (!isDD)
{
using (var ddc = new DDC.DDC())
{
// apply DD to xml arrangments
var singleResult = ddc.ApplyDD(arr.SongXml.File, phraseLen, removeSus, rampPath, cfgPath, out consoleOutput, true);
if (singleResult == 1)
{
var errMsg = "DDC generated an error while processing arrangement:" + Environment.NewLine + arr.SongXml.File + Environment.NewLine;
BetterDialog2.ShowDialog(errMsg, "DDC Generated Error", null, null, "Ok", Bitmap.FromHicon(SystemIcons.Error.Handle), "Error", 150, 150);
}
if (singleResult == 2)
{
consoleOutput = String.Format("Arrangement file '{0}' => {1}", Path.GetFileNameWithoutExtension(arr.SongXml.File), consoleOutput);
BetterDialog2.ShowDialog(consoleOutput, "DDC Generation Info", null, null, "Ok", Bitmap.FromHicon(SystemIcons.Error.Handle), "Error", 150, 150);
}
}
}
else
{
// commented out ... don't nag user with this message
// MessageBox.Show("Existing DD content in arrangement: " + arr.Name + " was not changed", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
Debug.WriteLine("Existing DD content in arrangement: " + arr.Name + " was not changed");
}
}
// put arrangment comments in correct order
Song2014.WriteXmlComments(arr.SongXml.File);
}
if (Path.GetFileName(dlcSavePath).Contains(" ") && platformPS3.Checked)
{
if (!ConfigRepository.Instance().GetBoolean("creator_ps3pkgnamewarn"))
MessageBox.Show(String.Format("PS3 package name can't support space character due to encryption limitation. {0} Spaces will be automatic removed for your PS3 package name.", Environment.NewLine), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
ConfigRepository.Instance()["creator_ps3pkgnamewarn"] = true.ToString();
}
if (!bwGenerate.IsBusy && packageData != null)
{
pbUpdateProgress.Style = ProgressBarStyle.Marquee;
pbUpdateProgress.Visible = true;
lblCurrentOperation.Visible = true;
dlcGenerateButton.Enabled = false;
bwGenerate.RunWorkerAsync(packageData);
}
}
private void GeneratePackage(object sender, DoWorkEventArgs e)
{
var currentGameVersion = (CurrentGameVersion == GameVersion.RS2012) ? GameVersion.RS2012 : GameVersion.RS2014;
var packageData = e.Argument as DLCPackageData;
errorsFound = new StringBuilder();
var numPlatforms = 0;
if (platformPC.Checked)
numPlatforms++;
if (platformMAC.Checked)
numPlatforms++;
if (platformXBox360.Checked)
numPlatforms++;
if (platformPS3.Checked)
numPlatforms++;
var step = (int)Math.Round(1.0 / numPlatforms * 100, 0);
int progress = 0;
if (platformPC.Checked)
try
{
bwGenerate.ReportProgress(progress, "Generating PC Package ...");
RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(dlcSavePath, packageData, new Platform(GamePlatform.Pc, currentGameVersion), pnum: numPlatforms);
progress += step;
numPlatforms--;
bwGenerate.ReportProgress(progress);
}
catch (Exception ex)
{
errorsFound.AppendLine(String.Format("Error generate PC package: {0}{1}{0}{2}{0}", Environment.NewLine, ex.Message, ex.StackTrace));
}
if (platformMAC.Checked)
try
{
bwGenerate.ReportProgress(progress, "Generating Mac Package ...");
RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(dlcSavePath, packageData, new Platform(GamePlatform.Mac, currentGameVersion), pnum: numPlatforms);
progress += step;
numPlatforms--;
bwGenerate.ReportProgress(progress);
}
catch (Exception ex)
{
errorsFound.AppendLine(String.Format("Error generate Mac package: {0}{1}{0}{2}{0}", Environment.NewLine, ex.Message, ex.StackTrace));
}
if (platformXBox360.Checked)
try
{
bwGenerate.ReportProgress(progress, "Generating XBox 360 Package ...");
RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(dlcSavePath, packageData, new Platform(GamePlatform.XBox360, currentGameVersion), pnum: numPlatforms);
progress += step;
numPlatforms--;
bwGenerate.ReportProgress(progress);
}
catch (Exception ex)
{
errorsFound.AppendLine(String.Format("Error generate XBox 360 package: {0}{1}{0}{2}{0}", Environment.NewLine, ex.Message, ex.StackTrace));
}
if (platformPS3.Checked)
try
{
bwGenerate.ReportProgress(progress, "Generating PS3 Package ...");
RocksmithToolkitLib.DLCPackage.DLCPackageCreator.Generate(dlcSavePath, packageData, new Platform(GamePlatform.PS3, currentGameVersion), pnum: numPlatforms);
progress += step;
numPlatforms--;
bwGenerate.ReportProgress(progress);
}
catch (Exception ex)
{
errorsFound.AppendLine(String.Format("Error generate PS3 package: {0}{1}. {0}PS3 package require 'JAVA x86' (32 bits) installed on your machine to generate properly.{0}", Environment.NewLine, ex.StackTrace));
}
// Cache cleanup so we don't serialize or reuse data that could be changed
packageData.CleanCache();
e.Result = (numPlatforms == 1 && errorsFound.Length > 0) ? "error" : "generate";
}
private void albumArtButton_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(DlcKeyTB.Text))
{
MessageBox.Show("Fill the 'CDLC Name' field first.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
DlcKeyTB.Focus();
return;
}
using (var ofd = new OpenFileDialog())
{
ofd.Filter = "Album Art File (*.bmp,*.dds,*.gif,*.jpg,*.jpeg,*.png)|*.bmp;*.dds;*.gif;*.jpg;*.jpeg;*.png";
if (ofd.ShowDialog() == DialogResult.OK)
{
if (ofd.FileName.IsValidImage())
AlbumArtPath = ofd.FileName;
else
MessageBox.Show("The selected image is not valid or not supported." + Environment.NewLine + "MimeType doesn't match with file extension!", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
private void dlcSaveButton_Click(object sender, EventArgs e)
{
SaveTemplateFile();
}
public void SaveTemplateFile(string defaultSavePath = null)
{
//var arrangements = arrangementLB.Items.OfType<Arrangement>().ToList();
var packageData = GetPackageData();
if (packageData == null)
{
MessageBox.Show("One or more fields are missing information.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string fileName = StringExtensions.GetValidShortFileName(ArtistSort, SongTitleSort, CurrentGameVersion.ToString(), ConfigRepository.Instance().GetBoolean("creator_useacronyms"));
if (!String.IsNullOrEmpty(defaultSavePath))
{
dlcSavePath = Path.Combine(defaultSavePath, fileName + ".dlc.xml");
}
else
{
using (var ofd = new SaveFileDialog())
{
ofd.SupportMultiDottedExtensions = true;
ofd.Filter = CurrentRocksmithTitle + " CDLC Template (*.dlc.xml)|*.dlc.xml";
ofd.FileName = fileName.GetValidFileName();
if (DialogResult.OK != ofd.ShowDialog()) return;
dlcSavePath = ofd.FileName;
}
}
//Make the paths relative
var BasePath = Path.GetDirectoryName(dlcSavePath);
if (!string.IsNullOrEmpty(packageData.AlbumArtPath))
packageData.AlbumArtPath = packageData.AlbumArtPath.RelativeTo(BasePath);
string audioPath = packageData.OggPath;
string audioPreviewPath = packageData.OggPreviewPath;
if (!String.IsNullOrEmpty(audioPath))
packageData.OggPath = audioPath.RelativeTo(BasePath);
if (!String.IsNullOrEmpty(audioPreviewPath))
packageData.OggPreviewPath = audioPreviewPath.RelativeTo(BasePath);
if (!String.IsNullOrEmpty(packageData.LyricArtPath))
packageData.LyricArtPath = packageData.LyricArtPath.RelativeTo(BasePath);
foreach (var arr in packageData.Arrangements)
{
if (String.IsNullOrEmpty(arr.SongXml.File))
continue;
arr.SongXml.File = arr.SongXml.File.RelativeTo(BasePath);
arr.SongFile.File = "";
if (!String.IsNullOrEmpty(arr.FontSng))
arr.FontSng = arr.FontSng.RelativeTo(BasePath);
}
try
{
using (
var stm = XmlWriter.Create(dlcSavePath,
new XmlWriterSettings { CheckCharacters = true, Indent = true }))
{
new DataContractSerializer(typeof(DLCPackageData)).WriteObject(stm, packageData);
}
}
catch
{
//Re-absolutize the paths
foreach (var arr in packageData.Arrangements)
{
if (!String.IsNullOrEmpty(arr.SongXml.File))
arr.SongXml.File = arr.SongXml.File.AbsoluteTo(BasePath);
if (!String.IsNullOrEmpty(arr.SongFile.File))
arr.SongFile.File = arr.SongFile.File.AbsoluteTo(BasePath);
if (!String.IsNullOrEmpty(arr.FontSng))
arr.FontSng = arr.FontSng.AbsoluteTo(BasePath);
}
if (!String.IsNullOrEmpty(packageData.LyricArtPath))
packageData.LyricArtPath = packageData.LyricArtPath.AbsoluteTo(BasePath);
}
//Re-absolutize the paths
foreach (var arr in packageData.Arrangements)
{
if (!String.IsNullOrEmpty(arr.SongXml.File))
arr.SongXml.File = arr.SongXml.File.AbsoluteTo(BasePath);
if (!String.IsNullOrEmpty(arr.SongFile.File))
arr.SongFile.File = arr.SongFile.File.AbsoluteTo(BasePath);
if (!String.IsNullOrEmpty(arr.FontSng))
arr.FontSng = arr.FontSng.AbsoluteTo(BasePath);
}
if (!String.IsNullOrEmpty(packageData.LyricArtPath))
packageData.LyricArtPath = packageData.LyricArtPath.AbsoluteTo(BasePath);
if (String.IsNullOrEmpty(defaultSavePath)) //if in GUI mode.
MessageBox.Show(CurrentRocksmithTitle + " CDLC Package template was saved.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public void dlcLoadButton_Click(object sender = null, EventArgs e = null)
{
//TODO: issue with gameversion
string dlcLoadPath;
using (var ofd = new OpenFileDialog())
{
ofd.InitialDirectory = Globals.DefaultProjectDir;
ofd.SupportMultiDottedExtensions = true;
ofd.Filter = CurrentRocksmithTitle + " CDLC Template (*.dlc.xml)|*.dlc.xml";
if (ofd.ShowDialog() != DialogResult.OK)
return;
dlcLoadPath = Globals.DefaultProjectDir = ofd.FileName;
}
LoadTemplate(dlcLoadPath);
}
public void LoadTemplate(string dlcLoadPath)
{
DLCPackageData info = null;
try
{
if (rbRs2014.Checked)
{
// check and fix the template compatibility if necessary
var templateString = File.ReadAllText(dlcLoadPath);
if (templateString.Contains("Manifest.Tone\">"))
{
templateString = templateString.Replace("Manifest.Tone\">", "Manifest2014.Tone\">");
File.WriteAllText(dlcLoadPath, templateString, Encoding.UTF8);
}
}
using (var stm = new XmlTextReader(dlcLoadPath))
info = new DataContractSerializer(typeof(DLCPackageData)).ReadObject(stm) as DLCPackageData;
if (info == null) throw new InvalidDataException("CDLC Template is null");
// use AppId to determine GameVersion of dlc.xml template
rbRs2012.Checked = (Convert.ToInt32(info.AppId) < 230000);
rbRs2014.Checked = (Convert.ToInt32(info.AppId) > 240000);
}
catch (Exception se)
{
MessageBox.Show("Can not load CDLC Template. \n" + se.Message, MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
FillPackageCreatorForm(info, dlcLoadPath);
Application.DoEvents();
MessageBox.Show(CurrentRocksmithTitle + " CDLC Template was loaded.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
Parent.Focus();
}
public void dlcImportButton_Click(object sender = null, EventArgs e = null)
{
string sourcePackage;
string savePath;
string tmp = Path.GetTempPath();
// GET PATH
using (var ofd = new OpenFileDialog())
{
ofd.Title = "Select a CDLC to import";
ofd.Filter = CurrentOFDPackageFilter;
if (ofd.ShowDialog() != DialogResult.OK)
return;
sourcePackage = ofd.FileName;
}
if (CurrentGameVersion == GameVersion.RS2014)
if (!sourcePackage.IsValidPSARC())
{
MessageBox.Show(String.Format("Invalid File Exception: File '{0}' can not be used by current process.", Path.GetFileName(sourcePackage)), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
using (var fbd = new VistaFolderBrowserDialog())
{
fbd.Description = "Select folder to save project artifacts";
fbd.UseDescriptionForTitle = true;
fbd.SelectedPath = Path.GetDirectoryName(sourcePackage) + Path.DirectorySeparatorChar;
if (fbd.ShowDialog() != DialogResult.OK)
return;
savePath = fbd.SelectedPath;
}
GlobalExtension.UpdateProgress = pbUpdateProgress;
GlobalExtension.UpdateProgress.Style = ProgressBarStyle.Continuous;
GlobalExtension.CurrentOperationLabel = lblCurrentOperation;
Thread.Sleep(100); // give Globals a chance to initialize
Application.DoEvents();
// UNPACK
var packagePlatform = sourcePackage.GetPlatform();
var unpackedDir = Packer.Unpack(sourcePackage, tmp, true);
savePath = Path.Combine(savePath, Path.GetFileNameWithoutExtension(sourcePackage));
// Same name xbox issue fix
if (packagePlatform.platform == GamePlatform.XBox360)
savePath = String.Format("{0}_{1}", savePath, GamePlatform.XBox360.ToString());
DirectoryExtension.Move(unpackedDir, savePath, true);
unpackedDir = savePath;
// REORGANIZE
var structured = ConfigRepository.Instance().GetBoolean("creator_structured");
if (structured && CurrentGameVersion == GameVersion.RS2014)
unpackedDir = DLCPackageData.DoLikeProject(savePath);
// LOAD DATA
DLCPackageData info = null; // DLCPackageData specific to RS2
if (CurrentGameVersion == GameVersion.RS2014)
info = DLCPackageData.LoadFromFolder(unpackedDir, packagePlatform, packagePlatform, chkIgnoreMultitoneEx.Checked);
else
info = DLCPackageData.RS1LoadFromFolder(unpackedDir, packagePlatform, rbConvert.Checked);
GlobalExtension.ShowProgress("Reorganized and Loaded ...", 75);
switch (packagePlatform.platform)
{
case GamePlatform.Pc:
info.Pc = true;
break;
case GamePlatform.Mac:
info.Mac = true;
break;
case GamePlatform.XBox360:
info.XBox360 = true;
break;
case GamePlatform.PS3:
info.PS3 = true;
break;
}
// FILL PACKAGE CREATOR FORM