Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathNotes.cs
More file actions
1066 lines (977 loc) · 37.9 KB
/
Copy pathNotes.cs
File metadata and controls
1066 lines (977 loc) · 37.9 KB
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
//-----------------------------------------------------------------------
// <copyright file="Notes.cs" company="NoteFly">
// NoteFly a note application.
// Copyright (C) 2010-2013 Tom
//
// This program 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 3 of the License, or
// (at your option) any later version.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
//-----------------------------------------------------------------------
namespace NoteFly
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Windows.Forms;
/// <summary>
/// Notes class, holds all notes
/// </summary>
public class Notes : IPlugin.IPluginHost
{
#region Fields (5)
/// <summary>
/// The note extension
/// </summary>
public const string NOTEEXTENSION = ".nfn";
/// <summary>
/// The maximum length of the filename.
/// </summary>
private const int LIMITLENFILE = 8;
/// <summary>
/// Empty file that hints notefly2 that notefly1 notes folder has been imported.
/// </summary>
private const string IMPORTEDFLAGFILE = "impnf30.flg";
/// <summary>
/// The list with all notes.
/// </summary>
private List<Note> notes;
/// <summary>
/// List with all skins for notes.
/// </summary>
private List<Skin> skins;
#endregion Fields
#region Constructors (1)
/// <summary>
/// Initializes a new instance of the Notes class.
/// </summary>
/// <param name="resetpositions">Boolean true for reseting all notes positions on loading.</param>
public Notes(bool resetpositions)
{
this.notes = new List<Note>();
this.skins = new List<Skin>();
this.skins = xmlUtil.LoadSkins();
this.LoadNotes(Settings.ProgramFirstrunned, resetpositions);
}
#endregion Constructors
#region Properties (2)
/// <summary>
/// Gets the number of notes there are.
/// </summary>
public int CountNotes
{
get
{
return this.notes.Count;
}
}
/// <summary>
/// Gets the number of skins there are.
/// </summary>
public int CountSkins
{
get
{
return this.skins.Count;
}
}
#endregion Properties
#region Methods (21)
/// <summary>
/// Add a new note the the notes list.
/// </summary>
/// <param name="note">The note to be added.</param>
/// <returns>True if succesfull added.</returns>
public bool AddNote(Note note)
{
if (note == null)
{
return false;
}
this.notes.Add(note);
return true;
}
/// <summary>
/// Create a new note object with some default settings
/// The default settings are note that can't be changed while editing a note.
/// </summary>
/// <param name="title">The title of the note.</param>
/// <param name="skinnr">The skinnr</param>
/// <param name="x">X coordinate</param>
/// <param name="y">Y coordinate</param>
/// <param name="width">Width of the note</param>
/// <param name="height">Height of the note</param>
/// <param name="wordwarp">Is the note content word warped.</param>
/// <returns>Note object</returns>
public Note CreateNoteDefaultSettings(string title, int skinnr, int x, int y, int width, int height, bool wordwarp)
{
Note newnote = new Note(this, this.GetNoteFilename(title)); // set filename based on title
newnote.Locked = false; // default
newnote.RolledUp = false; // default
newnote.Ontop = false; // default
newnote.Visible = true; // default
newnote.Wordwarp = wordwarp;
newnote.Title = title;
newnote.SkinNr = skinnr;
newnote.X = x;
newnote.Y = y;
newnote.Width = width;
newnote.Height = height;
return newnote;
}
/// <summary>
/// Add a new default note to the notes list
/// </summary>
/// <param name="title">The title the note.</param>
/// <param name="skinnr">The skinnr</param>
/// <param name="x">The X location of the note.</param>
/// <param name="y">The Y location of the note.</param>
/// <param name="width">The width of the note.</param>
/// <param name="height">The height of the note.</param>
/// <param name="content">The note rtf content.</param>
/// <param name="wordwarp">Is the note content word warped.</param>
public Note AddNoteDefaultSettings(string title, int skinnr, int x, int y, int width, int height, string content, bool wordwarp)
{
Note note = this.CreateNoteDefaultSettings(title, skinnr, x, y, width, height, wordwarp);
if (note != null)
{
this.AddNote(note);
xmlUtil.WriteNote(note, this.GetSkinName(skinnr), content);
note.CreateForm();
}
return note;
}
/// <summary>
/// Bring all notes to front of all other windows.
/// </summary>
public void BringToFrontNotes()
{
for (int i = 0; i < this.notes.Count; i++)
{
if (this.notes[i].Visible)
{
if (this.notes[i] == null)
{
throw new ApplicationException("Note object is null.");
}
else
{
this.notes[i].BringNoteToFront();
}
}
}
}
/// <summary>
/// Generate a random skinnummer.
/// </summary>
/// <returns>A random skin number/position</returns>
public int GenerateRandomSkinnr()
{
Random rndgen = new Random();
return rndgen.Next(0, this.skins.Count);
}
/// <summary>
/// Gets the highlight color.
/// </summary>
/// <param name="skinnr">The skin number</param>
/// <returns>Color object</returns>
public System.Drawing.Color GetHighlightClr(int skinnr)
{
return this.GetColor(3, skinnr);
}
/// <summary>
/// Gets a note, by position in list
/// </summary>
/// <param name="pos">Note position in list notes</param>
/// <returns>The Note object</returns>
public Note GetNote(int pos)
{
try
{
return this.notes[pos];
}
catch (ArgumentOutOfRangeException)
{
throw new ApplicationException("Can't get this note position: " + pos);
}
}
/// <summary>
/// Create a string used for filename of the note based on the
/// title of the note limited to the first xx characters.
/// </summary>
/// <param name="title">The title of the note</param>
/// <returns>A safe filename based on the title.</returns>
public string GetNoteFilename(string title)
{
string title2 = this.StripForbiddenFilenameChars(title);
string newfile;
if (title2.Length > LIMITLENFILE)
{
newfile = title2.Substring(0, LIMITLENFILE) + NOTEEXTENSION;
}
else
{
newfile = title2 + NOTEEXTENSION;
}
if (File.Exists(Path.Combine(Settings.NotesSavepath, newfile)))
{
newfile = this.Checknewfilename(newfile, LIMITLENFILE, '#');
return newfile;
}
else
{
return newfile;
}
}
/// <summary>
/// Gets the primary color.
/// </summary>
/// <param name="skinnr">The skin number</param>
/// <returns>The primary color</returns>
public System.Drawing.Color GetPrimaryClr(int skinnr)
{
return this.GetColor(1, skinnr);
}
/// <summary>
/// Gets the selected color.
/// </summary>
/// <param name="skinnr">The skin number</param>
/// <returns>The selected skin color.</returns>
public System.Drawing.Color GetSelectClr(int skinnr)
{
return this.GetColor(2, skinnr);
}
/// <summary>
/// Gets the primary texture for a skin.
/// </summary>
/// <param name="skinnr">The skin number</param>
/// <returns>A bitmap</returns>
public Bitmap GetPrimaryTexture(int skinnr)
{
Bitmap bitmaptexture = null;
if (!string.IsNullOrEmpty(this.skins[skinnr].PrimaryTexture))
{
bitmaptexture = new Bitmap(this.skins[skinnr].PrimaryTexture);
}
return bitmaptexture;
}
/// <summary>
/// Get the primary texture image layout for a skin.
/// </summary>
/// <param name="skinnr">The skin number</param>
/// <returns>The image layout how the note texture is used.</returns>
public System.Windows.Forms.ImageLayout GetPrimaryTextureLayout(int skinnr)
{
try
{
return this.skins[skinnr].PrimaryTextureLayout;
}
catch (IndexOutOfRangeException)
{
return this.skins[0].PrimaryTextureLayout;
}
}
/// <summary>
/// Get the name of a skin by the skinnr.
/// </summary>
/// <param name="skinnr">The skin number</param>
/// <returns>The name of the skin, e.g. Yellow</returns>
public string GetSkinName(int skinnr)
{
try
{
return this.skins[skinnr].Name;
}
catch (IndexOutOfRangeException)
{
return this.skins[0].Name;
}
}
/// <summary>
/// Get the skinnr that belongs by a name.
/// If not found return 0 is return so first skin is used.
/// </summary>
/// <param name="skinname">The skin name.</param>
/// <returns>The skinnr.</returns>
public int GetSkinNr(string skinname)
{
for (int i = 0; i < this.skins.Count; i++)
{
if (this.skins[i].Name == skinname)
{
return i;
}
}
Log.Write(LogType.error, "SkinNr not found for skinname: " + skinname);
return 0;
}
/// <summary>
/// Gets a string array with all the skin names.
/// </summary>
/// <returns>An array with skin names.</returns>
public string[] GetSkinsNames()
{
string[] skinnames = new string[this.skins.Count];
for (int i = 0; i < skinnames.Length; i++)
{
skinnames[i] = this.skins[i].Name;
}
return skinnames;
}
/// <summary>
/// Gets the text color.
/// </summary>
/// <param name="skinnr">The skin number</param>
/// <returns>Color object in text color.</returns>
public System.Drawing.Color GetTextClr(int skinnr)
{
return this.GetColor(4, skinnr);
}
/// <summary>
/// Loads all note files in the NotesSavepath.
/// </summary>
/// <param name="hasbeenfirstrun">True if it is the first run.</param>
/// <param name="resetpositions">True for reseting all the notes positions.</param>
public void LoadNotes(bool hasbeenfirstrun, bool resetpositions)
{
if (!Directory.Exists(Settings.NotesSavepath))
{
string notes_notefolderdoesnotexist = Strings.T("Folder with notes does not exist.\nDo want to load notes from the default notes folder?");
string notes_notefolderdoesnotexisttitle = Strings.T("Notes folder doesn't exist");
DialogResult result = MessageBox.Show(notes_notefolderdoesnotexist, notes_notefolderdoesnotexisttitle, MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.No)
{
Log.Write(LogType.error, notes_notefolderdoesnotexist + " No");
return;
}
else
{
Log.Write(LogType.error, notes_notefolderdoesnotexist + " Yes");
Settings.NotesSavepath = Program.GetDefaultNotesFolder();
}
}
#if DEBUG
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
#endif
string[] notefilespath = Directory.GetFiles(Settings.NotesSavepath, "*" + NOTEEXTENSION, SearchOption.TopDirectoryOnly);
string[] notefiles = new string[notefilespath.Length];
for (int i = 0; i < notefilespath.Length; i++)
{
notefiles[i] = Path.GetFileName(notefilespath[i]);
}
notefilespath = null;
#if DEBUG
stopwatch.Stop();
Log.Write(LogType.info, "Notes search time: " + stopwatch.ElapsedTicks.ToString() + " ticks");
#endif
this.notes.Clear();
int numloadingnotes = this.CheckLimitNotesTotal(notefiles.Length);
this.notes.Capacity = numloadingnotes;
#if DEBUG
stopwatch.Reset();
stopwatch.Start();
#endif
const int MARGINBETWEENNOTES = 4;
for (int i = 0; i < numloadingnotes; i++)
{
Note note = xmlUtil.LoadNoteFile(this, notefiles[i]);
if (note == null)
{
continue;
}
if (resetpositions)
{
note.Y = 10;
note.X = 10 + (i * MARGINBETWEENNOTES);
if (note.X > System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height)
{
note.X = 10 + (i * MARGINBETWEENNOTES) - System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
}
}
this.AddNote(note);
}
#if DEBUG
stopwatch.Stop();
Log.Write(LogType.info, "Notes load time: " + stopwatch.ElapsedMilliseconds.ToString() + " ms");
#endif
if (!hasbeenfirstrun)
{
this.ImportingNotesNoteFly2();
this.ImportingNotesNoteFly1();
this.CreateFirstrunNote();
}
}
/// <summary>
///
/// </summary>
public void ShowNotesVisible()
{
int numvisiblenotes = 0;
bool warnlimitvisiblenotesshowed = false;
foreach (Note note in this.notes)
{
if (note.Visible)
{
if (!warnlimitvisiblenotesshowed)
{
warnlimitvisiblenotesshowed = this.CheckLimitNotesVisible(numvisiblenotes);
}
note.CreateForm();
}
}
}
/// <summary>
/// Remove a note from the notes list.
/// </summary>
/// <param name="pos">The note position in the list.</param>
public void RemoveNote(int pos)
{
if (pos >= this.notes.Count || pos < 0)
{
throw new ApplicationException("Cannot find note to remove.");
}
else
{
this.notes.RemoveAt(pos);
}
}
/// <summary>
/// Strip forbidden filename characters of a string.
/// </summary>
/// <param name="orgname">The string to strip forbidden filecharacters from.</param>
/// <returns>The filename safe string</returns>
public string StripForbiddenFilenameChars(string orgname)
{
System.Text.StringBuilder newfilename = new System.Text.StringBuilder();
char[] forbiddenchars = Path.GetInvalidFileNameChars(); // "?<>:*|\\/\"".ToCharArray();
bool isforbiddenchar = false;
for (int pos = 0; pos < orgname.Length; pos++)
{
isforbiddenchar = false;
for (int fc = 0; fc < forbiddenchars.Length; fc++)
{
if (orgname[pos] == forbiddenchars[fc])
{
isforbiddenchar = true;
}
}
if (!isforbiddenchar)
{
newfilename.Append(orgname[pos]);
}
}
return newfilename.ToString();
}
/// <summary>
/// Update all note forms.
/// </summary>
public void UpdateAllNoteForms()
{
foreach (Note curnote in this.notes)
{
curnote.UpdateNoteForm();
}
}
/// <summary>
/// Get the primary texture full file path.
/// </summary>
/// <param name="skinnr">The skin position</param>
/// <returns>The full file path the texture file.</returns>
public string GetPrimaryTextureFile(int skinnr)
{
try
{
return this.skins[skinnr].PrimaryTexture;
}
catch (IndexOutOfRangeException)
{
return this.skins[0].PrimaryTexture;
}
}
/// <summary>
/// Reload all skins again.
/// </summary>
public void ReloadAllSkins()
{
this.skins.Clear();
this.skins = xmlUtil.LoadSkins();
}
/// <summary>
/// Gets the notes save directory.
/// </summary>
/// <returns>The directory where notes are saved.</returns>
public string GetNotesSavepath()
{
return Settings.NotesSavepath;
}
/// <summary>
/// Gets the full file path to the settings file.
/// </summary>
/// <returns>Settings file</returns>
public string GetSettingsFile()
{
return Path.Combine(Program.AppDataFolder, xmlUtil.SETTINGSFILE);
}
/// <summary>
/// Gets the skins file path skins file.
/// </summary>
/// <returns>The skins file full path.</returns>
public string GetSkinsFile()
{
return Path.Combine(Program.AppDataFolder, xmlUtil.SKINFILE);
}
/// <summary>
/// Log plugin info.
/// </summary>
/// <param name="infomsg">Info message</param>
public void LogPluginInfo(string infomsg)
{
Log.Write(LogType.info, "plugin, " + infomsg);
}
/// <summary>
/// Log plugin error.
/// </summary>
/// <param name="errormsg">Error message</param>
public void LogPluginError(string errormsg)
{
Log.Write(LogType.error, "plugin, " + errormsg);
}
/// <summary>
/// Gets the programme title. (for plugins)
/// </summary>
/// <returns>The title of the assembly.</returns>
public string GetAssemblyTitle()
{
return Program.AssemblyTitle;
}
/// <summary>
/// Get programme version.
/// Method for plugins
/// </summary>
/// <returns>Get the assembly version as string</returns>
public string GetAssemblyVersionAsString()
{
return Program.AssemblyVersionAsString;
}
/// <summary>
/// Get a setting as boolean. (for plugins)
/// </summary>
/// <param name="settingname">The name of the setting.</param>
/// <returns>A boolean setting.</returns>
public bool GetSettingBool(string settingname)
{
object settingsptr = this.FindSettings(settingname);
if (settingsptr != null)
{
if (settingsptr is bool)
{
return (bool)settingsptr;
}
else
{
Log.Write(LogType.exception, "plugin, requested setting not a boolean, return false for " + settingname);
return false;
}
}
else
{
Log.Write(LogType.exception, "plugin, requested setting not found.");
return false;
}
}
/// <summary>
/// Get a setting as integer. (for plugins)
/// </summary>
/// <param name="settingname">The name of the setting.</param>
/// <returns>An integer setting</returns>
public int GetSettingInt(string settingname)
{
object settingsptr = this.FindSettings(settingname);
if (settingsptr != null)
{
if (settingsptr is int)
{
return (int)settingsptr;
}
else
{
Log.Write(LogType.exception, "plugin, requested setting not a integer, return -1 for " + settingname);
return -1;
}
}
else
{
Log.Write(LogType.exception, "plugin, requested setting not found.");
return -1;
}
}
/// <summary>
/// Get a setting as float. (for plugins)
/// </summary>
/// <param name="settingname">The name of the setting.</param>
/// <returns>An float setting</returns>
public float GetSettingFloat(string settingname)
{
object settingsptr = this.FindSettings(settingname);
if (settingsptr != null)
{
if (settingsptr is float)
{
return (float)settingsptr;
}
else
{
Log.Write(LogType.exception, "plugin, requested setting not a float, return -1 for " + settingname);
return -1;
}
}
else
{
Log.Write(LogType.exception, "plugin, requested setting not found.");
return -1;
}
}
/// <summary>
/// Get a setting as string. (for plugins)
/// </summary>
/// <param name="settingname">The name of the setting.</param>
/// <returns>An string setting.</returns>
public string GetSettingString(string settingname)
{
object settingsptr = this.FindSettings(settingname);
if (settingsptr != null)
{
if (settingsptr is string)
{
return (string)settingsptr;
}
else
{
Log.Write(LogType.exception, "plugin, requested setting not a string, return null for " + settingname);
return null;
}
}
else
{
Log.Write(LogType.exception, "plugin, requested setting not found.");
return null;
}
}
/// <summary>
/// Find a setting in the setting class. (for plugins)
/// </summary>
/// <param name="settingname">The name of the setting.</param>
/// <returns>Return the setting valeau as object</returns>
private object FindSettings(string settingname)
{
Type type = typeof(Settings);
System.Reflection.FieldInfo[] fields = type.GetFields();
// Loop through all fields
foreach (var field in fields)
{
if (field.Name.Equals(settingname, StringComparison.OrdinalIgnoreCase))
{
object settingsptr = field.GetValue(null);
return settingsptr;
}
}
return null;
}
/// <summary>
/// Ask and import notes from NoteFly 1.0.x if application data folder of NoteFly 1.0.x exist.
/// </summary>
/// <returns>True if imported done, false if importing notefly 1.0.x notes not nessesary.</returns>
private bool ImportingNotesNoteFly1()
{
bool imported = false;
string nf1appdata = string.Empty;
if (Program.CurrentOS == Program.OS.WINDOWS)
{
nf1appdata = Path.Combine(System.Environment.GetEnvironmentVariable("APPDATA"), ".NoteFly");
}
else if (Program.CurrentOS == Program.OS.LINUX)
{
nf1appdata = Path.Combine(System.Environment.GetEnvironmentVariable("HOME"), ".NoteFly");
}
if (Directory.Exists(nf1appdata) && (!File.Exists(Path.Combine(nf1appdata, IMPORTEDFLAGFILE))))
{
DialogResult resdoimport = MessageBox.Show(Strings.T(
"Do you want to import the notes from NoteFly 1.0.x?\nPress cancel to ask this again next time."),
Strings.T("Import from NoteFly 1.0.x"),
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
if (resdoimport == DialogResult.Yes)
{
string nf1settingsfile = Path.Combine(nf1appdata, "settings.xml");
string nf1notesavepath = xmlUtil.GetContentString(nf1settingsfile, "notesavepath");
int noteid = 1;
ImportNotes importnotes = new ImportNotes(this);
string nf1notefile = Path.Combine(nf1notesavepath, noteid + ".xml");
while (File.Exists(nf1notefile))
{
nf1notefile = Path.Combine(nf1notesavepath, noteid + ".xml");
importnotes.ReadNoteFly1Note(nf1notefile);
noteid++;
}
this.CreateNotesImportedFlagfile(nf1appdata);
imported = true;
Log.Write(LogType.info, "Notes from NoteFly 1.0.x imported.");
}
else if (resdoimport == DialogResult.No)
{
this.CreateNotesImportedFlagfile(nf1appdata);
Log.Write(LogType.info, "Notes from NoteFly 1.0.x will not be imported.");
}
}
return imported;
}
/// <summary>
/// Create a empty file so this newer NoteFly version knows the application data of NoteFly 1.0.x is imported.
/// </summary>
/// <param name="folder">Path to NoteFly 1.0.x application data folder.</param>
private void CreateNotesImportedFlagfile(string folder)
{
try
{
File.Create(Path.Combine(folder, IMPORTEDFLAGFILE));
}
catch
{
Log.Write(LogType.exception, "Could not set import flag in old notes directory.");
}
}
/// <summary>
/// Clear all notes from memory of notefly.
/// </summary>
public void ClearAllNotes()
{
while (this.CountNotes > 0)
{
try
{
this.GetNote(0).DestroyForm();
this.RemoveNote(0);
}
catch (Exception)
{
break;
}
}
}
/// <summary>
/// Import NoteFly 2.5.x/2.0.x notes.
/// to be move to importnotes class.
/// </summary>
/// <returns>True if already imported.</returns>
private bool ImportingNotesNoteFly2()
{
bool imported = false;
string nf2appdata = string.Empty;
if (Program.CurrentOS == Program.OS.WINDOWS)
{
nf2appdata = Path.Combine(System.Environment.GetEnvironmentVariable("APPDATA"), ".NoteFly2");
}
else if (Program.CurrentOS == Program.OS.LINUX)
{
nf2appdata = Path.Combine(System.Environment.GetEnvironmentVariable("HOME"), ".NoteFly2");
}
if (Directory.Exists(nf2appdata) && (!File.Exists(Path.Combine(nf2appdata, IMPORTEDFLAGFILE))))
{
DialogResult resdlg = MessageBox.Show(Strings.T("Do you want to import the notes from NoteFly 2.5.x?\nPress cancel to ask this again next time."), Strings.T("Import from NoteFly 2.5.x"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (resdlg == DialogResult.Yes)
{
string nf2settingsfile = Path.Combine(nf2appdata, "settings.xml");
string nf2notessavepath = xmlUtil.GetContentString(nf2settingsfile, "NotesSavepath");
if (Directory.Exists(nf2notessavepath))
{
const string NF2_NOTEEXTENSION = ".nfn";
string[] notefilespath = Directory.GetFiles(nf2notessavepath, "*" + NF2_NOTEEXTENSION, SearchOption.TopDirectoryOnly);
// import notes by simple copy them over since note file format is not changed in notefly 3.0.x
for (int i = 0; i < notefilespath.Length; i++)
{
string filename = Path.GetFileName(notefilespath[i]);
string notefilepath = Path.Combine(Settings.NotesSavepath, filename);
if (!File.Exists(notefilepath) && !string.IsNullOrEmpty(filename))
{
File.Copy(notefilespath[i], notefilepath);
}
}
Log.Write(LogType.info, "Done importing notes from NoteFly 2.5.x");
this.LoadNotes(true, false);
this.CreateNotesImportedFlagfile(nf2appdata);
}
}
else if (resdlg == DialogResult.No)
{
this.CreateNotesImportedFlagfile(nf2appdata);
}
}
else
{
imported = true;
}
return imported;
}
/// <summary>
/// This method set a limit on how many notes total can be loaded.
/// </summary>
/// <param name="totanumbernotes">The total number of notes.</param>
/// <returns>The number of notes to load.</returns>
private int CheckLimitNotesTotal(int totanumbernotes)
{
if (totanumbernotes > Settings.NotesWarnlimitTotal)
{
string notes_manynotesloadalltitle = Strings.T("many notes");
string notes_manynotesloadall = Strings.T("There are many notes loading this can take a while, do you want to load them all?");
DialogResult dlgres = MessageBox.Show(notes_manynotesloadall, notes_manynotesloadalltitle, MessageBoxButtons.YesNo);
if (dlgres == DialogResult.No)
{
totanumbernotes = Settings.NotesWarnlimitTotal;
}
}
return totanumbernotes;
}
/// <summary>
/// Check if NotesWarnlimitVisible is reached and display warning then.
/// </summary>
/// <param name="currentnumber">The number of notes that are currently visible.</param>
/// <returns>True if warning limit is exceeded.</returns>
private bool CheckLimitNotesVisible(int currentnumber)
{
if (currentnumber > Settings.NotesWarnlimitVisible)
{
string notes_manynotesvisibletitle = Strings.T("Many notes visible");
string notes_manynotesvisible = Strings.T("There are many notes visible.\nHide some notes to make loading faster.");
MessageBox.Show(notes_manynotesvisible, notes_manynotesvisibletitle, MessageBoxButtons.YesNo);
return true;
}
else
{
return false;
}
}
/// <summary>
/// Check if filename already exist if it is then generate a new one.
/// </summary>
/// <param name="newfile">The suggested new filename.</param>
/// <param name="usedlimitlengthfile">The used file length limit.</param>
/// <param name="sepchar">Seperator character.</param>
/// <returns>Empty string on all used.</returns>
private string Checknewfilename(string newfile, int usedlimitlengthfile, char sepchar)
{
int num = 1;
int lenfilecounter = 3;
int numlen = num.ToString(CultureInfo.InvariantCulture.NumberFormat).Length;
while (File.Exists(Path.Combine(Settings.NotesSavepath, newfile)) && (numlen <= lenfilecounter))
{
numlen = num.ToString(CultureInfo.InvariantCulture.NumberFormat).Length;
newfile = newfile.Substring(0, usedlimitlengthfile - numlen - 1) + sepchar + num + NOTEEXTENSION;
num++;
}
if (numlen > lenfilecounter)
{
sepchar++;
if (sepchar < 47)
{
return this.Checknewfilename(newfile, usedlimitlengthfile, sepchar);
}
else
{
Log.Write(LogType.exception, "All suggested filenames to save this note based on title seems to be taken.");
return string.Empty;
}
}
else
{
return newfile;
}
}
/// <summary>
/// Create a demo note with instruction .
/// Don't create demo note again if a file with same filename already exist.
/// (Should be the first time that NoteFly is runned displayed only.)
/// </summary>
private void CreateFirstrunNote()
{
string title = Program.AssemblyTitle + " " + Program.AssemblyVersionAsString;
string filename;
if (title.Length > LIMITLENFILE)
{
filename = title.Substring(0, LIMITLENFILE) + NOTEEXTENSION;
}
else
{
filename = title.Substring(0, title.Length) + NOTEEXTENSION;
}
You can’t perform that action at this time.
