-
Notifications
You must be signed in to change notification settings - Fork 80
/
DLCPackageCreator.cs
2941 lines (2550 loc) · 127 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.Data;
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;
using RocksmithToolkitLib.Conversion;
using Newtonsoft.Json;
using Formatting = Newtonsoft.Json.Formatting;
using RocksmithToolkitLib.ToolkitTone;
using MakePedalSetting = RocksmithToolkitLib.ToolkitTone.ToolkitPedal;
namespace RocksmithToolkitGUI.DLCPackageCreator
{
public partial class DLCPackageCreator : UserControl
{
#region Constants
private const string TKI_ARRID = "(Arrangement ID by CDLC Creator)";
private const string TKI_REMASTER = "(Remastered by CDLC Creator)";
private const string TKI_DDC = "(DDC by CDLC Creator)"; // used to identify config condition
private const string TKI_RS1 = "(RS1 by CDLC Creator)";
#endregion
public static readonly string MESSAGEBOX_CAPTION = "CDLC Package Creator";
private BackgroundWorker bwGenerate = new BackgroundWorker();
private StringBuilder errorsFound;
private bool fixLowBass;
private bool fixMultiTone;
private string packageComment;
// prevents multiple tool tip appearance and gives better action
private ToolTip tt = new ToolTip();
public DLCPackageCreator()
{
InitializeComponent();
// it is better to be hidden initially and then unhide when needed
if (GeneralExtension.IsInDesignMode)
btnDevUse.Visible = true;
lstArrangements.AllowDrop = true;
numAudioQuality.MouseEnter += AudioQuality_MouseEnter;
rbConvert.MouseEnter += rbConvert_MouseEnter;
rbRs2014.MouseEnter += rbRs2014_MouseEnter;
numVolSong.MouseEnter += Volume_MouseEnter;
numVolPreview.MouseEnter += Volume_MouseEnter;
// using MouseUp event may result in known VS double clicking glitch
// when one control is over another control and the topmost
// control is double clicked then the background control can
// inadvertantly intercept the second click as a MouseUp event
// in this case it clears the GUI and produces undesired results
rbRs2012.MouseClick += GameVersion_MouseClick;
rbRs2014.MouseClick += GameVersion_MouseClick;
rbConvert.MouseClick += GameVersion_MouseClick;
gbGameVersion.MouseEnter += GameVersion_MouseEnter;
// Generate package worker
bwGenerate.DoWork += new DoWorkEventHandler(GeneratePackage);
bwGenerate.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged);
bwGenerate.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ProcessCompleted);
bwGenerate.WorkerReportsProgress = true;
AddValidationEventHandlers();
// this sequence gets done everytime config changes
try
{
ReadConfigSettings();
PopulateAppIdCombo();
PopulateTonesLB();
}
catch
{
/*For mono compatibility*/
}
}
//dirty implementation, it's always true, consider undo\redo manager for actions made+logging maybe?
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public bool IsDirty { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public string UnpackedDir { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public string DestPath { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public bool PlatformPC
{
get { return chkPlatformPC.Checked; }
set { chkPlatformPC.Checked = value; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public bool PlatformMAC
{
get { return chkPlatformMAC.Checked; }
set { chkPlatformMAC.Checked = value; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public bool PlatformXBox360
{
get { return chkPlatformXBox360.Checked; }
set { chkPlatformXBox360.Checked = value; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public bool PlatformPS3
{
get { return chkPlatformPS3.Checked; }
set { chkPlatformPS3.Checked = value; }
}
public string Album
{
get { return txtAlbum.Text; }
set { txtAlbum.Text = value.GetValidAtaSpaceName(); }
}
public string AlbumSort
{
get { return txtAlbumSort.Text; }
set { txtAlbumSort.Text = String.IsNullOrEmpty(value) ? Album.GetValidSortableName() : value.GetValidSortableName(); }
}
public string AlbumYear
{
get { return txtYear.Text; }
set { txtYear.Text = value.GetValidYear(); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public string AppId
{
get { return txtAppId.Text; }
set { txtAppId.Text = value.GetValidAppIdSixDigits(); }
}
public string Artist
{
get { return txtArtist.Text; }
set { txtArtist.Text = value.GetValidAtaSpaceName(); }
}
public string ArtistSort
{
get { return txtArtistSort.Text; }
set { txtArtistSort.Text = String.IsNullOrEmpty(value) ? Artist.GetValidSortableName() : value.GetValidSortableName(); }
}
public string AverageTempo
{
get { return txtTempo.Text; }
set { txtTempo.Text = value.GetValidTempo(); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public GameVersion PreviousGameVersion { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
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;
}
}
}
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 (*_xbox, *.*)|*_xbox; *.*|";
filter += CurrentRocksmithTitle + " PS3 Package (*.edat)|*.edat|";
filter += CurrentRocksmithTitle + " All Files (*.*)|*.*";
break;
default:
filter = CurrentRocksmithTitle + " PC Package (*.dat)|*.dat|";
filter += CurrentRocksmithTitle + " XBox360 Package (*_xbox, *.*)|*_xbox; *.*|";
// TODO: add support for RS1 PS3
// filter + CurrentRocksmithTitle + " PS3 Package (*.edat)|*.edat|";
filter += CurrentRocksmithTitle + " All Files (*.*)|*.*";
break;
}
return filter;
}
}
public string DLCKey // appears to be interchageble with SongKey
{
get { return txtDlcKey.Text; }
set { txtDlcKey.Text = value.GetValidKey(); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public bool JavaBool { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public string ToolkitVers { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public string PackageAuthor { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public string PackageRating { get; set; }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
public string PackageComment
{
get
{
var tkiComment = CurrentGameVersion == GameVersion.RS2012 ? TKI_RS1 : TKI_REMASTER;
// add any ToolkitInfo comment
if (String.IsNullOrEmpty(packageComment))
return tkiComment;
if (!packageComment.Contains("Remastered") || !packageComment.Contains("RS1"))
return packageComment + " " + tkiComment;
return packageComment;
}
set { packageComment = value; }
}
public string PackageVersion
{
get { return txtVersion.Text; }
set { txtVersion.Text = String.IsNullOrEmpty(value) ? "" : value.GetValidVersion(); }
}
public string JapaneseArtistName
{
get { return txtJapaneseArtistName.Text; }
set { txtJapaneseArtistName.Text = value; }
}
public string JapaneseSongTitle
{
get { return txtJapaneseSongTitle.Text; }
set { txtJapaneseSongTitle.Text = value; }
}
public string SongTitle
{
get { return txtSongTitle.Text; }
set { txtSongTitle.Text = value.GetValidAtaSpaceName(); }
}
public string SongTitleSort
{
get { return txtSongTitleSort.Text; }
set { txtSongTitleSort.Text = String.IsNullOrEmpty(value) ? SongTitle.GetValidSortableName() : value.GetValidSortableName(); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
private string AlbumArtPath // 512 (RS1)
{
get { return txtAlbumArtPath.Text; }
set { txtAlbumArtPath.Text = value; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // perma fix to prevent creating a property value in designer
private string AudioPath
{
get { return txtAudioPath.Text; }
set { txtAudioPath.Text = value; }
}
private string CurrentOFDAudioFileFilter
{
get
{
switch (CurrentGameVersion)
{
case GameVersion.None:
case GameVersion.RS2014:
return "All Supported Files|*.wem;*.ogg;*.wav|Wwise 2013 audio files (*.wem)|*.wem|Ogg Vorbis audio files (*.ogg)|*.ogg|Wave audio files (*.wav)|*.wav";
default:
return "All Supported Files|*.ogg;*.wav|Wwise 2010 audio files (*.ogg)|*.ogg|Ogg Vorbis audio files (*.ogg)|*.ogg|Wave audio files (*.wav)|*.wav";
}
}
}
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;
}
}
private string CurrentRocksmithTitle
{
get
{
switch (CurrentGameVersion)
{
case GameVersion.None:
case GameVersion.RS2014:
return "Rocksmith 2014";
default:
return "Rocksmith";
}
}
}
public dynamic CreateNewTone(string toneName = "Default")
{
var name = GetUniqueToneName(toneName);
var allPedals = ToolkitPedal.LoadFromResource(CurrentGameVersion);
// create usable new tone, not just empty tone name/key
if (CurrentGameVersion != GameVersion.RS2012)
{
//return new Tone2014() { Name = name, Key = name };
var tone2014 = new Tone2014();
tone2014.Name = name.GetValidAtaSpaceName();
tone2014.Key = name.GetValidKey(isTone: true);
tone2014.GearList.Amp = allPedals.First(p => p.Key == "Amp_OrangeAD50").MakePedalSetting(GameVersion.RS2014);
tone2014.GearList.Cabinet = allPedals.First(p => p.Key == "Cab_OrangeJimmyBean_57_Cone").MakePedalSetting(GameVersion.RS2014);
tone2014.ToneDescriptors.Add("$[35720]CLEAN");
return tone2014;
}
// return new Tone { Name = name, Key = name };
var tone = new Tone();
tone.Name = name.GetValidAtaSpaceName();
tone.Key = name.GetValidKey(isTone: true);
tone.PedalList.Add("Amp", allPedals.First(p => p.Key == "Amp_Fusion").MakePedalSetting(GameVersion.RS2012));
tone.PedalList.Add("Cabinet", allPedals.First(p => p.Key == "Cab_2X12_Fusion_57_Cone").MakePedalSetting(GameVersion.RS2012));
return tone;
}
public Arrangement GenMetronomeArr(Arrangement arr)
{
var mArr = GeneralExtension.Copy(arr);
var songXml = Song2014.LoadFromFile(mArr.SongXml.File);
var newXml = Path.GetTempFileName();
mArr.SongXml = new RocksmithToolkitLib.DLCPackage.AggregateGraph.SongXML { File = newXml };
mArr.SongFile = new RocksmithToolkitLib.DLCPackage.AggregateGraph.SongFile { File = "" };
mArr.ClearCache();
mArr.BonusArr = true;
mArr.Id = IdGenerator.Guid();
mArr.MasterId = RandomGenerator.NextInt();
mArr.Metronome = Metronome.Itself;
songXml.ArrangementProperties.Metronome = (int)Metronome.Itself;
var ebeats = songXml.Ebeats;
var songEvents = new RocksmithToolkitLib.XML.SongEvent[ebeats.Length];
for (var i = 0; i < ebeats.Length; i++)
{
songEvents[i] = new RocksmithToolkitLib.XML.SongEvent
{
Code = ebeats[i].Measure == -1 ? "B1" : "B0",
Time = ebeats[i].Time
};
}
songXml.Events = songXml.Events.Union(songEvents, new EqSEvent()).OrderBy(x => x.Time).ToArray();
using (var stream = File.OpenWrite(mArr.SongXml.File))
songXml.Serialize(stream, true);
return mArr;
}
public void LoadTemplateFile(string templatePath)
{
// Make the paths relative
var basePath = Path.GetDirectoryName(templatePath);
if (String.IsNullOrEmpty(UnpackedDir))
UnpackedDir = basePath;
DLCPackageData info = null;
try
{
if (CurrentGameVersion == GameVersion.RS2014) // rbRs2014.Checked)
{
// check and fix the template compatibility if necessary
var templateString = File.ReadAllText(templatePath);
if (templateString.Contains("Manifest.Tone\">"))
{
templateString = templateString.Replace("Manifest.Tone\">", "Manifest2014.Tone\">");
File.WriteAllText(templatePath, templateString, Encoding.UTF8);
}
}
using (var stm = new XmlTextReader(templatePath))
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
CurrentGameVersion = (Convert.ToInt32(info.AppId) < 230000) ? GameVersion.RS2012 : GameVersion.RS2014;
}
catch (Exception se)
{
MessageBox.Show("Can not load CDLC Template. \n" + se.Message, MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
foreach (var arr in info.Arrangements)
{
// load xml comments
arr.XmlComments = Song2014.ReadXmlComments(Path.Combine(basePath, arr.SongXml.File));
// apply bassfix to template info in case arrangement was changed in EOF
if (arr.ArrangementType == ArrangementType.Bass)
{
// fix old toolkit behavior
if (arr.TuningStrings == null)
{
arr.TuningStrings = new TuningStrings { String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0 };
continue;
}
if (rbRs2012.Checked)
continue;
var bassFix = false;
//Low tuning fix for bass, If lowest string is B and bass fix not applied
if (arr.TuningStrings.String0 < -4 && arr.TuningPitch != 220.00)
if (fixLowBass)
bassFix = true;
else
bassFix |= MessageBox.Show(@"The bass tuning may be too low. Apply Low Bass Tuning Fix?" + Environment.NewLine + @"Note: The fix may revert if bass Arrangement is re-saved in EOF. ", @"Warning ... Low Bass Tuning", MessageBoxButtons.YesNo) == DialogResult.Yes;
// Fix Low Bass Tuning
if (bassFix && TuningFrequency.ApplyBassFix(arr, fixLowBass))
{
arr.TuningStrings = Song2014.LoadFromFile(Path.Combine(basePath, arr.SongXml.File)).Tuning;
arr.TuningPitch = 220.00;
arr.Tuning = TuningDefinitionRepository.Instance.Detect(arr.TuningStrings, GameVersion.RS2014, false).UIName;
//MessageBox.Show("It appears the bass arrangement has been modified in EOF." + Environment.NewLine +
// "It is recommended that you manually 'Add' all the project" + Environment.NewLine +
// "files to the toolkit rather than to use 'Load Template'," + Environment.NewLine +
// "because some template files have been modified in EOF.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
try
{
FillPackageCreatorForm(info, templatePath);
}
catch (Exception ex)
{
throw new Exception("<ERROR> LoadTemplateFile Failed, Corrupt Template ..." + Environment.NewLine +
Path.GetFileName(templatePath) + Environment.NewLine + Environment.NewLine +
"Delete this template, and manually load the project files." + Environment.NewLine +
ex.Message);
}
// RS2014 ONLY FIELDS
chkPlatformMAC.Enabled = CurrentGameVersion != GameVersion.RS2012;
numVolPreview.Enabled = CurrentGameVersion != GameVersion.RS2012;
chkJapaneseTitle.Enabled = CurrentGameVersion != GameVersion.RS2012;
chkShowlights.Enabled = CurrentGameVersion != GameVersion.RS2012;
if (!GlobalsLib.IsUnitTest)
Parent.Focus();
}
public string SaveTemplateFile(string templateDir = "", bool validate = true)
{
// FIXME: RS1 tone data not being saved (reseting to default)
var templatePath = String.Empty;
var fileName = String.Empty;
var packageDataError = String.Empty;
DLCPackageData packageData = GetPackageData(validate, out packageDataError);
try
{
fileName = StringExtensions.GetValidShortFileName(ArtistSort, SongTitleSort, CurrentGameVersion.ToString(), ConfigRepository.Instance().GetBoolean("creator_useacronyms"));
}
catch (Exception ex)
{
if (DialogResult.Yes == MessageBox.Show("CDLC template can not be autosaved." + Environment.NewLine +
ex.Message + Environment.NewLine + Environment.NewLine + "Exit without saving?", MESSAGEBOX_CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
{
return String.Empty;
}
}
if (!String.IsNullOrEmpty(templateDir) && !String.IsNullOrEmpty(fileName))
{
templatePath = Path.Combine(templateDir, fileName + ".dlc.xml");
}
else
{
using (var ofd = new SaveFileDialog())
{
if (!String.IsNullOrEmpty(UnpackedDir))
ofd.InitialDirectory = UnpackedDir;
else
{
try
{
// use EOF project directory if it exists
ofd.InitialDirectory = Path.GetDirectoryName(packageData.Arrangements[0].SongXml.File);
}
catch
{
// ignore exeption if the EOF project directory does not exists
}
}
ofd.Title = "Save CDLC Template File as ...";
ofd.SupportMultiDottedExtensions = true;
ofd.Filter = CurrentRocksmithTitle + " CDLC Template (*.dlc.xml)|*.dlc.xml";
ofd.FileName = fileName.GetValidFileName();
if (DialogResult.OK != ofd.ShowDialog())
return String.Empty;
templatePath = ofd.FileName;
}
}
// Make the paths relative
var basePath = Path.GetDirectoryName(templatePath);
if (String.IsNullOrEmpty(UnpackedDir))
UnpackedDir = basePath;
if (!String.IsNullOrEmpty(packageData.OggPath))
packageData.OggPath = packageData.OggPath.RelativeTo(basePath);
if (!String.IsNullOrEmpty(packageData.OggPreviewPath))
packageData.OggPreviewPath = packageData.OggPreviewPath.RelativeTo(basePath);
if (!string.IsNullOrEmpty(packageData.AlbumArtPath))
packageData.AlbumArtPath = packageData.AlbumArtPath.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.LyricsArtPath))
arr.LyricsArtPath = arr.LyricsArtPath.RelativeTo(basePath);
if (!String.IsNullOrEmpty(arr.GlyphsXmlPath))
arr.GlyphsXmlPath = arr.GlyphsXmlPath.RelativeTo(basePath);
}
try
{
// Write Template with Relative Paths
using (var stm = XmlWriter.Create(templatePath, new XmlWriterSettings { CheckCharacters = true, Indent = true }))
{
new DataContractSerializer(typeof(DLCPackageData)).WriteObject(stm, packageData);
IsDirty = false;
}
}
catch (Exception ex)
{
throw new Exception("<ERROR> SaveTemplateFile Failed ..." + Environment.NewLine + ex.Message);
}
// Re-Absolutize the paths
if (!String.IsNullOrEmpty(packageData.OggPath))
packageData.OggPath = packageData.OggPath.AbsoluteTo(basePath);
if (!String.IsNullOrEmpty(packageData.OggPreviewPath))
packageData.OggPreviewPath = packageData.OggPreviewPath.AbsoluteTo(basePath);
if (!string.IsNullOrEmpty(packageData.AlbumArtPath))
packageData.AlbumArtPath = packageData.AlbumArtPath.AbsoluteTo(basePath);
foreach (var arr in packageData.Arrangements)
{
if (!String.IsNullOrEmpty(arr.SongXml.File))
arr.SongXml.File = arr.SongXml.File.AbsoluteTo(basePath);
if (!String.IsNullOrEmpty(arr.LyricsArtPath))
arr.LyricsArtPath = arr.LyricsArtPath.AbsoluteTo(basePath);
if (!String.IsNullOrEmpty(arr.GlyphsXmlPath))
arr.GlyphsXmlPath = arr.GlyphsXmlPath.AbsoluteTo(basePath);
}
if (String.IsNullOrEmpty(templateDir)) //if in GUI mode.
MessageBox.Show(CurrentRocksmithTitle + " CDLC template was saved.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
return templatePath;
}
/// <summary>
/// Update song XML file (guitar or bass) with user modified DLCPackageData info
/// </summary>
/// <param name="arr"></param>
/// <param name="info"></param>
public void UpdateSongXml(Arrangement arr, DLCPackageData info)
{
if (arr.ArrangementType == ArrangementType.Vocal || arr.ArrangementType == ArrangementType.ShowLight)
return;
var song2014 = Song2014.LoadFromFile(arr.SongXml.File);
song2014.AlbumYear = info.SongInfo.SongYear.ToString();
song2014.ArtistName = info.SongInfo.Artist;
song2014.Title = info.SongInfo.SongDisplayName;
song2014.AlbumName = info.SongInfo.Album;
song2014.ArtistNameSort = info.SongInfo.ArtistSort;
song2014.SongNameSort = info.SongInfo.SongDisplayNameSort;
song2014.AlbumNameSort = info.SongInfo.AlbumSort;
song2014.AverageTempo = info.SongInfo.AverageTempo;
// add optional properties
if (!String.IsNullOrEmpty(info.SongInfo.JapaneseSongName) || !String.IsNullOrEmpty(info.SongInfo.JapaneseArtistName))
{
song2014.OptionalProperties = new OptionalProperties()
{
JapaneseArtistName = info.SongInfo.JapaneseArtistName,
JapaneseSongName = info.SongInfo.JapaneseSongName
};
}
song2014.Tuning = arr.TuningStrings;
song2014.Capo = (byte)arr.CapoFret;
// all other ArrangementProperties in the xml are set by EOF and not changed by Toolkit (currently)
song2014.ArrangementProperties = arr.ArrangementPropeties != null ? arr.ArrangementPropeties : new SongArrangementProperties2014();
song2014.ArrangementProperties.Represent = arr.Represent ? 1 : 0;
song2014.ArrangementProperties.BonusArr = arr.BonusArr ? 1 : 0;
song2014.ArrangementProperties.PathLead = Convert.ToInt32(arr.RouteMask == RouteMask.Lead);
song2014.ArrangementProperties.PathRhythm = Convert.ToInt32(arr.RouteMask == RouteMask.Rhythm);
song2014.ArrangementProperties.PathBass = Convert.ToInt32(arr.RouteMask == RouteMask.Bass);
song2014.ArrangementProperties.RouteMask = (int)arr.RouteMask;
song2014.ArrangementProperties.StandardTuning = arr.Tuning == "E Standard" ? 1 : 0;
song2014.ArrangementProperties.BassPick = arr.ArrangementType == ArrangementType.Bass ? (int)arr.PluckedType : 0;
// TODO: monitor this change
// Commented out - EOF now properly sets the bonus/represent elements
// represent is set to "1" by default, if there is a bonus then set represent to "0"
//songXml.ArrangementProperties.Represent = arr.BonusArr ? 0 : 1;
// for alternate arrangement then both represent and bonus are set to "0"
//if (songXml.Part > 1 && !arr.BonusArr)
// songXml.ArrangementProperties.Represent = 0;
if (CurrentGameVersion != GameVersion.RS2012)
{
//TODO: before this, check somewhere if autotone present, like update arrangement info in GetPackageData section.
bool updTones = song2014.Tones != null;
if (!String.IsNullOrEmpty(arr.ToneBase)) song2014.ToneBase = arr.ToneBase;
if (!String.IsNullOrEmpty(arr.ToneA))
{
if (updTones)
foreach (var t in song2014.Tones)
if (t.Name == song2014.ToneA)
{
t.Name = arr.ToneA;
t.Id = 0;
}
song2014.ToneA = arr.ToneA;
}
if (!String.IsNullOrEmpty(arr.ToneB))
{
if (updTones)
foreach (var t in song2014.Tones)
if (t.Name == song2014.ToneB)
{
t.Name = arr.ToneB;
t.Id = 1;
}
song2014.ToneB = arr.ToneB;
}
if (!String.IsNullOrEmpty(arr.ToneC))
{
if (updTones)
foreach (var t in song2014.Tones)
if (t.Name == song2014.ToneC)
{
t.Name = arr.ToneC;
t.Id = 2;
}
song2014.ToneC = arr.ToneC;
}
if (!String.IsNullOrEmpty(arr.ToneD))
{
if (updTones)
foreach (var t in song2014.Tones)
if (t.Name == song2014.ToneD)
{
t.Name = arr.ToneD;
t.Id = 3;
}
song2014.ToneD = arr.ToneD;
}
// write updated xml arrangement
using (var stream = File.Open(arr.SongXml.File, FileMode.Create))
song2014.Serialize(stream, true);
}
if (CurrentGameVersion == GameVersion.RS2012)
{
// detect and maintain old RS1 XML versions
if (String.IsNullOrEmpty(song2014.Version) || song2014.Version == "4")
{
var song = Song.LoadFromFile(arr.SongXml.File);
// write updated xml arrangement as old RS1 XML version
using (var stream = File.Open(arr.SongXml.File, FileMode.Create))
song.Serialize(stream, true);
}
}
}
private void AddArrangementsQuick(string[] filePaths)
{
foreach (var filePath in filePaths)
AddArrangement(filePath);
}
private void AddArrangement(string xmlFilePath = "")
{
Arrangement arrangement = null;
using (var form = new ArrangementForm(this, CurrentGameVersion))
{
form.EditMode = false;
if (!String.IsNullOrEmpty(xmlFilePath))
{
if (!form.AddXmlArrangement(xmlFilePath))
return;
form.LoadArrangementData(xmlFilePath);
}
else
{
if (form.ShowDialog() != DialogResult.OK)
return;
}
arrangement = form.Arrangement;
if (arrangement == null || form.IsAlreadyAdded(arrangement.SongXml.File))
return;
}
// respect processing order (must come before arrangement is added)
// creates the appropriate arrangement identifier string
if (GlyphDefinitions.UpdateCustomFontStatus(ref arrangement, UnpackedDir))
Debug.WriteLine(arrangement.SongXml.File + " HasCustomFont");
lstArrangements.Items.Add(arrangement);
IsDirty = true;
}
private void AddValidationEventHandlers()
{
txtArtist.Validating += ValidateName;
txtArtistSort.Validating += ValidateSortName;
txtSongTitle.Validating += ValidateName;
txtSongTitleSort.Validating += ValidateSortName;
txtAlbum.Validating += ValidateName;
txtAlbumSort.Validating += ValidateSortName;
txtYear.Validating += ValidateYear;
txtVersion.Validating += ValidateVersion;
txtDlcKey.Validating += ValidateDlcKey;
txtVersion.Validating += ClickedInputControl;
txtTempo.Validating += ValidateTempo;
btnArrangementAdd.Click += ClickedInputControl;
btnArrangementEdit.Click += ClickedInputControl;
btnArrangementRemove.Click += ClickedInputControl;
btnToneAdd.Click += ClickedInputControl;
btnToneEdit.Click += ClickedInputControl;
btnToneRemove.Click += ClickedInputControl;
btnToneDuplicate.Click += ClickedInputControl;
btnToneImport.Click += ClickedInputControl;
}
private void DuplicateTone()
{
if (lstTones.SelectedItem != null && lstTones.Items.Count > 0)
{
dynamic tone = lstTones.SelectedItem;
switch (CurrentGameVersion)
{
case GameVersion.RS2012:
tone = GeneralExtension.Copy<Tone>((Tone)lstTones.SelectedItem);
break;
case GameVersion.None:
case GameVersion.RS2014:
tone = GeneralExtension.Copy<Tone2014>((Tone2014)lstTones.SelectedItem);
break;
}
var name = GetUniqueToneName(lstTones.Text);
tone.Name = name;
tone.Key = name.GetValidKey(isTone: true);
lstTones.Items.Add(tone);
dynamic firstTone = lstTones.Items[0];
foreach (var item in lstArrangements.Items.OfType<Arrangement>())
if (tone.Name.Equals(item.ToneBase))
item.ToneBase = firstTone.Name;
lstArrangements.Refresh();
IsDirty = true;
}
}
public void FillPackageCreatorForm(DLCPackageData info, string filesBaseDir)
{
PlatformPC = info.Pc;
PlatformMAC = info.Mac;
PlatformXBox360 = info.XBox360;
PlatformPS3 = info.PS3;
if (info.ToolkitInfo == null)
info.ToolkitInfo = new ToolkitInfo { PackageVersion = "1" };
ToolkitVers = info.ToolkitInfo.ToolkitVersion;
PackageVersion = info.ToolkitInfo.PackageVersion;
PackageComment = info.ToolkitInfo.PackageComment;
PackageAuthor = info.ToolkitInfo.PackageAuthor;
PackageRating = info.ToolkitInfo.PackageRating; // new for future
lstTones.Items.Clear();
switch (CurrentGameVersion)
{
case GameVersion.RS2012:
if (info.Tones == null)
info.Tones = new List<Tone>();
if (info.Tones.Count == 0)
info.Tones.Add(CreateNewTone());
foreach (var tone in info.Tones)
{
if (String.IsNullOrEmpty(tone.Key)) // JIC should never happen
tone.Key = tone.Name.GetValidKey(isTone: true);
lstTones.Items.Add(tone);
}
break;
case GameVersion.None:
case GameVersion.RS2014:
if (info.TonesRS2014 == null)
info.TonesRS2014 = new List<Tone2014>();
if (info.TonesRS2014.Count == 0)
info.TonesRS2014.Add(CreateNewTone());
foreach (var toneRS2014 in info.TonesRS2014)
{
if (String.IsNullOrEmpty(toneRS2014.Key))
toneRS2014.Key = toneRS2014.Name.GetValidKey(isTone: true);
lstTones.Items.Add(toneRS2014);
}
break;
}
var basePath = Path.GetDirectoryName(filesBaseDir);
// Song INFO
txtDlcKey.Text = info.Name;
// do in case CurrentGameVersion changed
PopulateAppIdCombo();
// Update AppID unless it is locked
if (!ConfigRepository.Instance().GetBoolean("general_lockappid"))
{
if (String.IsNullOrEmpty(info.AppId))
{
// get GeneralConfig default AppID
var songAppId = SongAppIdRepository.Instance().Select((CurrentGameVersion == GameVersion.RS2014) ? ConfigRepository.Instance()["general_defaultappid_RS2014"] : ConfigRepository.Instance()["general_defaultappid_RS2012"], CurrentGameVersion);
if (!String.IsNullOrEmpty(songAppId.AppId))
AppId = songAppId.AppId;
else
AppId = "248750"; // JIC use hardcoded default
}
else
AppId = info.AppId;
}
else
AppId = info.AppId;
SelectComboAppId(AppId);
// validate on-load to address old CDLC issues
// REM info.SongInfo is from Manifest JSON File Data
txtAlbum.Text = info.SongInfo.Album.GetValidAtaSpaceName();
txtAlbumSort.Text = info.SongInfo.AlbumSort.GetValidSortableName();
txtJapaneseSongTitle.Text = info.SongInfo.JapaneseSongName;
txtJapaneseArtistName.Text = info.SongInfo.JapaneseArtistName;
chkJapaneseTitle.Checked = !String.IsNullOrEmpty(info.SongInfo.JapaneseSongName) || !String.IsNullOrEmpty(info.SongInfo.JapaneseArtistName);
txtSongTitle.Text = info.SongInfo.SongDisplayName.GetValidAtaSpaceName();
txtSongTitleSort.Text = info.SongInfo.SongDisplayNameSort.GetValidSortableName();
txtYear.Text = info.SongInfo.SongYear.ToString();
txtArtist.Text = info.SongInfo.Artist.GetValidAtaSpaceName();
txtArtistSort.Text = info.SongInfo.ArtistSort.GetValidSortableName();
txtTempo.Text = info.SongInfo.AverageTempo.ToString();
// fill in the new AlbumSort textbox if it is empty
if (String.IsNullOrEmpty(txtAlbumSort.Text))
{
var useDefaultAuthor = ConfigRepository.Instance().GetBoolean("creator_usedefaultauthor");
// use default author for AlbumSort or generate
if (useDefaultAuthor) // && CurrentGameVersion == GameVersion.RS2014)
AlbumSort = ConfigRepository.Instance()["general_defaultauthor"].Trim().GetValidSortableName();
else
AlbumSort = Album.GetValidSortableName();
}
// AlbumArtPath from template RelativeTo path must be re-converted AbsoluteTo path
if (!String.IsNullOrEmpty(info.AlbumArtPath))
{
// remove old template relative path identifiers
info.AlbumArtPath = info.AlbumArtPath.Replace(@"..\..\", "").Replace(@"..\", "");
AlbumArtPath = info.AlbumArtPath.AbsoluteTo(basePath);
info.ArtFiles = null; // force ArtFiles array to be generated from the AlbumArtPath
}
// OggPath/WemPath from template RelativeTo path must be re-converted AbsoluteTo path
if (!String.IsNullOrEmpty(info.OggPath))
{
// remove old template relative path identifiers
info.OggPath = info.OggPath.Replace(@"..\", "");
AudioPath = info.OggPath.AbsoluteTo(basePath);
}
numVolSong.Value = Decimal.Round((decimal)info.Volume, 2);
numVolPreview.Value = info.PreviewVolume != null ? Decimal.Round((decimal)info.PreviewVolume, 2) : numVolSong.Value;
if (info.OggQuality > 1 && info.OggQuality < 10)
numAudioQuality.Value = info.OggQuality;
else
numAudioQuality.Value = 4;
lstArrangements.Items.Clear();
for (int i = 0; i < info.Arrangements.Count; i++)
{
var arrangement = info.Arrangements[i];
// remove old template relative path identifiers
arrangement.SongXml.File = arrangement.SongXml.File.Replace(@"..\..\", "").Replace(@"..\", "");
// Template RelativeTo paths must be re-converted AbsoluteTo paths
arrangement.SongXml.File = arrangement.SongXml.File.AbsoluteTo(basePath);
if (!String.IsNullOrEmpty(arrangement.LyricsArtPath))
arrangement.LyricsArtPath = arrangement.LyricsArtPath.AbsoluteTo(basePath);
if (!String.IsNullOrEmpty(arrangement.GlyphsXmlPath))
arrangement.GlyphsXmlPath = arrangement.GlyphsXmlPath.AbsoluteTo(basePath);
arrangement.ClearCache();